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

CliTestDoxPrinter::addError() cannot handle errors in setUpBeforeClass() #3107

Closed
stanolacko opened this issue Apr 27, 2018 · 2 comments
Closed
Labels
type/bug Something is broken

Comments

@stanolacko
Copy link

Q A
PHPUnit version 7.1.2
PHP version 7.2.2
Installation Method PHAR

If you made error in TestCase, like calling non_existing_function(), you get error, which tells you nothing. In this case, I'm not able to find, that problem is non_existing_function().

class CombiPneuTestSnazzyBee extends PHPUnit\Framework\TestCase {

public static function setUpBeforeClass() {
	non_existing_function();
}

}

Produce:
PHP Fatal error: Uncaught Error: Call to a member function fail() on null in phar://REAL_PATH/phpunit.phar/phpunit/Util/TestDox/CliTestDoxPrinter.php:116
Stack trace:
#0 phar://REAL_PATH/phpunit.phar/phpunit/Framework/TestResult.php(265): PHPUnit\Util\TestDox\CliTestDoxPrinter->addError(Object(PHPUnit\Framework\TestSuite), Object(PHPUnit\Framework\ExceptionWrapper), 0)
#1 phar://REAL_PATH/phpunit.phar/phpunit/Framework/TestSuite.php(754): PHPUnit\Framework\TestResult->addError(Object(PHPUnit\Framework\TestSuite), Object(PHPUnit\Framework\ExceptionWrapper), 0)
#2 phar://REAL_PATH/phpunit.phar/phpunit/TextUI/TestRunner.php(529): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#3 phar://REAL_PATH/phpunit.phar/phpunit/TextUI/Command.php(198): PHPUnit\TextUI\TestRunner->doRun(Object(PHPUnit\Framework\TestSuite), Array, true)
#4 phar://REAL_PATH/phpunit.phar/phpunit/TextUI/Command.php( in phar://REAL_PATH/phpunit.phar/phpunit/Util/TestDox/CliTestDoxPrinter.php on line 116

Fatal error: Uncaught Error: Call to a member function fail() on null in phar://REAL_PATH/phpunit.phar/phpunit/Util/TestDox/CliTestDoxPrinter.php:116
Stack trace:
#0 phar://REAL_PATH/phpunit.phar/phpunit/Framework/TestResult.php(265): PHPUnit\Util\TestDox\CliTestDoxPrinter->addError(Object(PHPUnit\Framework\TestSuite), Object(PHPUnit\Framework\ExceptionWrapper), 0)
#1 phar://REAL_PATH/phpunit.phar/phpunit/Framework/TestSuite.php(754): PHPUnit\Framework\TestResult->addError(Object(PHPUnit\Framework\TestSuite), Object(PHPUnit\Framework\ExceptionWrapper), 0)
#2 phar://REAL_PATH/phpunit.phar/phpunit/TextUI/TestRunner.php(529): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#3 phar://REAL_PATH/phpunit.phar/phpunit/TextUI/Command.php(198): PHPUnit\TextUI\TestRunner->doRun(Object(PHPUnit\Framework\TestSuite), Array, true)
#4 phar://REAL_PATH/phpunit.phar/phpunit/TextUI/Command.php( in phar://REAL_PATH/phpunit.phar/phpunit/Util/TestDox/CliTestDoxPrinter.php on line 116

@sebastianbergmann
Copy link
Owner

<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;

class Test extends TestCase
{
    public static function setUpBeforeClass(): void
    {
        does_not_exist();
    }
    
    public function testOne(): void
    {
        $this->assertTrue(true);
    }
}
$ phpunit --testdox Test
PHPUnit 7.1.4 by Sebastian Bergmann and contributors.

PHP Fatal error:  Uncaught Error: Call to a member function fail() on null in /usr/local/src/phpunit/src/Util/TestDox/CliTestDoxPrinter.php:116

@sebastianbergmann sebastianbergmann changed the title fail() on null CliTestDoxPrinter::addError() cannot handle errors in setUpBeforeClass() Apr 28, 2018
@sebastianbergmann sebastianbergmann added the type/bug Something is broken label Apr 28, 2018
@sebastianbergmann
Copy link
Owner

CC @rpkamp

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

2 participants