PHPUnit抱怨缺少PHPUnit_Extensions_Story_TestCase

Lately I've been having problems with PHPUnit, which keeps complaining about missing PHPUnit_Extensions_Story_TestCase despite the fact that the extension is installed (previous installed using pear install phpunit/PHPUnit_Story). This only happens when I'm running a unit test that fails. So, instead of having a "normal" proper failure stack trace, I have something like this:

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] => XXXesources\hybrid\Users,[type] => ->,[args] => Array ([0] => XXX\data\objects\Operation Object

This goes on how don't know how many hundreds of lines more until if finally tells the actual problem:

Time: 20.35 seconds, Memory: 18.50Mb

There was 1 failure:

1) Tests\XXXesources\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 ...

I'm running PHPUnit 4.0.10 and have installed PHPUnit_Story-1.0.2 . I understand that this is not a normal behaviour, but unfortunately I don't know how to get rid of this. Any suggestions?

P.S. - I was checking /usr/bin/phpunit file and in the autoload function, the $classes array is missing an entry with 'phpunit_extensions_story_testcase' ...but if I try to edit the file, Phar complains about invalid signature.

Your custom autoloader at /Users/pedro/Code/Repositories/api-v2/src/XXX/system/Autoloader.php is outputting that stuff instead of returning false on line 40. Without seeing the source code of said autoloader, it's impossible to say why that is happening.

PHP autoloaders are supposed to silently return false if a class cannot be loaded. This is required to allow chaining multiple autoloaders. PHPUnit uses its own autoloader for its own code which cannot run correctly due to your custom autoloader not following the spec.

I have the same problem and the only way I solved it --for now-- was downgrading to PHPUnit 3.7.32.

Had the same problem with phpunit 4.x. in combination with the Yii 1.x autoloader. Unit testing works fine, usually, but breaks as soon as I enable code coverage.

Disclaimer: The following is really ugly but it works for me:

Just add an empty class to your project so the autoloader doesn't fail.

<?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
    {

    }
}