Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging of TestSuite setup failures #3428

Merged
merged 10 commits into from
Nov 30, 2018
20 changes: 8 additions & 12 deletions src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,29 +704,25 @@ public function run(TestResult $result = null): TestResult
}
}
} catch (SkippedTestSuiteError $e) {
$numTests = \count($this);

for ($i = 0; $i < $numTests; $i++) {
$result->startTest($this);
$result->addFailure($this, $e, 0);
$result->endTest($this, 0);
foreach ($this->tests() as $test) {
$result->startTest($test);
$result->addFailure($test, $e, 0);
$result->endTest($test, 0);
}

$this->tearDown();
$result->endTestSuite($this);

return $result;
} catch (Throwable $t) {
$numTests = \count($this);

for ($i = 0; $i < $numTests; $i++) {
foreach ($this->tests() as $test) {
if ($result->shouldStop()) {
break;
}

$result->startTest($this);
$result->addError($this, $t, 0);
$result->endTest($this, 0);
$result->startTest($test);
$result->addError($test, $t, 0);
$result->endTest($test, 0);
}

$this->tearDown();
Expand Down
6 changes: 0 additions & 6 deletions src/Util/TestDox/CliTestDoxPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@ public function startTest(Test $test): void
if ($test instanceof TestCase) {
$className = $this->prettifier->prettifyTestClass(\get_class($test));
$testMethod = $this->prettifier->prettifyTestCase($test);
} elseif ($test instanceof TestSuite) {
$className = $test->getName();
$testMethod = \sprintf(
'Error bootstapping suite (most likely in %s::setUpBeforeClass)',
$test->getName()
);
} elseif ($test instanceof PhptTestCase) {
$className = \get_class($test);
$testMethod = $test->getName();
Expand Down
4 changes: 2 additions & 2 deletions tests/end-to-end/regression/GitHub/2145.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Time: %s, Memory: %s

There was 1 error:

1) Issue2145Test
1) Issue2145Test::testOne
Exception in %s%eIssue2145Test.php:%d
%A
ERRORS!
Tests: 2, Assertions: 0, Errors: 1.
Tests: 1, Assertions: 0, Errors: 1.
4 changes: 2 additions & 2 deletions tests/end-to-end/regression/GitHub/3107/issue-3107-test.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Issue3107\Issue3107Test
Error bootstapping suite (most likely in Issue3107\Issue3107Test::setUpBeforeClass)
Issue3107\Issue3107
One
│ Error: Call to undefined function %Sdoes_not_exist()
Expand Down
58 changes: 58 additions & 0 deletions tests/end-to-end/regression/GitHub/3364/issue-3364-test.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/3364
--FILE--
<?php
$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--teamcity';
$_SERVER['argv'][3] = __DIR__ . DIRECTORY_SEPARATOR . 'tests';

require __DIR__ . '/../../../../bootstrap.php';
PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.


##teamcity[testCount count='4' flowId='%d']

##teamcity[testSuiteStarted name='%stests%eend-to-end%eregression%eGitHub%e3364%etests' flowId='%d']

##teamcity[testSuiteStarted name='Issue3364SetupBeforeClassTest' locationHint='php_qn://%s%etests%eend-to-end%eregression%eGitHub%e3364%etests%eIssue3364SetupBeforeClassTest.php::\Issue3364SetupBeforeClassTest' flowId='%d']

##teamcity[testStarted name='testOneWithClassSetupException' locationHint='php_qn://%s%etests%eend-to-end%eregression%eGitHub%e3364%etests%eIssue3364SetupBeforeClassTest.php::\Issue3364SetupBeforeClassTest::testOneWithClassSetupException' flowId='%d']

##teamcity[testFailed name='testOneWithClassSetupException' message='throw exception in setUpBeforeClass' details=' %s%etests%eend-to-end%eregression%eGitHub%e3364%etests%eIssue3364SetupBeforeClassTest.php:18|n ' duration='%d' flowId='%d']

##teamcity[testFinished name='testOneWithClassSetupException' duration='%d' flowId='%d']

##teamcity[testStarted name='testTwoWithClassSetupException' locationHint='php_qn://%s%etests%eend-to-end%eregression%eGitHub%e3364%etests%eIssue3364SetupBeforeClassTest.php::\Issue3364SetupBeforeClassTest::testTwoWithClassSetupException' flowId='%d']

##teamcity[testFailed name='testTwoWithClassSetupException' message='throw exception in setUpBeforeClass' details=' %s%etests%eend-to-end%eregression%eGitHub%e3364%etests%eIssue3364SetupBeforeClassTest.php:18|n ' duration='%d' flowId='%d']

##teamcity[testFinished name='testTwoWithClassSetupException' duration='%d' flowId='%d']

##teamcity[testSuiteFinished name='Issue3364SetupBeforeClassTest' flowId='%d']

##teamcity[testSuiteStarted name='Issue3364SetupTest' locationHint='php_qn://%s%etests%eend-to-end%eregression%eGitHub%e3364%etests%eIssue3364SetupTest.php::\Issue3364SetupTest' flowId='%d']

##teamcity[testStarted name='testOneWithSetupException' locationHint='php_qn://%s%etests%eend-to-end%eregression%eGitHub%e3364%etests%eIssue3364SetupTest.php::\Issue3364SetupTest::testOneWithSetupException' flowId='%d']

##teamcity[testFailed name='testOneWithSetupException' message='RuntimeException : throw exception in setUp' details=' %s%etests%eend-to-end%eregression%eGitHub%e3364%etests%eIssue3364SetupTest.php:18|n ' duration='%d' flowId='%d']

##teamcity[testFinished name='testOneWithSetupException' duration='%d' flowId='%d']

##teamcity[testStarted name='testTwoWithSetupException' locationHint='php_qn://%s%etests%eend-to-end%eregression%eGitHub%e3364%etests%eIssue3364SetupTest.php::\Issue3364SetupTest::testTwoWithSetupException' flowId='%d']

##teamcity[testFailed name='testTwoWithSetupException' message='RuntimeException : throw exception in setUp' details=' %s%etests%eend-to-end%eregression%eGitHub%e3364%etests%eIssue3364SetupTest.php:18|n ' duration='%d' flowId='%d']

##teamcity[testFinished name='testTwoWithSetupException' duration='%d' flowId='%d']

##teamcity[testSuiteFinished name='Issue3364SetupTest' flowId='%d']

##teamcity[testSuiteFinished name='%stests%eend-to-end%eregression%eGitHub%e3364%etests' flowId='%d']


Time: %s, Memory: %s


ERRORS!
Tests: 4, Assertions: 0, Errors: 4.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use PHPUnit\Framework\TestCase;

class Issue3364SetupBeforeClassTest extends TestCase
{
public static function setUpBeforeClass(): void
{
throw new \RuntimeException('throw exception in setUpBeforeClass');
}

public function testOneWithClassSetupException(): void
{
$this->fail();
}

public function testTwoWithClassSetupException(): void
{
$this->fail();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use PHPUnit\Framework\TestCase;

class Issue3364SetupTest extends TestCase
{
public function setUp(): void
{
throw new \RuntimeException('throw exception in setUp');
}

public function testOneWithSetupException(): void
{
$this->fail();
}

public function testTwoWithSetupException(): void
{
$this->fail();
}
}