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

include(PHPUnit_Extensions_Story_TestCase.php): failed to open stream: No such file or directory #3271

Closed
ThePeach opened this Issue Mar 15, 2014 · 11 comments

Comments

Projects
None yet
5 participants
@ThePeach

ThePeach commented Mar 15, 2014

tl;dr autoloader in PHPUnit >= 3.7 breaks Code Coverage

Given the amount of changes over PHPUnit I've recently hit a big problem which is impacting my tests.
I'm using latest stable version of Yii (1.1.14) and latest stable version of PHPUnit (Currently 4.0.7, although I've had this problem with 3.7 as well).

Running the tests normally is totally fine:

$ phpunit --config=phpunit.xml  unit
PHPUnit 4.0.7 by Sebastian Bergmann.

Configuration read from /mnt/workspace/website/protected/tests/phpunit.xml

...............

Time: 14 ms, Memory: 9.25Mb

OK (15 tests, 1 assertion)

but when trying to generate the Clover code coverage report, I get the following error:

$ phpunit --config=phpunit.xml --coverage-clover=../../coverage.xml unit                                                                                                         
PHPUnit 4.0.7 by Sebastian Bergmann.

Configuration read from /mnt/workspace/website/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/bin/phpunit/php-code-coverage/CodeCoverage/Filter.php(331): class_exists('PHPUnit_Extensi...')
#5 phar:///usr/bin/phpunit/php-code-coverage/CodeCoverage/Filter.php(312): PHP_CodeCoverage_Filter->addDirectoryContainingClassToBlacklist('PHPUnit_Extensi...', 2)
#6 phar:///usr/bin/phpunit/php-code-coverage/CodeCoverage/Filter.php(257): PHP_CodeCoverage_Filter->prefillBlacklist()
#7 phar:///usr/bi 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/works
pace/yii-1.1.14.f0fee9/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

Call Stack:
    0.0006     766568   1. {main}() /usr/bin/phpunit:0
    0.0130    1359368   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:581
    0.0130    1359984   3. PHPUnit_TextUI_Command->run() phar:///usr/bin/phpunit/phpunit/TextUI/Command.php:132
    0.1026    8291984   4. PHPUnit_TextUI_TestRunner->doRun() phar:///usr/bin/phpunit/phpunit/TextUI/Command.php:179
    0.1072    9182488   5. PHPUnit_Framework_TestSuite->run() phar:///usr/bin/phpunit/phpunit/TextUI/TestRunner.php:419
    0.1078    9201304   6. PHPUnit_Framework_TestSuite->run() phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php:722
    0.1079    9201960   7. PHPUnit_Framework_TestCase->run() phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php:722
    0.1080    9201960   8. PHPUnit_Framework_TestResult->run() phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php:764
    0.1317    9441400   9. PHP_CodeCoverage->stop() phar:///usr/bin/phpunit/phpunit/Framework/TestResult.php:734
    0.1807   10972808  10. PHP_CodeCoverage->append() phar:///usr/bin/phpunit/php-code-coverage/CodeCoverage.php:293
    0.1807   10980800  11. PHP_CodeCoverage->applyListsFilter() phar:///usr/bin/phpunit/php-code-coverage/CodeCoverage.php:320
    0.1807   10992008  12. PHP_CodeCoverage_Filter->isFiltered() phar:///usr/bin/phpunit/php-code-coverage/CodeCoverage.php:551
    0.1811   10992056  13. PHP_CodeCoverage_Filter->prefillBlacklist() phar:///usr/bin/phpunit/php-code-coverage/CodeCoverage/Filter.php:257
    0.4889   12023112  14. PHP_CodeCoverage_Filter->addDirectoryContainingClassToBlacklist() phar:///usr/bin/phpunit/php-code-coverage/CodeCoverage/Filter.php:312
    0.4889   12023160  15. class_exists() phar:///usr/bin/phpunit/php-code-coverage/CodeCoverage/Filter.php:331
    0.4889   12023528  16. YiiBase::autoload() phar:///usr/bin/phpunit/php-code-coverage/CodeCoverage/Filter.php:0
    0.4911   12025656  17. PHPUnit_Util_ErrorHandler::handleError() phar:///usr/bin/phpunit/php-code-coverage/CodeCoverage/Filter.php:427

My current pear installation is the following:

$ pear list -a                                                                                                                                                          [27/1969]
INSTALLED PACKAGES, CHANNEL __URI:
==================================
(no packages installed)

INSTALLED PACKAGES, CHANNEL COMPONENTS.EZ.NO:
=============================================
PACKAGE      VERSION STATE
Base         1.8     stable
ConsoleTools 1.6.1   stable

INSTALLED PACKAGES, CHANNEL DOC.PHP.NET:
========================================
(no packages installed)

INSTALLED PACKAGES, CHANNEL PEAR.AGAVI.ORG:
===========================================
(no packages installed)

INSTALLED PACKAGES, CHANNEL PEAR.PHING.INFO:
============================================
(no packages installed)

INSTALLED PACKAGES, CHANNEL PEAR.PHP-BAUSTELLE.DE:
==================================================
(no packages installed)

INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET:
=========================================
PACKAGE          VERSION STATE
Archive_Tar      1.3.11  stable
Cache_Lite       1.7.15  stable
Console_Getopt   1.3.1   stable
HTTP_Request2    2.2.1   stable
Net_URL2         2.0.5   stable
PEAR             1.9.4   stable
Structures_Graph 1.0.4   stable
XML_RPC2         1.1.1   stable
XML_Util         1.2.1   stable

INSTALLED PACKAGES, CHANNEL PEAR.PHPONTRAX.COM:
===============================================
(no packages installed)

INSTALLED PACKAGES, CHANNEL PEAR.PHPUNIT.DE:
============================================
PACKAGE                           VERSION STATE
DbUnit                            1.3.0   stable
File_Iterator                     1.3.4   stable
PHPUnit                           4.0.7   stable
PHPUnit_Selenium                  1.3.3   stable
PHPUnit_SkeletonGenerator         1.2.1   stable
PHPUnit_Story                     1.0.2   stable
PHPUnit_TicketListener_Fogbugz    1.0.0   stable
PHPUnit_TicketListener_GitHub     1.0.0   stable
PHPUnit_TicketListener_GoogleCode 1.0.0   stable
PHPUnit_TicketListener_Trac       1.0.0   stable
PHP_CodeCoverage                  1.2.16  stable
PHP_Invoker                       1.1.3   stable
PHP_Timer                         1.0.5   stable
PHP_TokenStream                   1.2.2   stable
Text_Template                     1.2.0   stable

INSTALLED PACKAGES, CHANNEL PEAR.PROPELORM.ORG:
===============================================
(no packages installed)

INSTALLED PACKAGES, CHANNEL PEAR.SYMFONY.COM:
=============================================
PACKAGE VERSION STATE
Yaml    2.4.2   stable

INSTALLED PACKAGES, CHANNEL PECL.PHP.NET:
=========================================
(no packages installed)

I've read through #1907 but can't make much out of it: as I've understood the problem relies on some sort of conflict between the PHPUnit autoloader and Yii one, but since I'm not particularly well acquainted to the internals of Yii, I'm struggling a bit to implement a solution that could solve this problem, as the original ticket does not really provide a proper solution.

Please also consider that I had to comment from line 11 to line 15 of framework/test/CTestCase.php

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Mar 15, 2014

Well, short answer is to install all phpunit dependencies, and noted above Story too ;)

Ragazzo commented Mar 15, 2014

Well, short answer is to install all phpunit dependencies, and noted above Story too ;)

@ThePeach

This comment has been minimized.

Show comment
Hide comment
@ThePeach

ThePeach Mar 15, 2014

Hi Ragazzo, thanks for the reply.
I've followed the installation instructions at http://phpunit.de/manual/current/en/installation.html#installation.pear and added the few that were missing (namely PHP_CodeCoverage and PHP_Invoker IIRC).

From the pear list I've posted above, do you see anything specific I'm missing?

ThePeach commented Mar 15, 2014

Hi Ragazzo, thanks for the reply.
I've followed the installation instructions at http://phpunit.de/manual/current/en/installation.html#installation.pear and added the few that were missing (namely PHP_CodeCoverage and PHP_Invoker IIRC).

From the pear list I've posted above, do you see anything specific I'm missing?

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Mar 15, 2014

Nope, i dont actually see something wrong (however i switched to codeception but lets not offtop), are you using CTestCase and autloaders registred correctly ? check your pera/PhpUnit if it really have Story extension.

Ragazzo commented Mar 15, 2014

Nope, i dont actually see something wrong (however i switched to codeception but lets not offtop), are you using CTestCase and autloaders registred correctly ? check your pera/PhpUnit if it really have Story extension.

@ThePeach

This comment has been minimized.

Show comment
Hide comment
@ThePeach

ThePeach Mar 15, 2014

The tests I've got are extending from CTestCase, I'm assuming the autoloaders are registered correctly.
The current state of framework/test/CTestCase.php is the following:

$ diff -u CTestCase.php.orig CTestCase.php
--- CTestCase.php.orig  2014-03-15 12:32:36.335980412 +0000
+++ CTestCase.php       2014-03-15 12:33:00.889421166 +0000
@@ -8,11 +8,11 @@
  * @license http://www.yiiframework.com/license/
  */

-require_once('PHPUnit/Runner/Version.php');
-require_once('PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11
+//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_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

Story seems to be there:

$ ls -l /usr/share/php/PHPUnit/Extensions/Story/
total 44
-rw-r--r-- 1 root root 3165 Mar 15 12:25 Autoload.php
-rw-r--r-- 1 root root 2772 Mar 15 12:25 Given.php
drwxr-xr-x 3 root root 4096 Mar 15 12:25 ResultPrinter
-rw-r--r-- 1 root root 3639 Mar 15 12:25 ResultPrinter.php
-rw-r--r-- 1 root root 5740 Mar 15 12:25 Scenario.php
-rw-r--r-- 1 root root 3893 Mar 15 12:25 Step.php
-rw-r--r-- 1 root root 6120 Mar 15 12:25 TestCase.php
-rw-r--r-- 1 root root 2769 Mar 15 12:25 Then.php
-rw-r--r-- 1 root root 2769 Mar 15 12:25 When.php

ThePeach commented Mar 15, 2014

The tests I've got are extending from CTestCase, I'm assuming the autoloaders are registered correctly.
The current state of framework/test/CTestCase.php is the following:

$ diff -u CTestCase.php.orig CTestCase.php
--- CTestCase.php.orig  2014-03-15 12:32:36.335980412 +0000
+++ CTestCase.php       2014-03-15 12:33:00.889421166 +0000
@@ -8,11 +8,11 @@
  * @license http://www.yiiframework.com/license/
  */

-require_once('PHPUnit/Runner/Version.php');
-require_once('PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11
+//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_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

Story seems to be there:

$ ls -l /usr/share/php/PHPUnit/Extensions/Story/
total 44
-rw-r--r-- 1 root root 3165 Mar 15 12:25 Autoload.php
-rw-r--r-- 1 root root 2772 Mar 15 12:25 Given.php
drwxr-xr-x 3 root root 4096 Mar 15 12:25 ResultPrinter
-rw-r--r-- 1 root root 3639 Mar 15 12:25 ResultPrinter.php
-rw-r--r-- 1 root root 5740 Mar 15 12:25 Scenario.php
-rw-r--r-- 1 root root 3893 Mar 15 12:25 Step.php
-rw-r--r-- 1 root root 6120 Mar 15 12:25 TestCase.php
-rw-r--r-- 1 root root 2769 Mar 15 12:25 Then.php
-rw-r--r-- 1 root root 2769 Mar 15 12:25 When.php
@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Mar 15, 2014

hm, not sure then, sorry, but yes this is something with last changes in autoloaders.

Ragazzo commented Mar 15, 2014

hm, not sure then, sorry, but yes this is something with last changes in autoloaders.

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Mar 17, 2014

Member

Try to apply changes from #3211

Member

klimov-paul commented Mar 17, 2014

Try to apply changes from #3211

@ThePeach

This comment has been minimized.

Show comment
Hide comment
@ThePeach

ThePeach Mar 17, 2014

hi klimov-paul, thanks for the reply.
I'm a bit confused by the directory structure, as the current version of yii I'm using (1.1.14) does not provide the /tests directory as I see in the referenced patch.

Am I correctly assuming that I should override the bootstrap.php file that I've got in myApplication/protected/tests ?

ThePeach commented Mar 17, 2014

hi klimov-paul, thanks for the reply.
I'm a bit confused by the directory structure, as the current version of yii I'm using (1.1.14) does not provide the /tests directory as I see in the referenced patch.

Am I correctly assuming that I should override the bootstrap.php file that I've got in myApplication/protected/tests ?

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Mar 17, 2014

Member

Add the following code to the top of your bootstrap file:

// Support PHPUnit <=3.7 and >=3.8
if (file_exists('PHPUnit/Framework/TestCase.php'))
  require_once('PHPUnit/Framework/TestCase.php'); // <= 3.7
else
  require_once('src/Framework/TestCase.php'); // >= 3.8
// make sure non existing PHPUnit classes do not break with Yii autoloader
Yii::$enableIncludePath = false;
Member

klimov-paul commented Mar 17, 2014

Add the following code to the top of your bootstrap file:

// Support PHPUnit <=3.7 and >=3.8
if (file_exists('PHPUnit/Framework/TestCase.php'))
  require_once('PHPUnit/Framework/TestCase.php'); // <= 3.7
else
  require_once('src/Framework/TestCase.php'); // >= 3.8
// make sure non existing PHPUnit classes do not break with Yii autoloader
Yii::$enableIncludePath = false;
@ThePeach

This comment has been minimized.

Show comment
Hide comment
@ThePeach

ThePeach Mar 17, 2014

$ phpunit unit
PHP Warning:  require_once(src/Framework/TestCase.php): failed to open stream: No such file or directory in /mnt/workspace/website/protected/tests/bootstrap.php on line 7
...

phpunit 4.0.7 installed via pear tells me that the file is here:

$ pear list-files phpunit/phpunit
...
php    /usr/share/php/PHPUnit/Framework/TestCase.php
...

Also, please note that the tests without coverage were running fine, the error seemed to be specific to the coverage report being generated.

ThePeach commented Mar 17, 2014

$ phpunit unit
PHP Warning:  require_once(src/Framework/TestCase.php): failed to open stream: No such file or directory in /mnt/workspace/website/protected/tests/bootstrap.php on line 7
...

phpunit 4.0.7 installed via pear tells me that the file is here:

$ pear list-files phpunit/phpunit
...
php    /usr/share/php/PHPUnit/Framework/TestCase.php
...

Also, please note that the tests without coverage were running fine, the error seemed to be specific to the coverage report being generated.

@samdark samdark added the type:bug label Mar 31, 2014

@samdark samdark added this to the 1.1.15 milestone Mar 31, 2014

@samdark samdark self-assigned this Mar 31, 2014

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Mar 31, 2014

Member

Verified. I'll solve it before 1.1.15.

Member

samdark commented Mar 31, 2014

Verified. I'll solve it before 1.1.15.

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Oct 23, 2014

Member

Closing since Pear is officially deprecated.

Member

samdark commented Oct 23, 2014

Closing since Pear is officially deprecated.

@samdark samdark closed this Oct 23, 2014

@cebe cebe removed this from the 1.1.16 milestone Oct 23, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment