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

CTestCase PHPUnit 3.7.10 autoload fails #1907

Closed
Ragazzo opened this issue Dec 31, 2012 · 61 comments
Closed

CTestCase PHPUnit 3.7.10 autoload fails #1907

Ragazzo opened this issue Dec 31, 2012 · 61 comments

Comments

@Ragazzo
Copy link

Ragazzo commented Dec 31, 2012

I know there are some issues about that (phpunit < 3.7.10) and looks like there were solved but, i got this problem, need to notice that problem occures when tests fails:
When i run unit tests, Yii::autoloader throws Exceptions on not found files, this files:

PHP_invoker.php, PHPUnit_Extensions_Database_TestCase.php, PHPUnit_Extensions_Story_TestCase.php

on
YiiBase::autoload() ...\php\pear\PHPUnit\Util\GlobalState.php:0
So i found that problem again in autoloader order, if i comment spl_autoload_register(array('YiiBase','autoload')); // put yii's autoloader at the end than no exceptions will be thrown by Yii::autoload() even if there is a fail test. But if i run WebTestCase tests Yii autoload throws errors again.
So is it my problem or its a Yii bug or phpunit bug? Btw. spl autoloaders list is correct (Yii autoload is the last one). Could it be because of in YiiBase at the end of the file there is already spl_autoload_register(array('YiiBase','autoload')); ?

@samdark
Copy link
Member

samdark commented Jan 1, 2013

Which Yii version have you tried?

@Ragazzo
Copy link
Author

Ragazzo commented Jan 1, 2013

@samdark 1.1.13 but does not matter now, i've discovered that it was my fault, not Yii, i forgot to install some packages, but anyway i found bug on pear installer with readlink function(does not work on XP dont know why). Will close this one.

@Ragazzo Ragazzo closed this as completed Jan 1, 2013
@nezaboravi
Copy link

Actually this is not quite correct and should not be closed.
If you are on windows, you can not install PHP_Invoker, since it depends on php extension pcntl, which does not exists for Windows platform. But i think its not a Yii bug, its more likely phpunit bug, but since its a third party, phpunit will not fix it. So for now, looks like on windows platform this can not be solved?

@Ragazzo
Copy link
Author

Ragazzo commented Jan 31, 2013

@nezaboravi u can find PHP_Invoker package on phpunit.de site, not through pear, and install it manually, works for me. (pear.phpunit.de)

@ahbowers
Copy link

ahbowers commented Mar 6, 2013

I had the exact same problem but the solution ended up being pretty simple.

Here's how I solved the problem for each file:

PHP_Invoker.php

I suspect this would have worked:

pear install phpunit/PHP_Invoker

but instead I did this:

  • went to pear.phpunit.de
  • manually downloaded PHP_Invoker utility class
  • unzipped the file on my daughter's mac (I'm running Windows)
  • put the "Invoker" directory under C:\xampp\php\pear\PHP
  • put the "Invoker.php" file under C:\xampp\php\pear\PHP

PHPUnit_Extensions_Database_TestCase.php

pear install phpunit/dbUnit

PHPUnit_Extensions_Story_TestCase.php

pear install phpunit/PHPUnit_Story

@wilwade
Copy link

wilwade commented Apr 5, 2013

Just an additional note that:

put the "Invoker" directory under C:\xampp\php\pear\PHP
put the "Invoker.php" file under C:\xampp\php\pear\PHP

Also works for those on OSX using MAMP and do not want to go through the mess of getting pcntl running. Although the directory is different. Usually something along the lines of:

$ pear config-get php_dir

Then the subdirectory PHP of the output.
(Mine: /Applications/MAMP/bin/php/php5.4.10/share/pear/PHP)

@Sharom
Copy link

Sharom commented Jun 14, 2013

It is a bug in YiiBase::autoload(). Incorrect implementation of autoloader if you want.
This implementation breaks logic of class_exists() and should be fixed.

@cebe
Copy link
Member

cebe commented Jun 14, 2013

Can you give a bit more details about what you are talking about? Code line and what is wrong exactly? :)

@Sharom
Copy link

Sharom commented Jun 14, 2013

Existence of the file should be checked before include.
And if file does not exists, autoload() should return false.

But it triggers a warning. An you should to use require instead of include.

And what is it?:

return class_exists($className,false) || interface_exists($className,false);

If autoloader is asked it means, that class doesn't exist.
If in your autoloader realy loaded file with expected class — return true, else — false.

For example:

require_once __DIR__.'/../vendor/yiisoft/yii/framework/YiiBase.php';
class_exists('SomeMissingClass', true);
Warning: include(SomeMissingClass.php): failed to open stream: No such file or directory in /.../YiiBase.php on line 421

About problem with PHPUnit:

Configuration read from /Users/roman/Projects/swiftmailer-yii/phpunit.xml.dist

PHP Fatal error:  Uncaught exception 'PHPUnit_Framework_Error_Warning' with message 'include(PHPUnit_Extensions_Database_TestCase.php): failed to open stream: No such file or directory' in /Users/roman/Projects/swiftmailer-yii/vendor/yiisoft/yii/framework/YiiBase.php:421
Stack trace:
#0 /Users/roman/Projects/swiftmailer-yii/vendor/yiisoft/yii/framework/YiiBase.php(421): PHPUnit_Util_ErrorHandler::handleError(2, 'include(PHPUnit...', '/Users/roman/Pr...', 421, Array)
#1 /Users/roman/Projects/swiftmailer-yii/vendor/yiisoft/yii/framework/YiiBase.php(421): YiiBase::autoload()
#2 [internal function]: YiiBase::autoload('PHPUnit_Extensi...')
#3 [internal function]: spl_autoload_call('PHPUnit_Extensi...')
#4 /Users/roman/.local/phpunit37/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Filter.php(334): class_exists('PHPUnit_Extensi...')
#5 /Users/roman/.local/phpunit37/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Filter.php(317): PHP_CodeCoverage_Filter->addDirectoryContainingClassToBlacklist('PHPUnit_Extensi...', 2)
#6 /Users/r in /Users/roman/Projects/swiftmailer-yii/vendor/yiisoft/yii/framework/YiiBase.php on line 421

Look at :

#4 /Users/roman/.local/phpunit37/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Filter.php(334): 
class_exists('PHPUnit_Extensi...')

Calling of class_exists() triggers warning. PHPUnit handles it and convert to Exception. Test fails!

@Ragazzo
Copy link
Author

Ragazzo commented Jun 14, 2013

Yes it is a bug, but fix can not be applied because of BC. You need to install all dep. packages to avoid this bug.

@Ragazzo
Copy link
Author

Ragazzo commented Jun 14, 2013

See this PR #2324

@Sharom
Copy link

Sharom commented Jun 14, 2013

What can I say. Yii...

@Ragazzo
Copy link
Author

Ragazzo commented Jun 14, 2013

Use symfony, kohana, or even laravel, feel free to choose ;)

@Sharom
Copy link

Sharom commented Jun 14, 2013

My choise is Symfony 2. But now I work with existing project based on Yii.

@cebe
Copy link
Member

cebe commented Jun 14, 2013

Yii 1.1 was created before there was PSR-0 and namespaces so autoloader was created to rely on include path. This works really nice when following the yii way but causes problems like this with external libraries.
You can easily prepend another autoloader before yii's to handle external library classes:
http://www.yiiframework.com/doc/api/1.1/YiiBase#registerAutoloader-detail

This case is special as PHPUnit tries to detect whether extension is loaded by trying to autoload the classes.
It is not a common case things like this happen so it was not considered when autoloader was created.
Yii 2 will of course follow PSR-0 and solve the problem.

A workaround for this could be to make a custom autoloader, tell him the classes loaded by PHPUnit that are not installed and return true for them without doing anything else. prepend that autoloader before yii autoloader with the function given above. Sounds a bit hacky but will help you in this special case.

@Sharom
Copy link

Sharom commented Jun 17, 2013

@cebe, PEAR recommendation has been.

@jorgebg
Copy link

jorgebg commented Aug 8, 2013

I solved it installing the following packages:

pear install phpunit/PHPUnit
pear install phpunit/PHPUnit_Selenium
pear install phpunit/PHP_Invoker
pear install phpunit/PHPUnit_Story
pear install phpunit/DbUnit

@Ragazzo
Copy link
Author

Ragazzo commented Aug 8, 2013

yes, that because phpunit uses them internally and when calling class_exists() phpunit do not call it with second param true that forces php to include file and Yii autoload triggers error. so overall it is phpunit bug.

@Sharom
Copy link

Sharom commented Aug 8, 2013

It is not phpunit bug. It is Yii bug. Yii brakes class_exists() logic.

@Ragazzo
Copy link
Author

Ragazzo commented Aug 8, 2013

@Sharom please investigate phpunit code, and stop posting this bullshit, thanks.
sebastianbergmann/phpunit#754
https://github.com/sebastianbergmann/phpunit/blob/master/PHPUnit/Util/GlobalState.php#L428

@cebe
Copy link
Member

cebe commented Aug 8, 2013

Calm down boys, yii autoloader is not perfect and PHPUnits usage of class_exists() is also not nice, but we can not change that right now. Workarounds have been described so please stop fighting here.

@Ragazzo
Copy link
Author

Ragazzo commented Aug 8, 2013

lol, those symfony guys are so symfony) they can not have conversations in normal way, they always trying to say "Yii sucks, Kohana sucks, OtherPhpFw sucks" ))

@cebe
Copy link
Member

cebe commented Aug 8, 2013

Nice method name "addDirectoryContainingClassToPHPUnitFilesList" :-D

@Ragazzo
Copy link
Author

Ragazzo commented Aug 8, 2013

@cebe check this out https://gist.github.com/DavertMik/4309132 =D

@aditya-
Copy link

aditya- commented Oct 25, 2013

Hi Team,

I am running acceptance test cases using phpunit-selenium, and codeception ... while executing my phpunit i am getting [RuntimeException]
include(PHP_Invoker.php): failed to open stream: No such file or directory
error ..

even i followed this : #1907 (comment)

and also i re-installed invoker .. but still issue was not solve any suggestions to fix the problem

yii version : 1.1.13
os: Ubuntu 
selenium version : selenium-server-standalone-2.35.0.jar
codeception version: 1.7.1
PHPUnit 3.7.27 

output :


winzest@winzest-System-Product-Name:/usr/share/nginx/www/testprep/app/tests/acceptance/testprerp$ php codecept.phar run acceptance highCept.php --debug
Codeception PHP Testing Framework v1.7.1
Powered by PHPUnit 3.7.27 by Sebastian Bergmann.


Acceptance Tests (1) -----------------------
Running highCept.php                    
Scenario:
* I am on page "/user/login"
* I resize window 1224,768
* I fill field "#LoginForm_username","[email protected]"
* I fill field "#LoginForm_password","apple@123"
* I click "input[type="submit"]"
* I click "Dashboard"
* I click "Practice"
 ERROR 

---------------------------------------------


Time: 23.72 seconds, Memory: 15.50Mb

There was 1 error:

---------
1) highCept.php
Sorry, I couldn't click "Practice":
RuntimeException: Call to undefined method WebGuy\hlprSteps::prctQuizAttmpt


  [RuntimeException]  


  [ErrorException]                                                            
  include(PHP_Invoker.php): failed to open stream: No such file or directory  


Exception trace:
 () at /usr/share/nginx/www/testprep/app/vendor/yiisoft/yii/framework/YiiBase.php:421
 Codeception\Subscriber\ErrorHandler->errorHandler() at /usr/share/nginx/www/testprep/app/vendor/yiisoft/yii/framework/YiiBase.php:421
 YiiBase::autoload() at /usr/share/nginx/www/testprep/app/vendor/yiisoft/yii/framework/YiiBase.php:421
 YiiBase::autoload() at n/a:n/a
 spl_autoload_call() at n/a:n/a
 class_exists() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/vendor/phpunit/phpunit/PHPUnit/Util/GlobalState.php:409
 PHPUnit_Util_GlobalState::addDirectoryContainingClassToPHPUnitFilesList() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/vendor/phpunit/phpunit/PHPUnit/Util/GlobalState.php:388
 PHPUnit_Util_GlobalState::phpunitFiles() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/vendor/phpunit/phpunit/PHPUnit/Util/Filter.php:76
 PHPUnit_Util_Filter::getFilteredStacktrace() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/src/Codeception/Subscriber/Console.php:231
 Codeception\Subscriber\Console->printException() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/src/Codeception/Subscriber/Console.php:216
 Codeception\Subscriber\Console->printScenarioFail() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/src/Codeception/Subscriber/Console.php:180
 Codeception\Subscriber\Console->printFail() at n/a:n/a
 call_user_func() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php:164
 Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php:53
 Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/src/Codeception/PHPUnit/ResultPrinter/UI.php:21
 Codeception\PHPUnit\ResultPrinter\UI->printDefect() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/vendor/phpunit/phpunit/PHPUnit/TextUI/ResultPrinter.php:225
 PHPUnit_TextUI_ResultPrinter->printDefects() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/vendor/phpunit/phpunit/PHPUnit/TextUI/ResultPrinter.php:295
 PHPUnit_TextUI_ResultPrinter->printErrors() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/vendor/phpunit/phpunit/PHPUnit/TextUI/ResultPrinter.php:155
 PHPUnit_TextUI_ResultPrinter->printResult() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/src/Codeception/Codecept.php:144
 Codeception\Codecept->printResult() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/src/Codeception/Command/Run.php:103
 Codeception\Command\Run->execute() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:244
 Symfony\Component\Console\Command\Command->run() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:897
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:191
 Symfony\Component\Console\Application->doRun() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:121
 Symfony\Component\Console\Application->run() at phar:///usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar/codecept:29
 require_once() at /usr/share/nginx/www/testprep/app/tests/acceptance/testprerp/codecept.phar:7


run [-c|--config="..."] [--report] [--html] [--xml] [--tap] [--json] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--coverage] [--no-exit] [--defer-flush] [-g|--group="..."] [-s|--skip="..."] [--skip-group="..."] [suite] [test]


please suggest me something to fix the problem ..

@Ragazzo any ideas ? @yiisoft ... please look at here once

@samdark
Copy link
Member

samdark commented Oct 25, 2013

Should be either your PHPUnit local issue or Codeception issue. These exact tests are runned constantly via Travis (that's PHPUnit w/o Codeception).

@aditya-
Copy link

aditya- commented Oct 26, 2013

Hi @samdark

Thanks for your replay ... Any suggestions to fix

[RuntimeException]

[ErrorException]
include(PHP_Invoker.php): failed to open stream: No such file or directory

like adjusting yiibase.php or adding some packages anything ?

@aditya-
Copy link

aditya- commented Oct 26, 2013

@DavertMik please look here once

@Ragazzo
Copy link
Author

Ragazzo commented Oct 26, 2013

are you sure you have installed PHP_Invoker? go to your pear folder and check if it there, if no you can download package manually and put it under that folder.

@samdark
Copy link
Member

samdark commented Oct 26, 2013

@Sharom that's not relevant unless you're suggesting Yii2 :)

@aditya-
Copy link

aditya- commented Oct 26, 2013

I tried both ways..

  1. directly installing via package
  2. Copy files to pear folder

but still its not working .. getting headache with this ..

Anyone please suggest ..

@samdark
Copy link
Member

samdark commented Oct 26, 2013

@aditya- can you try PhpUnit w/o Codeception? i.e. from tests dir run phpunit framework.

@cebe
Copy link
Member

cebe commented Oct 26, 2013

@aditya- make sure yii autoloader is the last one in the autoloader chain.

OR include PHP_Invoker.php explicitly in phpunit bootstrap file to work around it.

@aditya-
Copy link

aditya- commented Oct 26, 2013

Hi @samdark
yes i have some unit + functional test cases which are written in phpunit ... its there in tests folder .. after i run those functional tests ..after some scenarios i am getting same error ..

[ErrorException]

include(PHP_Invoker.php): failed to open stream: No such file or directory

@aditya-
Copy link

aditya- commented Oct 26, 2013

@cebe

Thanks for the idea ... i am just wondering still its throwing same error

@samdark
Copy link
Member

samdark commented Oct 26, 2013

@aditya-
Copy link

aditya- commented Oct 26, 2013

yeah !!!

First of all Thanks @samdark .. For helping me to fix this issue ..

i tried this before i posted here.. i got this from Google.. i think so but ... this is also not fixed the issue .. after that i tried manually replacing invoker files in pear folder

@Sharom
Copy link

Sharom commented Oct 26, 2013

@samdark, на сколько я знаю, ты из России. Так вот, на чистом русском: Yii - дерьмо. Часть 1 и часть 2.

@samdark
Copy link
Member

samdark commented Oct 26, 2013

@Sharom ну ок :)

@yvgorshkov
Copy link

@Sharom, не будь балаболом, приведи факты.

@Sharom
Copy link

Sharom commented Oct 26, 2013

В чем ОК? Вы делаете дерьмо.

@Sharom
Copy link

Sharom commented Oct 26, 2013

@yvgorshkov, станешь программистом, сам увидишь факты.

@yvgorshkov
Copy link

@samdark не обращай внимания, таких балаболов и хYесосоB дохера. Возможно он просто бухой.
@Sharom завались.

@Sharom
Copy link

Sharom commented Oct 26, 2013

@yvgorshkov, я трезв. Я не переношу дерьмовые продукты. Вроде Yii.
Масса времени, потраченная в пустую.

@samdark
Copy link
Member

samdark commented Oct 26, 2013

For English-speaking people: sorry that we're using Russian. Don't spend time translating, it's just offtopic chat that doesn't have anything to do with the problem described in the ticket.

@yvgorshkov не стоит переходить на личности и материться.

@Sharom

  1. github, а тем более тикет по конкретной проблеме — ну лучшее место для подобных заявлений. Просто не в тему. Хотите поговорить об этом — пишите на форум http://yiiframework.ru/ или http://yiiframework.com/ в русскоязычный раздел. Ну или можно мне в почту: [email protected].
  2. Каждый имеет право на своё мнение, но если хотите что-то доказать остальным, желательно всё-таки аргументировать.

@aditya-
Copy link

aditya- commented Oct 26, 2013

@samdark

lol .. Thanks for understanding our problem ;-) but yii is great framework ..

@aditya-
Copy link

aditya- commented Oct 26, 2013

@samdark
i am translating every bit till now .. for any luck ..finally you clarified .. 👍

@samdark
Copy link
Member

samdark commented Oct 26, 2013

@aditya- so was your problem solved? If not, get to Yii IRC and ping me. That will be faster.

@aditya-
Copy link

aditya- commented Oct 26, 2013

No @samdark .. not yet fixed .. yes i will cum there .. Thank you ..

@DavertMik
Copy link

@aditya- Please add this line

YiiBase::$enableIncludePath=false;

Somewhere in bootstrap file.
For the details you can look into my PR #2324

If this not helps: install the PHP_Invoker from PEAR channel.


@Sharom No one here is talking about new projects, right?

My choise is Symfony 2. But now I work with existing project based on Yii.

I understand your feelings. My choice is Rails and I suffered that hard when I had to use Symfony :)
If you really feel that terrible you just change your job and spam into issues on GitHub.

@Sharom
Copy link

Sharom commented Oct 28, 2013

This problem with Yii could be fixed.
We need just fix Yii autoloader as it described in PHP documentation.
But some people fear breaking code.

Yes it is a bug, but fix can not be applied because of BC. You need to install all dep. packages to avoid this bug.

This is a well-founded fear. But, on the other hand, the current behavior of the code breaks behavior of the class_exists(). And class_exists is the function of the SPL.

In my opinion it is a greater evil.

@aditya-
Copy link

aditya- commented Nov 6, 2013

Sorry for no replay .. i was on vacation till now ..

@DavertMik

YiiBase::$enableIncludePath=false;

Really works great .. issue was fixed .. Thank you .. 👍

Thank you to all who helped me.. Specially to @samdark 👍

@arfeen
Copy link
Contributor

arfeen commented Nov 7, 2013

@pennyp Thanks for your solution. I was experiencing the same problem and followed your instructions, then it worked smoothly.

@1nstinct
Copy link

1nstinct commented Oct 8, 2014

I had tried to fix PHPUnit + Yii for a two days before found a "YiiBase::$enableIncludePath=false;" solution. I thought Yii is more better. It was my first disappointment about Yii ((

@marcovtwout
Copy link
Member

Shouldn't we place this line somewhere in the default test code? YiiBase::$enableIncludePath=false;

See also: Codeception/Codeception#234 (comment)

@marcovtwout
Copy link
Member

Does PHPUnit 4.6 fix this issue?

https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-4.6.md
"Fixed sebastianbergmann/phpunit#1599: The PHAR build of PHPUnit no longer uses an autoloader to load PHPUnit's own classes and instead statically loads all classes on startup"

@marcovtwout
Copy link
Member

Unfortunately, no:

PHPUnit 4.6.2 by Sebastian Bergmann and contributors.

Configuration read from S:\www\xxx\application\tests\phpunit.xml

F
Warning: include(PHP_Invoker.php): failed to open stream: No such file or directory in S:\www\xxx\application\vendor\yiisoft\yii\framework\YiiBase.php on line 432

@marcovtwout
Copy link
Member

(this issue still exists in PHPUnit 6 when running tests from NetBeans)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests