Skip to content

Commit

Permalink
Test whether the --filter option is passed to phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Jun 4, 2015
1 parent d573c3a commit 611deae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
20 changes: 18 additions & 2 deletions src-tests/Process/ProcessSetCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,21 @@ 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();

$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
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 7 additions & 7 deletions src/Console/Command/RunTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Process/ProcessSetCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 611deae

Please sign in to comment.