Skip to content

Commit

Permalink
Fix the count of tests printed in console when tests are filtered (#3034
Browse files Browse the repository at this point in the history
)

Change-Id: I6c341ad6b99799e16dfce43b9eae899b0b27d3d9
Conflicts:
	src/Codeception/PHPUnit/Runner.php
	tests/cli/RunCest.php
  • Loading branch information
dzoeteman authored and Naktibalda committed May 4, 2016
1 parent 1cc5375 commit 90fbb7b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
50 changes: 27 additions & 23 deletions src/Codeception/PHPUnit/Runner.php
Expand Up @@ -41,30 +41,9 @@ public function getPrinter()
return $this->printer;
}

public function doEnhancedRun(
\PHPUnit_Framework_Test $suite,
\PHPUnit_Framework_TestResult $result,
array $arguments = []
) {
unset($GLOBALS['app']); // hook for not to serialize globals

public function prepareSuite(\PHPUnit_Framework_Test $suite, array &$arguments)
{
$this->handleConfiguration($arguments);
$result->convertErrorsToExceptions(false);

if (empty(self::$persistentListeners)) {
$this->applyReporters($result, $arguments);
}

if (class_exists('\Symfony\Bridge\PhpUnit\SymfonyTestsListener')) {
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
$arguments['listeners'][] = new \Symfony\Bridge\PhpUnit\SymfonyTestsListener();
}
$arguments['listeners'][] = $this->printer;

// clean up listeners between suites
foreach ($arguments['listeners'] as $listener) {
$result->addListener($listener);
}

$filterFactory = new \PHPUnit_Runner_Filter_Factory();
if ($arguments['groups']) {
Expand All @@ -89,6 +68,31 @@ public function doEnhancedRun(
}

$suite->injectFilter($filterFactory);
}

public function doEnhancedRun(
\PHPUnit_Framework_Test $suite,
\PHPUnit_Framework_TestResult $result,
array $arguments = []
) {
unset($GLOBALS['app']); // hook for not to serialize globals

$result->convertErrorsToExceptions(false);

if (empty(self::$persistentListeners)) {
$this->applyReporters($result, $arguments);
}

if (class_exists('\Symfony\Bridge\PhpUnit\SymfonyTestsListener')) {
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
$arguments['listeners'][] = new \Symfony\Bridge\PhpUnit\SymfonyTestsListener();
}
$arguments['listeners'][] = $this->printer;

// clean up listeners between suites
foreach ($arguments['listeners'] as $listener) {
$result->addListener($listener);
}

$suite->run($result);
unset($suite);
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Subscriber/Console.php
Expand Up @@ -97,7 +97,7 @@ public function beforeSuite(SuiteEvent $e)
$this->buildResultsTable($e);

$this->message("%s Tests (%d) ")
->with(ucfirst($e->getSuite()->getName()), count($e->getSuite()->tests()))
->with(ucfirst($e->getSuite()->getName()), $e->getSuite()->count())
->style('bold')
->width(array_sum($this->columns), '-')
->prepend("\n")
Expand Down
1 change: 1 addition & 0 deletions src/Codeception/SuiteManager.php
Expand Up @@ -149,6 +149,7 @@ protected function createSuite($name)

public function run(PHPUnit\Runner $runner, \PHPUnit_Framework_TestResult $result, $options)
{
$runner->prepareSuite($this->suite, $options);
$this->dispatcher->dispatch(Events::SUITE_BEFORE, new Event\SuiteEvent($this->suite, $result, $this->settings));
$runner->doEnhancedRun($this->suite, $result, $options);
$this->dispatcher->dispatch(Events::SUITE_AFTER, new Event\SuiteEvent($this->suite, $result, $this->settings));
Expand Down
14 changes: 9 additions & 5 deletions tests/cli/RunCest.php
Expand Up @@ -113,31 +113,35 @@ public function runCustomReport(\CliGuy $I)
public function runOneGroup(\CliGuy $I)
{
$I->executeCommand('run skipped -g notorun');
$I->seeInShellOutput('Skipped Tests (1)');
$I->seeInShellOutput("IncompleteMeCept");
$I->dontSeeInShellOutput("SkipMeCept");
}

public function skipRunOneGroup(\CliGuy $I)
{
$I->executeCommand('run skipped --skip-group notorun');
$I->seeInShellOutput('Skipped Tests (2)');
$I->seeInShellOutput("SkipMeCept");
$I->dontSeeInShellOutput("IncompleteMeCept");
}

public function skipGroupOfCest(\CliGuy $I)
{
$I->executeCommand('run dummy');
$I->seeInShellOutput('optimistic');
$I->seeInShellOutput('Optimistic');
$I->seeInShellOutput('Dummy Tests (5)');
$I->executeCommand('run dummy --skip-group ok');
$I->seeInShellOutput('pessimistic');
$I->dontSeeInShellOutput('optimistic');
$I->seeInShellOutput('Pessimistic');
$I->seeInShellOutput('Dummy Tests (4)');
$I->dontSeeInShellOutput('Optimistic');
}

public function runTwoSuites(\CliGuy $I)
{
$I->executeCommand('run skipped,dummy --no-exit');
$I->seeInShellOutput("Skipped Tests");
$I->seeInShellOutput("Dummy Tests");
$I->seeInShellOutput("Skipped Tests (3)");
$I->seeInShellOutput("Dummy Tests (5)");
$I->dontSeeInShellOutput("Remote Tests");
}

Expand Down

0 comments on commit 90fbb7b

Please sign in to comment.