Hi all, this has bothered me for a long time but now the problem has increased to a point I cannot ignore it anymore.
tl;dr: PHPUnit 3.7 broke backward compatibility
Basically if you upgrade to PHPUnit 3.7 or above, and try to run the tests you start getting a series of errors.
Some problems are solved by commenting parts of framework/test/CTestCase.php:
//require_once('PHPUnit/Runner/Version.php');
// require_once('PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11
//require_once('PHPUnit/Autoload.php');
as these two files are not available anymore - it seems - on the phar packaged PHPUnit.
now, by removing the PHPUnit autoloader you should rely on the newest autoloader that leverages on the PSR-0 which can be impossibile to use in certain environments (at least until we start developing for Yii2).
There’s a lengthy bug report that goes into this and beyond:
Someone was suggesting to implement a custom autoloader for phpunit in the meantime (or grab the old Autoloader and package it?)
I’d like to know what can be done to fix this situation as our dev environments are currently broken and I’m a bit at loss here.
Thanks for anyone who likes to contribute to this thread.
[edit] as a solution it’s been suggested to stay on 3.6, which is fine, but we’ve found some problems on 3.6 that have been fixed in later releases, so this might be not a solution.
I have the same issue. It seems that all require_once calls in framework/test/CTestCase.php should be removed and autoloader should be rewritten.
Today my PHPUnit was updated to the latest stable 4.0.4 and I can’t downgrade to lower version.
install phpunit/PHPUnit-3.7
Failed to download phpunit/PHPUnit, version "3.7", latest release is version 4.0.4, stability "stable", use "channel://pear.phpunit.de/PHPUnit-4.0.4" to install
What version of the Framework are you using? The CTestCase class in 1.1.13 no longer uses the 2nd require_once, although it does include a workaround for "<= 3.6.11." I think your issue may have been addressed as I am running unit tests just fine with 1.1.13 and PHPUnit 3.7.21.
The question of the topic was about phpunit, which version is greater that 3.7.
I faced with the similar issue today. I installed an extension to phpunit and it was automatically updated to the latest version 4.0.4. And I realized that there is no chance to do a small downgrade. Even though I would like to use modern software, which is officially supported.
I’m on 1.1.14-f0fee9 and this is what I’ve got on frameworks/test/CTestCase.php:
require_once('PHPUnit/Runner/Version.php');
require_once('PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11
spl_autoload_unregister(array('YiiBase','autoload'));
require_once('PHPUnit/Autoload.php');
spl_autoload_register(array('YiiBase','autoload')); // put yii's autoloader at the end
if (in_array('phpunit_autoload', spl_autoload_functions())) { // PHPUnit >= 3.7 'phpunit_autoload' was obsoleted
spl_autoload_unregister('phpunit_autoload');
Yii::registerAutoloader('phpunit_autoload');
}
I actually missed the Filesystem.php line in my initial post which I also commented.
The situation is the following:
running phpunit 3.7 with the unedited CTestCase.php I get the following:
$ phpunit unit
PHP Warning: require_once(PHPUnit/Runner/Version.php): failed to open stream: No such file or directory in /mnt/workspace/yii-1.1.14.f0fee9/framework/test/CTestCase.php on line 11
PHP Stack trace:
PHP 1. {main}() /usr/share/php/phpunit/phpunit.phar:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/share/php/phpunit/phpunit.phar:531
PHP 3. PHPUnit_TextUI_Command->run() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/TextUI/Command.php:129
PHP 4. PHPUnit_Runner_BaseTestRunner->getTest() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/TextUI/Command.php:150
PHP 5. PHPUnit_Framework_TestSuite->addTestFiles() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Runner/BaseTestRunner.php:96
PHP 6. PHPUnit_Framework_TestSuite->addTestFile() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Framework/TestSuite.php:416
PHP 7. PHPUnit_Util_Fileloader::checkAndLoad() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Framework/TestSuite.php:355
PHP 8. PHPUnit_Util_Fileloader::load() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Util/Fileloader.php:76
PHP 9. include_once() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Util/Fileloader.php:92
PHP 10. YiiBase::autoload() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Util/Fileloader.php:0
PHP 11. include() /mnt/workspace/yii-1.1.14.f0fee9/framework/YiiBase.php:401
Warning: require_once(PHPUnit/Runner/Version.php): failed to open stream: No such file or directory in /mnt/workspace/yii-1.1.14.f0fee9/framework/test/CTestCase.php on line 11
now if I comment out the include Version.php I get:
$ phpunit unit
PHP Warning: require_once(PHPUnit/Util/Filesystem.php): failed to open stream: No such file or directory in /mnt/workspace/yii-1.1.14.f0fee9/framework/test/CTestCase.php on line 12
PHP Stack trace:
PHP 1. {main}() /usr/share/php/phpunit/phpunit.phar:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/share/php/phpunit/phpunit.phar:531
PHP 3. PHPUnit_TextUI_Command->run() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/TextUI/Command.php:129
PHP 4. PHPUnit_Runner_BaseTestRunner->getTest() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/TextUI/Command.php:150
PHP 5. PHPUnit_Framework_TestSuite->addTestFiles() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Runner/BaseTestRunner.php:96
PHP 6. PHPUnit_Framework_TestSuite->addTestFile() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Framework/TestSuite.php:416
PHP 7. PHPUnit_Util_Fileloader::checkAndLoad() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Framework/TestSuite.php:355
PHP 8. PHPUnit_Util_Fileloader::load() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Util/Fileloader.php:76
PHP 9. include_once() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Util/Fileloader.php:92
PHP 10. YiiBase::autoload() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Util/Fileloader.php:0
PHP 11. include() /mnt/workspace/yii-1.1.14.f0fee9/framework/YiiBase.php:401
Warning: require_once(PHPUnit/Util/Filesystem.php): failed to open stream: No such file or directory in /mnt/workspace/yii-1.1.14.f0fee9/framework/test/CTestCase.php on line 12
If again I comment the include Filesystem.php line I get:
$ phpunit unit
PHP Warning: require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory in /mnt/workspace/yii-1.1.14.f0fee9/framework/test/CTestCase.php on line 15
PHP Stack trace:
PHP 1. {main}() /usr/share/php/phpunit/phpunit.phar:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/share/php/phpunit/phpunit.phar:531
PHP 3. PHPUnit_TextUI_Command->run() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/TextUI/Command.php:129
PHP 4. PHPUnit_Runner_BaseTestRunner->getTest() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/TextUI/Command.php:150
PHP 5. PHPUnit_Framework_TestSuite->addTestFiles() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Runner/BaseTestRunner.php:96
PHP 6. PHPUnit_Framework_TestSuite->addTestFile() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Framework/TestSuite.php:416
PHP 7. PHPUnit_Util_Fileloader::checkAndLoad() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Framework/TestSuite.php:355
PHP 8. PHPUnit_Util_Fileloader::load() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Util/Fileloader.php:76
PHP 9. include_once() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Util/Fileloader.php:92
PHP 10. YiiBase::autoload() phar:///usr/share/php/phpunit/phpunit.phar/PHPUnit/Util/Fileloader.php:0
PHP 11. include() /mnt/workspace/yii-1.1.14.f0fee9/framework/YiiBase.php:401
Warning: require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory in /mnt/workspace/yii-1.1.14.f0fee9/framework/test/CTestCase.php on line 15
At the very end if I comment out also the include Autoload.php line I can get the test passing.
At the moment I cannot replicate the error with the autoloader I had previously, but this situation should suffice to raise a few problems of backward compatibility with phpunit greater than 3.7
OK, I’ve found that I won’t get any error if I just run
$ phpunit unit
but I get this when trying to create the coverage report:
$ phpunit --log-junit ../../build/logs/junit.xml --coverage-clover ../../build/logs/clover.xml --coverage-html ../../build/coverage/ unit
PHPUnit 3.7.20 by Sebastian Bergmann.
Configuration read from /mnt/workspace/theframeworks.com/protected/tests/phpunit.xml
PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Error_Warning' with message 'include(PHPUnit_Extensions_Story_TestCase.php): failed to open stream: No such file or directory' in /mnt/workspace/yii-1.1.
14.f0fee9/framework/YiiBase.php:427
Stack trace:
#0 /mnt/workspace/yii-1.1.14.f0fee9/framework/YiiBase.php(427): PHPUnit_Util_ErrorHandler::handleError(2, 'include(PHPUnit...', '/mnt/workspace/...', 427, Array)
#1 /mnt/workspace/yii-1.1.14.f0fee9/framework/YiiBase.php(427): YiiBase::autoload()
#2 [internal function]: YiiBase::autoload('PHPUnit_Extensi...')
#3 [internal function]: spl_autoload_call('PHPUnit_Extensi...')
#4 phar:///usr/share/php/phpunit/phpunit.phar/PHP_CodeCoverage-1.2.10/PHP/CodeCoverage/Filter.php(330): class_exists('PHPUnit_Extensi...')
#5 phar:///usr/share/php/phpunit/phpunit.phar/PHP_CodeCoverage-1.2.10/PHP/CodeCoverage/Filter.php(316): PHP_CodeCoverage_Filter->addDirectoryContainingClassToBlacklist('PHPUnit_Extensi...', 2)
#6 phar:///usr/share/php/phpunit/phpunit.phar/PHP_CodeCoverage-1.2.10/PHP/Code in /mnt/workspace/yii-1.1.14.f0fee9/framework/YiiBase.php on line 427
Fatal error: Uncaught exception 'PHPUnit_Framework_Error_Warning' with message 'include(PHPUnit_Extensions_Story_TestCase.php): failed to open stream: No such file or directory' in /mnt/workspace/yii-1.1.14.f0
fee9/framework/YiiBase.php on line 427
PHPUnit_Framework_Error_Warning: include(PHPUnit_Extensions_Story_TestCase.php): failed to open stream: No such file or directory in /mnt/workspace/yii-1.1.14.f0fee9/framework/YiiBase.php on line 427
...
without options everything is fine:
$ phpunit unit
PHPUnit 3.7.20 by Sebastian Bergmann.
Configuration read from /mnt/workspace/site.com/protected/tests/phpunit.xml
......................
Time: 2 seconds, Memory: 29.50Mb