Skip to content

Commit 9c7897b

Browse files
committed
Extended bakery test to add Test Scope and sprinkle selection argument
(Thanks @ssnukala !)
1 parent 6e69897 commit 9c7897b

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3636
- Added `test:mail` Bakery Command
3737
- Add support for other config['mailer'] options ([#872]; Thanks @apple314159 !)
3838
- Added support for npm dependencies on the frontend with auditting for known vulnerabilities
39+
- Extended `bakery test` to add Test Scope and sprinkle selection argument (Thanks @ssnukala !)
3940

4041
### Changed
4142
- Moved Bakery commands from `app/System/Bakery` to the `Core` sprinkle and `UserFrosting\Sprinkle\Core\Bakery` namespace.

app/sprinkles/core/src/Bakery/Test.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
namespace UserFrosting\Sprinkle\Core\Bakery;
1010

11+
use Illuminate\Support\Str;
1112
use Symfony\Component\Console\Input\InputInterface;
1213
use Symfony\Component\Console\Output\OutputInterface;
1314
use Symfony\Component\Console\Input\InputOption;
15+
use Symfony\Component\Console\Input\InputArgument;
1416
use UserFrosting\System\Bakery\BaseCommand;
1517

1618
/**
@@ -33,8 +35,9 @@ protected function configure()
3335
{
3436
$this->setName('test')
3537
->addOption('coverage', 'c', InputOption::VALUE_NONE, 'Generate code coverage report in HTML format. Will be saved in _meta/coverage')
36-
->setDescription('Run tests')
37-
->setHelp('Run php unit tests');
38+
->addArgument('testscope', InputArgument::OPTIONAL, "Test Scope can either be a sprinkle name or a class formated as 'SprinkleName\Tests\TestClass` or 'SprinkleName\Tests\TestClass::method` (Optional)")
39+
->setDescription('Runs automated tests')
40+
->setHelp("Run PHP unit tests. Tests from a specific sprinkle can optionally be run using the 'testscope' argument (`php bakery test SprinkleName`). A specific test class can also be be run using the testscope argument (`php bakery test 'SprinkleName\Tests\TestClass'`), as a specific test method (`php bakery test 'SprinkleName\Tests\TestClass::method'`).");
3841
}
3942

4043
/**
@@ -50,6 +53,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
5053
$command .= ' -v';
5154
}
5255

56+
$testscope = $input->getArgument('testscope');
57+
if ($testscope) {
58+
$slashes = '\\\\';
59+
if (strpos($testscope, '\\') !== false) {
60+
$this->io->note("Executing Specified Test Scope : $testscope");
61+
$testscope = str_replace('\\', $slashes, $testscope);
62+
$command .= " --filter='UserFrosting" . $slashes . 'Sprinkle' . $slashes . $testscope . "'";
63+
} else {
64+
$this->io->note("Executing all tests in Sprinkle '".Str::studly($testscope)."'");
65+
$command .= " --filter='UserFrosting" . $slashes . 'Sprinkle' . $slashes . Str::studly($testscope) . $slashes . 'Tests' . $slashes . "' ";
66+
}
67+
}
68+
5369
// Add coverage report
5470
if ($input->getOption('coverage')) {
5571
$command .= ' --coverage-html _meta/coverage';

0 commit comments

Comments
 (0)