From 9c7897bcd23a07742e4938d6f0ef60655161feb2 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Wed, 9 Jan 2019 20:57:43 -0500 Subject: [PATCH] Extended `bakery test` to add Test Scope and sprinkle selection argument (Thanks @ssnukala !) --- CHANGELOG.md | 1 + app/sprinkles/core/src/Bakery/Test.php | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86b9a455f..e0c73cb80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/app/sprinkles/core/src/Bakery/Test.php b/app/sprinkles/core/src/Bakery/Test.php index 3b4a32d4a..b4163fd8e 100644 --- a/app/sprinkles/core/src/Bakery/Test.php +++ b/app/sprinkles/core/src/Bakery/Test.php @@ -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; /** @@ -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'`)."); } /** @@ -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';