| Q | A
| --------------------| ---------------
| PHPUnit version | 6.1.3
| PHP version | 7.0.15
| Installation Method | Composer
Fresh installation throws Fatal error when PHPUnit is called with . parameter. Providing any other random dir as a parameter is handled fine.
$ vendor/bin/phpunit .
PHP Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /home/tomas/Projects/labas/vendor/doctrine/instantiator/tests/DoctrineTest/InstantiatorTest/Exception/InvalidArgumentExceptionTest.php on line 33
PHP Stack trace:
PHP 1. {main}() /home/tomas/Projects/labas/vendor/phpunit/phpunit/phpunit:0
PHP 2. PHPUnit\TextUI\Command::main() /home/tomas/Projects/labas/vendor/phpunit/phpunit/phpunit:53
PHP 3. PHPUnit\TextUI\Command->run() /home/tomas/Projects/labas/vendor/phpunit/phpunit/src/TextUI/Command.php:140
PHP 4. PHPUnit\Runner\BaseTestRunner->getTest() /home/tomas/Projects/labas/vendor/phpunit/phpunit/src/TextUI/Command.php:161
PHP 5. PHPUnit\Framework\TestSuite->addTestFiles() /home/tomas/Projects/labas/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:65
PHP 6. PHPUnit\Framework\TestSuite->addTestFile() /home/tomas/Projects/labas/vendor/phpunit/phpunit/src/Framework/TestSuite.php:394
PHP 7. PHPUnit\Util\Fileloader::checkAndLoad() /home/tomas/Projects/labas/vendor/phpunit/phpunit/src/Framework/TestSuite.php:322
PHP 8. PHPUnit\Util\Fileloader::load() /home/tomas/Projects/labas/vendor/phpunit/phpunit/src/Util/Fileloader.php:45
PHP 9. include_once() /home/tomas/Projects/labas/vendor/phpunit/phpunit/src/Util/Fileloader.php:61
@tomasliubinas check https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-6.0.0#backwards-compatibility-issues
PHPUnit's units of code are now namespaced. For instance, PHPUnit_Framework_TestCase is now PHPUnit\Framework\TestCase
so PHPUnit_Framework_TestCase does not exist anymore in version 6+
@kokspflanze thanks for the response. Just please be aware that the behavior could be reproduced on a completely fresh installation:
$ mkdir myproject
$ cd myproject
$ composer require phpunit/phpunit
$ vendor/bin/phpunit .
PHP Fatal error: Class 'PHPUnit_Framework_TestCase' not found ...
@tomasliubinas You are trying to run an existing test suite that uses the old PHPUnit_Framework_TestCase class name with PHPUnit 6 (that is what composer require phpunit/phpunit installs for you). This cannot work.
You want to read the release announcement that @kokspflanze already pointed you to (and maybe https://thephp.cc/news/2017/02/death-star-version-constraint and https://thephp.cc/news/2017/02/migrating-to-phpunit-6, too).
You're talking past each other.
He did not even write a single test as his reproduction steps show.
Actually, this is not a bug in PHPUnit at all.
The problem lies in the fact that doctrine's instantiator tests are not PHPUnit 6 compliant and their execution is attempted when . is passed as PHPUnit scans the given directory tree recursively.
It might actually be a nice idea to "catch" this type of problem by providing the class again but having a it skip or fail with a more helpful error message?
@theseer You are right, my bad.
@tomasliubinas What you're describing for a "completely fresh installation" and then using phpunit . is expected behaviour.
When you do
$ mkdir test
$ cd test
$ composer require phpunit/phpunit
Using version ^6.1 for phpunit/phpunit
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 28 installs, 0 updates, 0 removals
- Installing sebastian/version (2.0.1): Loading from cache
- Installing sebastian/resource-operations (1.0.0): Loading from cache
- Installing sebastian/recursion-context (3.0.0): Loading from cache
- Installing sebastian/object-reflector (1.1.1): Loading from cache
- Installing sebastian/object-enumerator (3.0.2): Loading from cache
- Installing sebastian/global-state (2.0.0): Loading from cache
- Installing sebastian/exporter (3.1.0): Loading from cache
- Installing sebastian/environment (3.0.2): Loading from cache
- Installing sebastian/diff (1.4.1): Loading from cache
- Installing sebastian/comparator (2.0.0): Loading from cache
- Installing doctrine/instantiator (1.0.5): Loading from cache
- Installing phpunit/php-text-template (1.2.1): Loading from cache
- Installing phpunit/phpunit-mock-objects (4.0.1): Loading from cache
- Installing phpunit/php-timer (1.0.9): Loading from cache
- Installing phpunit/php-file-iterator (1.4.2): Loading from cache
- Installing theseer/tokenizer (1.1.0): Loading from cache
- Installing sebastian/code-unit-reverse-lookup (1.0.1): Loading from cache
- Installing phpunit/php-token-stream (1.4.11): Loading from cache
- Installing phpunit/php-code-coverage (5.2.1): Loading from cache
- Installing webmozart/assert (1.2.0): Loading from cache
- Installing phpdocumentor/reflection-common (1.0): Loading from cache
- Installing phpdocumentor/type-resolver (0.2.1): Loading from cache
- Installing phpdocumentor/reflection-docblock (3.1.1): Loading from cache
- Installing phpspec/prophecy (v1.7.0): Loading from cache
- Installing phar-io/version (1.0.1): Loading from cache
- Installing phar-io/manifest (1.0.1): Loading from cache
- Installing myclabs/deep-copy (1.6.1): Loading from cache
- Installing phpunit/phpunit (6.1.3): Downloading (100%)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit suggests installing phpunit/php-invoker (^1.1)
Writing lock file
Generating autoload files
$ ./vendor/bin/phpunit .
PHP Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /home/sb/test/vendor/doctrine/instantiator/tests/DoctrineTest/InstantiatorTest/Exception/InvalidArgumentExceptionTest.php on line 33
then you instruct PHPUnit to execute all tests that it can (recursively) find in .. This will find the tests for PHPUnit itself as well as the tests for PHPUnit's dependencies (./vendor/**/*Test.php).
This is not what you want. It cannot work. You have to point PHPUnit to your tests directory instead of a directory that contains your tests directory.
@theseer This has nothing to do with PHPUnit_Framework_TestCase being gone. This has to do with pointing PHPUnit at the wrong directory.
@sebastianbergmann I do realize that. I was merely pondering if the FATAL ERROR could be avoided for the underlying problem and a more user friendly error message could be provided.
That's not a huge issue. There are no tests and I would not expect to get them running at this point. PHPUnit is dealing at the code level when looking for the class so the argument to show Fatal error is understandable. However from a new user perspective it would be much more nice and probably more informative to handle this case. Getting a nice error message "No test class found" in such dumb scenario for me would mean that my installation is valid, I am set and ready to start writing tests. Meanwhile reading the Fatal error I get a slightly different idea about the possible source of the issue.
Most helpful comment
You're talking past each other.
He did not even write a single test as his reproduction steps show.
Actually, this is not a bug in PHPUnit at all.
The problem lies in the fact that doctrine's instantiator tests are not PHPUnit 6 compliant and their execution is attempted when
.is passed as PHPUnit scans the given directory tree recursively.