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

7.5.7 class \Failure not found during class teardown exception #3564

Closed
rtek opened this issue Mar 16, 2019 · 3 comments
Closed

7.5.7 class \Failure not found during class teardown exception #3564

rtek opened this issue Mar 16, 2019 · 3 comments
Assignees
Labels
type/bug Something is broken

Comments

@rtek
Copy link

rtek commented Mar 16, 2019

Q A
PHPUnit version 7.5.7
PHP version 7.1.19
Installation Method Composer

Throwing an exception from tearDownAfterClass results in fatal error:

<?php

class Bug extends \PHPUnit\Framework\TestCase
{
    static public function tearDownAfterClass()
    {
        throw new \Exception('bug');
    }

    public function testBug()
    {
        $this->fail();
    }
}
$ vendor/bin/phpunit tests/Bug.php  --debug --verbose
PHPUnit 7.5.7 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.1.19 with Xdebug 2.5.3
Configuration: phpunit.xml.dist

Test 'Bug::testBug' started
Test 'Bug::testBug' ended
PHP Fatal error:  Uncaught Error: Class 'Failure' not found in vendor\phpunit\phpunit\src\Framework\TestSuite.php:761
Stack trace:
#0 vendor\phpunit\phpunit\src\TextUI\TestRunner.php(641): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#1 vendor\phpunit\phpunit\src\TextUI\Command.php(206): PHPUnit\TextUI\TestRunner->doRun(Object(PHPUnit\Framework\TestSuite), Array, true)
#2 vendor\phpunit\phpunit\src\TextUI\Command.php(162): PHPUnit\TextUI\Command->run(Array, true)
#3 vendor\phpunit\phpunit\phpunit(61): PHPUnit\TextUI\Command::main()
#4 {main}
thrown in vendor\phpunit\phpunit\src\Framework\TestSuite.php on line 761

Fatal error: Uncaught Error: Class 'Failure' not found in vendor\phpunit\phpunit\src\Framework\TestSuite.php on line 761

Error: Class 'Failure' not found in vendor\phpunit\phpunit\src\Framework\TestSuite.php on line 761

Call Stack:
0.0000     368768   1. {main}() vendor\phpunit\phpunit\phpunit:0
0.0060    1162648   2. PHPUnit\TextUI\Command::main() vendor\phpunit\phpunit\phpunit:61
0.0060    1171440   3. PHPUnit\TextUI\Command->run() vendor\phpunit\phpunit\src\TextUI\Command.php:162
0.0160    2951704   4. PHPUnit\TextUI\TestRunner->doRun() vendor\phpunit\phpunit\src\TextUI\Command.php:206
0.0250    3275088   5. PHPUnit\Framework\TestSuite->run() vendor\phpunit\phpunit\src\TextUI\TestRunner.php:641
--

@sebastianbergmann
Copy link
Owner

@epdenouden In 96c1264, you added $test = new \Failure('tearDownAfterClass');.

\Failure is not part of PHPUnit's production code but rather part of its test suite's fixture. This is why the tests for PHPUnit's own test suite work (because \Failure is available then). When PHPUnit's own test suite's fixture is not available, which, obviously ;-), is the default case, then \Failure does not exist.

@sebastianbergmann
Copy link
Owner

@epdenouden Can you take care of this? If not, I can look into it (but would first have to dig into the changes you made there).

@epdenouden
Copy link
Contributor

epdenouden commented Mar 16, 2019

\Failure is not part of PHPUnit's production code but rather part of its test suite's fixture.

It was the first thing I thought when I saw the bug, as I did get confused looking for the right way to do this. Will check the 'synthetic error' mechanism again or find some other way to inject a placeholder test.

@rtek Thanks for the detailed report! As @sebastianbergmann mentions, this wouldn't have been much harder to find otherwise and I completely overlooked it the first time around.

driesvints added a commit to laravel/cashier-stripe that referenced this issue Mar 21, 2019
I experienced sebastianbergmann/phpunit#3564 so I'm now requiring a lower PHPUnit 7.x version for the time being. We can't upgrade to 8.0 yet because we're still supporting PHP 7. A bugfix is already made (sebastianbergmann/phpunit#3566) so we should revert this once that's been tagged.
stronk7 added a commit to stronk7/moodle that referenced this issue May 6, 2019
Previously we were sticky to 7.5.7 and this issue was
hitting our windows runs:

sebastianbergmann/phpunit#3564
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

3 participants