phpunit: Call to undefined method PHPUnit\Util\TestDox\CliTestDoxPrinter::formatWithColor() using testdox mode
Q | A |
---|---|
PHPUnit version | 8.0.0 |
PHP version | 7.4.2 |
Installation Method | Composer |
Summary
Current behavior
PHPUnit 8.0.0 by Sebastian Bergmann and contributors.
PHP Fatal error: Uncaught Error: Call to undefined method PHPUnit\Util\TestDox\CliTestDoxPrinter::formatWithColor() in /usr/share/php/PHPUnit/Util/TestDox/CliTestDoxPrinter.php:183
Stack trace:
#0 vendor/phpunit/phpunit/src/Framework/TestResult.php(313): PHPUnit\Util\TestDox\CliTestDoxPrinter->addWarning()
#1 vendor/phpunit/phpunit/src/Framework/TestResult.php(848): PHPUnit\Framework\TestResult->addWarning()
#2 vendor/phpunit/phpunit/src/Framework/TestCase.php(797): PHPUnit\Framework\TestResult->run()
#3 vendor/phpunit/phpunit/src/Framework/TestSuite.php(761): PHPUnit\Framework\TestCase->run()
#4 vendor/phpunit/phpunit/src/Framework/TestSuite.php(761): PHPUnit\Framework\TestSuite->run()
#5 vendor/phpunit/phpunit/src/TextUI/TestRunner.php(632): PHPUnit\Framework\TestSuite->run()
#6 vendor/phpunit/phpunit/src/TextUI/Comma in /usr/share/php/PHPUnit/Util/TestDox/CliTestDoxPrinter.php on line 183
How to reproduce
composer.json
{
"name": "williamdes/testrepo",
"require": {
"phpunit/phpunit": "8.0"
}
}
phpunit.xml
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.4/phpunit.xsd"
colors="true"
backupGlobals="false"
bootstrap="vendor/autoload.php"
stderr="true"
>
<testsuites>
<testsuite name="Unit tests">
<directory suffix=".php">test/</directory>
</testsuite>
</testsuites>
</phpunit>
test/DataTest.php
<?php
declare(strict_types = 1);
namespace Williamdes\MariaDBMySQLKBS\Test;
use \PHPUnit\Framework\TestCase;
class DataTest extends TestCase
{
}
Run ./vendor/bin/phpunit --testdox
Expected behavior
Run tests and show testdox output
Duplicate of https://github.com/sebastianbergmann/phpunit/issues/3906
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 23 (12 by maintainers)
@williamdes There is no issue here to fix (in PHPUnit).
@williamdes Yes, I just tried it again and you are right: it does fail in this environment. But that is the crux of this issue, it is a problem that is related to environment, packages, (mounted) directories.
For sure it is a problem you encounter while working with PHPUnit but it isn’t an
@internal
problem of PHPUnit itself. If you install any recent version of PHPUnit it will happily fingerpaint your TestDox output.To get a handle on this I would have to start comparing and debugging the difference between both scenarios. This is too much work for an edge case that is not caused by the internals of PHPUnit itself. However, if you manage to pinpoint the exact issue and make a proper pull request: sure, go for it!
I’ll be in my corner refactoring the execution reordering and
@dataProvider
stuff@williamdes Have you tried removing the global install of PHPUnit, also in the docker container?
As said before: trying to debug from afar has been very time consuming, as neither @sebastianbergmann nor me could reproduce the error.
I did. Deleted my jokey comment and tried it in a fresh
/tmp
folder, which worked fine. I don’t doubt you are seeing the errors you are pasting here, yet it is quite obvious there is something going on with different versions of PHPUnit on your system.Whatever the details: this is an uncommon edge case. I am putting my money on your global install being v7 and the example being v8.
Of course not.
That is not the one being called, right? Your globally installed PHPUnit should not interfere when calling
./vendor/bin/phpunit
from inside your project.A PHPUnit 8.* and 7.* colliding will most certainly give you strange errors like this!
This even misses
CliTestDoxPrinter::formatWithColor()
not thecolorizeTextBox()
. Definitely something with code versions. I need to reproduce this locally, from the provided config, code and output I do not understand what’s going wrong here.