PHPUnit抱怨缺少PHPUnit_Extensions_Story_TestCase

时间:2014-03-19 10:09:40

标签: php phpunit

最近我一直遇到PHPUnit的问题,尽管已经安装了扩展程序(之前使用pear install phpunit / PHPUnit_Story安装),但它一直抱怨缺少PHPUnit_Extensions_Story_TestCase。 这只发生在我运行失败的单元测试时。所以,而不是一个正常的"适当的故障堆栈跟踪,我有这样的事情:

ECould not find PHPUnit_Extensions_Story_TestCase

#0  PHPUnit_Util_Fileloader::{closure}(PHPUnit_Extensions_Story_TestCase) called at [/Users/pedro/Code/Repositories/api-v2/src/XXX/system/Autoloader.php:40]
#1  Autoloader->autoload(PHPUnit_Extensions_Story_TestCase)
#2  spl_autoload_call(PHPUnit_Extensions_Story_TestCase)
#3  class_exists(PHPUnit_Extensions_Story_TestCase) called at [phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:110]
#4  PHPUnit_Util_Blacklist->initialize() called at [phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:74]
#5  PHPUnit_Util_Blacklist->isBlacklisted(phar:///usr/bin/phpunit/php-invoker/Invoker.php) called at [phar:///usr/bin/phpunit/phpunit/Util/Filter.php:105]
#6  PHPUnit_Util_Filter::getFilteredStacktrace(PHP_Invoker_TimeoutException Object ([] => Execution aborted after 5 seconds,[] => ,[] => 0,[] => phar:///usr/bin/phpunit/php-invoker/Invoker.php,[] => 111,[] => Array ([0] => Array ([file] => /Users/pedro/Code/Repositories/api-v2/src/XXX/data/adapters/MySQLiAdapter.php,[line] => 160,[function] => callback,[class] => PHP_Invoker,[type] => ->,[args] => Array ([0] => 14)),[1] => Array ([file] => /Users/pedro/Code/Repositories/api-v2/src/XXX/data/adapters/MySQLiAdapter.php,[line] => 306,[function] => query,[class] => XXX\data\adapters\MySQLiAdapter,[type] => ->,[args] => Array ([0] => SELECT * FROM `users` ORDER BY RAND() LIMIT 82 )),[2] => Array ([file] => /Users/pedro/Code/Repositories/api-v2/src/XXX/data/objects/Mapper.php,[line] => 138,[function] => select,[class] => XXX\data\adapters\MySQLiAdapter,[type] => ->,[args] => Array ([0] => `users`,[1] => ,[2] => RAND(),[3] => 82)),[3] => Array ([file] => /Users/pedro/Code/Repositories/api-v2/src/XXX/resources/hybrid/Users.php,[line] => 53,[function] => read,[class] => XXX\data\objects\Mapper,[type] => ->,[args] => Array ([0] => RAND(),[1] => 82)),[4] => Array ([function] => read,[class] => XXX\resources\hybrid\Users,[type] => ->,[args] => Array ([0] => XXX\data\objects\Operation Object

如果最终告诉实际问题,那么如何知道多少几百行呢?

Time: 20.35 seconds, Memory: 18.50Mb

There was 1 failure:

1) Tests\XXX\resources\hybrid\NotificationsTest::testReadNotificationsWithLimit
Failed asserting that '4567135422196220076' matches expected 4567135456555958453.

/Users/pedro/Code/Repositories/api-v2/tests/XXX/resources/hybrid/NotificationsTest.php:168

FAILURES!
Tests: 5, Assertions: 15, Failures: 1.

Generating code coverage report in Clover XML format ...

我正在运行PHPUnit 4.0.10并安装了PHPUnit_Story-1.0.2。我知道这不是一种正常的行为,但不幸的是我不知道如何摆脱这种行为。有什么建议吗?

P.S。 - 我正在检查/ usr / bin / phpunit文件,并且在autoload函数中,$ classes数组缺少一个带有' phpunit_extensions_story_testcase'的条目。 ...但如果我尝试编辑文件,Phar会抱怨签名无效。

3 个答案:

答案 0 :(得分:2)

/Users/pedro/Code/Repositories/api-v2/src/XXX/system/Autoloader.php处的自定义自动加载器正在输出该内容,而不是在false行返回40。如果没有看到自动加载器的源代码,就不可能说出为什么会发生这种情况。

如果无法加载类,PHP自动加载器应该静默return false这是允许链接多个自动加载器所必需的。 PHPUnit使用自己的自动加载器来处理自己的代码,由于您的自定义自动加载器没有遵循规范,因此无法正常运行。

答案 1 :(得分:0)

我有同样的问题,我解决它的唯一方法 - 现在 - 正在降级到PHPUnit 3.7.32。

答案 2 :(得分:0)

与phpunit 4.x有同样的问题。与Yii 1.x自动装载机配合使用。通常,单元测试工作正常,但只要启用代码覆盖就会中断。

免责声明:以下内容非常难看,但对我有用:

只需在项目中添加一个空类,这样自动加载器就不会失败。

<?php

if(!class_exists('PHPUnit_Extensions_Story_TestCase'))
{
    /**
     * PHPUnit_Extensions_Story_TestCase
     * 
     * This skeleton class is added to get code coverage collection using XDebug 
     * and PHPUnit 4.x working again.
     */
    class PHPUnit_Extensions_Story_TestCase
    {

    }
}
相关问题