Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Warning include PHPUnit_Extensions_Story_TestCase.php failed to open stream

I use php Yii framework and run functional test. I have install PHPUnit_Story

pear install phpunit/PHPUnit_Story

and the extension is there

/usr/share/php/PHPUnit/Extensions/Story

But i get error:

PHP Warning:  include(PHPUnit_Extensions_Story_TestCase.php): failed to open stream: No such file or directory in /var/www/yii/framework/YiiBase.php on line 427
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:581
PHP   3. PHPUnit_TextUI_Command->run() phar:///usr/bin/phpunit/phpunit/TextUI/Command.php:132
PHP   4. PHPUnit_TextUI_TestRunner->doRun() phar:///usr/bin/phpunit/phpunit/TextUI/Command.php:179
PHP   5. PHPUnit_TextUI_ResultPrinter->printResult() phar:///usr/bin/phpunit/phpunit/TextUI/TestRunner.php:425
PHP   6. PHPUnit_TextUI_ResultPrinter->printFailures() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:177
PHP   7. PHPUnit_TextUI_ResultPrinter->printDefects() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:322
PHP   8. PHPUnit_TextUI_ResultPrinter->printDefect() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:243
PHP   9. PHPUnit_TextUI_ResultPrinter->printDefectTrace() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:254
PHP  10. PHPUnit_Util_Filter::getFilteredStacktrace() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:290
PHP  11. PHPUnit_Util_Blacklist->isBlacklisted() phar:///usr/bin/phpunit/phpunit/Util/Filter.php:105
PHP  12. PHPUnit_Util_Blacklist->initialize() phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:74
PHP  13. class_exists() phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:110
PHP  14. spl_autoload_call() phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:110
PHP  15. YiiBase::autoload() phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:0
PHP Warning:  include(): Failed opening 'PHPUnit_Extensions_Story_TestCase.php' for inclusion (include_path='.:/var/www/yii-example/protected/components:/var/www/yii-example/protected/models:/usr/share/php:/usr/share/pear') in /var/www/yii/framework/YiiBase.php on line 427
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:581
PHP   3. PHPUnit_TextUI_Command->run() phar:///usr/bin/phpunit/phpunit/TextUI/Command.php:132
PHP   4. PHPUnit_TextUI_TestRunner->doRun() phar:///usr/bin/phpunit/phpunit/TextUI/Command.php:179
PHP   5. PHPUnit_TextUI_ResultPrinter->printResult() phar:///usr/bin/phpunit/phpunit/TextUI/TestRunner.php:425
PHP   6. PHPUnit_TextUI_ResultPrinter->printFailures() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:177
PHP   7. PHPUnit_TextUI_ResultPrinter->printDefects() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:322
PHP   8. PHPUnit_TextUI_ResultPrinter->printDefect() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:243
PHP   9. PHPUnit_TextUI_ResultPrinter->printDefectTrace() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:254
PHP  10. PHPUnit_Util_Filter::getFilteredStacktrace() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:290
PHP  11. PHPUnit_Util_Blacklist->isBlacklisted() phar:///usr/bin/phpunit/phpunit/Util/Filter.php:105
PHP  12. PHPUnit_Util_Blacklist->initialize() phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:74
PHP  13. class_exists() phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:110
PHP  14. spl_autoload_call() phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:110
PHP  15. YiiBase::autoload() phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:0
like image 683
leiyonglin Avatar asked Mar 13 '14 03:03

leiyonglin


1 Answers

It looks like there are some problems between the PHPUnit and Yii autoloaders. PHPUnit is switching to using a single phar archive, and as such the files that Yii attempts to include no longer exist.

The recommended way to install PHPUnit and dependencies now is to use Composer. I spent a couple of days battling using PEAR with all of its quirks, but this tutorial for composer and Yii had me running unit tests again in minutes:

http://blog.mediasuite.co.nz/tip-how-to-set-up-phpunit-for-yii-using-composer/

Basic steps:

Create a composer.json file in your project root:

{
    "require-dev": {
        "phpunit/phpunit": "3.7.*",
        "phpunit/phpunit-selenium": ">=1.2",
        "phpunit/dbunit": ">=1.2",
        "phpunit/phpunit-story": "*",
        "phpunit/php-invoker": "*"
    },
    "autoload": {
        "psr-0": {"": "src"}
    },
    "config": {
        "bin-dir": "bin/"
    }
}

Install composer into your project using:

curl -sS https://getcomposer.org/installer | php

Ensure composer is executable:

chmod +x composer.phar

Let composer install the dependencies:

./composer.phar install --dev

Check you have a project specific phpunit version installed:

./bin/phpunit --version

Now in protected/tests you can run your unit tests with:

../../bin/phpunit unit

and your selenium tests with

../../bin/phpunit functional

If you're using version control, it's best to commit the composer.json and composer.lock files, but ignore the contents of the /vendor folder

like image 163
Hippyjim Avatar answered Oct 19 '22 12:10

Hippyjim