Skip to content

Commit

Permalink
Extended bakery test to add Test Scope and sprinkle selection argument
Browse files Browse the repository at this point in the history
(Thanks @ssnukala !)
  • Loading branch information
lcharette committed Jan 10, 2019
1 parent 6e69897 commit 9c7897b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added `test:mail` Bakery Command
- Add support for other config['mailer'] options ([#872]; Thanks @apple314159 !)
- Added support for npm dependencies on the frontend with auditting for known vulnerabilities
- Extended `bakery test` to add Test Scope and sprinkle selection argument (Thanks @ssnukala !)

### Changed
- Moved Bakery commands from `app/System/Bakery` to the `Core` sprinkle and `UserFrosting\Sprinkle\Core\Bakery` namespace.
Expand Down
20 changes: 18 additions & 2 deletions app/sprinkles/core/src/Bakery/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

namespace UserFrosting\Sprinkle\Core\Bakery;

use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use UserFrosting\System\Bakery\BaseCommand;

/**
Expand All @@ -33,8 +35,9 @@ protected function configure()
{
$this->setName('test')
->addOption('coverage', 'c', InputOption::VALUE_NONE, 'Generate code coverage report in HTML format. Will be saved in _meta/coverage')
->setDescription('Run tests')
->setHelp('Run php unit tests');
->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)")
->setDescription('Runs automated tests')
->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'`).");
}

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

$testscope = $input->getArgument('testscope');
if ($testscope) {
$slashes = '\\\\';
if (strpos($testscope, '\\') !== false) {
$this->io->note("Executing Specified Test Scope : $testscope");
$testscope = str_replace('\\', $slashes, $testscope);
$command .= " --filter='UserFrosting" . $slashes . 'Sprinkle' . $slashes . $testscope . "'";
} else {
$this->io->note("Executing all tests in Sprinkle '".Str::studly($testscope)."'");
$command .= " --filter='UserFrosting" . $slashes . 'Sprinkle' . $slashes . Str::studly($testscope) . $slashes . 'Tests' . $slashes . "' ";
}
}

// Add coverage report
if ($input->getOption('coverage')) {
$command .= ' --coverage-html _meta/coverage';
Expand Down

0 comments on commit 9c7897b

Please sign in to comment.