From eef576730e73a18ae2153aa8e16e4be09964cdb8 Mon Sep 17 00:00:00 2001 From: Jakub Zverina Date: Wed, 3 Jun 2015 14:43:59 +0200 Subject: [PATCH 1/3] possibility to run just some test cases filtered by name (see #12) --- src/Console/Command/RunTestsCommand.php | 10 +++++++++- src/Process/ProcessSetCreator.php | 12 ++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Console/Command/RunTestsCommand.php b/src/Console/Command/RunTestsCommand.php index 9c479d8e..fc0380ad 100644 --- a/src/Console/Command/RunTestsCommand.php +++ b/src/Console/Command/RunTestsCommand.php @@ -45,6 +45,7 @@ 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_PUBLISH_RESULTS = 'publish-results'; @@ -121,6 +122,12 @@ 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, @@ -246,7 +253,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $processSet = $processSetCreator->createFromFiles( $files, $input->getOption(self::OPTION_GROUP), - $input->getOption(self::OPTION_EXCLUDE_GROUP) + $input->getOption(self::OPTION_EXCLUDE_GROUP), + $input->getOption(self::OPTION_FILTER) ); if (!count($processSet)) { diff --git a/src/Process/ProcessSetCreator.php b/src/Process/ProcessSetCreator.php index d0bd8a6d..2617b699 100644 --- a/src/Process/ProcessSetCreator.php +++ b/src/Process/ProcessSetCreator.php @@ -54,11 +54,12 @@ public function __construct( * @param Finder $files * @param array $groups Groups to be run * @param array $excludeGroups Groups to be excluded + * @param string $filter filter test cases by name * @return ProcessSet */ - public function createFromFiles(Finder $files, array $groups = null, array $excludeGroups = null) + public function createFromFiles(Finder $files, array $groups = null, array $excludeGroups = null, $filter = null) { - if ($groups || $excludeGroups) { + if ($groups || $excludeGroups || $filter) { $this->output->writeln('Filtering testcases:'); } if ($groups) { @@ -67,6 +68,9 @@ public function createFromFiles(Finder $files, array $groups = null, array $excl if ($excludeGroups) { $this->output->writeln(sprintf(' - excluding group(s): %s', implode(', ', $excludeGroups))); } + if ($filter) { + $this->output->writeln(sprintf(' - filtering tests by name: %s', $filter)); + } $processSet = $this->getProcessSet(); @@ -126,6 +130,10 @@ public function createFromFiles(Finder $files, array $groups = null, array $excl '--configuration=' . realpath(__DIR__ . '/../phpunit.xml'), ]; + if ($filter) { + $phpunitArgs[] = '--filter=' . $filter; + } + // If ANSI output is enabled, turn on colors in PHPUnit if ($this->output->isDecorated()) { $phpunitArgs[] = '--colors=always'; From 34cb05821f2ff82644c2530913b2f29f4d6f6012 Mon Sep 17 00:00:00 2001 From: Ondrej Machulda Date: Wed, 3 Jun 2015 16:47:35 +0200 Subject: [PATCH 2/3] 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 2617b699..e5ded57b 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(); From cb34ceeb71c87c3d443884b645fd7f1c1f534a52 Mon Sep 17 00:00:00 2001 From: Ondrej Machulda Date: Thu, 4 Jun 2015 15:40:27 +0200 Subject: [PATCH 3/3] Added record to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4d56b49..385e9d0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## Unreleased ### Added - Check if browser given to `run-tests` command is supported (this helps avoiding typos, interchange of browser and environment etc.). +- Option `--filter` which allows filtering tests/testcases by name (@ziizii) ### Changed - The `logs/results.xml` could now be also accessed locally (the XSLT is now embedded right into the file, so we don't encounter same-origin policy problems).