From 611deaefff8c148d01e6c42bccb107c7de9fdd36 Mon Sep 17 00:00:00 2001 From: Ondrej Machulda Date: Wed, 3 Jun 2015 16:47:35 +0200 Subject: [PATCH] Test whether the --filter option is passed to phpunit --- src-tests/Process/ProcessSetCreatorTest.php | 20 ++++++++++++++++++-- src/Console/Command/RunTestsCommand.php | 14 +++++++------- src/Process/ProcessSetCreator.php | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src-tests/Process/ProcessSetCreatorTest.php b/src-tests/Process/ProcessSetCreatorTest.php index a331869e..f12eaa4f 100644 --- a/src-tests/Process/ProcessSetCreatorTest.php +++ b/src-tests/Process/ProcessSetCreatorTest.php @@ -83,13 +83,13 @@ public function testShouldCreateEmptyProcessSetIfNoFilesGiven() public function testShouldCreateProcessSetFromGivenFiles() { - $processSet = $this->creator->createFromFiles($this->findDummyTests(), [], []); + $processSet = $this->creator->createFromFiles($this->findDummyTests(), [], [], ''); $this->assertQueuedTests([self::NAME_DUMMY_TEST, self::NAME_BAR_TEST, self::NAME_FOO_TEST], $processSet); // Test properties of DummyTest - /** @var Process $dummyTestProcess */ $processes = $processSet->get(ProcessSet::PROCESS_STATUS_QUEUED); + /** @var Process $dummyTestProcess */ $dummyTestProcess = $processes[self::NAME_DUMMY_TEST]->process; $testCommand = $dummyTestProcess->getCommandLine(); $testEnv = $dummyTestProcess->getEnv(); @@ -97,6 +97,7 @@ public function testShouldCreateProcessSetFromGivenFiles() $this->assertContains('phpunit', $testCommand); $this->assertContains('--log-junit=logs/Lmc-Steward-Process-Fixtures-DummyTests-DummyTest.xml', $testCommand); $this->assertNotContains('--colors', $testCommand); // Decorated output is disabled in setUp() + $this->assertNotContains('--filter', $testCommand); $this->assertRegExp('/--configuration=.*\/src\/phpunit\.xml/', $testCommand); // Check defaults were passed to the Processes @@ -150,6 +151,21 @@ public function testShouldAddTestsOfGivenGroupsButExcludeFromThemThoseOfExcluded $this->assertRegExp('/Excluding testcase file .*\/GroupBarTest\.php with group bar/', $output); } + public function testShouldPassFilterOptionToPhpunitProcess() + { + $processSet = $this->creator->createFromFiles($this->findDummyTests(), [], [], 'testCase::testName'); + + $processes = $processSet->get(ProcessSet::PROCESS_STATUS_QUEUED); + /** @var Process $dummyTestProcess */ + $dummyTestProcess = $processes[self::NAME_DUMMY_TEST]->process; + $testCommand = $dummyTestProcess->getCommandLine(); + $output = $this->bufferedOutput->fetch(); + + $this->assertContains('Filtering testcases:', $output); + $this->assertContains('by testcase/test name: testCase::testName', $output); + $this->assertContains('--filter=testCase::testName', $testCommand); + } + public function testShouldPropagateCustomOptionsIntoProcess() { $this->input = new StringInput( diff --git a/src/Console/Command/RunTestsCommand.php b/src/Console/Command/RunTestsCommand.php index fc0380ad..b625d4c8 100644 --- a/src/Console/Command/RunTestsCommand.php +++ b/src/Console/Command/RunTestsCommand.php @@ -45,8 +45,8 @@ class RunTestsCommand extends Command const OPTION_LOGS_DIR = 'logs-dir'; const OPTION_PATTERN = 'pattern'; const OPTION_GROUP = 'group'; - const OPTION_FILTER = 'filter'; const OPTION_EXCLUDE_GROUP = 'exclude-group'; + const OPTION_FILTER = 'filter'; const OPTION_PUBLISH_RESULTS = 'publish-results'; /** @@ -122,18 +122,18 @@ protected function configure() InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Only run testcases with specified @group of this name' ) - ->addOption( - self::OPTION_FILTER, - null, - InputOption::VALUE_REQUIRED, - 'Run only tests whose name is matching this filter' - ) ->addOption( self::OPTION_EXCLUDE_GROUP, null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Exclude testcases with specified @group from being run' ) + ->addOption( + self::OPTION_FILTER, + null, + InputOption::VALUE_REQUIRED, + 'Run only testcases/tests with name matching this filter' + ) ->addOption( self::OPTION_PUBLISH_RESULTS, null, diff --git a/src/Process/ProcessSetCreator.php b/src/Process/ProcessSetCreator.php index cf3d2e8c..6f01bee6 100644 --- a/src/Process/ProcessSetCreator.php +++ b/src/Process/ProcessSetCreator.php @@ -69,7 +69,7 @@ public function createFromFiles(Finder $files, array $groups = null, array $excl $this->output->writeln(sprintf(' - excluding group(s): %s', implode(', ', $excludeGroups))); } if ($filter) { - $this->output->writeln(sprintf(' - filtering tests by name: %s', $filter)); + $this->output->writeln(sprintf(' - by testcase/test name: %s', $filter)); } $processSet = $this->getProcessSet();