Search code examples
phpunitzend-framework3zend-test

class PHPUnit\Framework\ExpectationFailedException not found


when I try to run a failed test with this command : ./vendor/bin/phpunit I get this Fatal Error :

PHPUnit 5.7.20 by Sebastian Bergmann and contributors.

PHP Fatal error:  Class 'PHPUnit\Framework\ExpectationFailedException' 
not found in /var/www/zend/vendor/zendframework/zend-
test/src/PHPUnit/Controller/AbstractControllerTestCase.php on line 444

Solution

  • This is "fixed" by a script in Zend\Test called phpunit-class-aliases.php but it's not configured properly IMHO since it's in the autoload-dev section (meaning it doesn't propagate out to other projects.)

    So, in your project composer.json, do something like this:

    "autoload-dev": {
        "files": [
            "vendor/zendframework/zend-test/autoload/phpunit-class-aliases.php"
        ]
    },
    

    Then composer install

    N.B. Zend\Test has a pull request that fixes this very thing, but they're saying it's PHPUnit's fault (Shame on you PHPUnit 4 for... idunno... having the wrong class name according to Zend\Test) So, I've done it instead: composer require illchuk/phpunit-class-aliases