3

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
1
  • have you tried to remove the vendor folder and start over again? Not as root (!): $ rm -rf ./vendor && composer install Commented Jun 20, 2017 at 16:10

3 Answers 3

4

Your version of phpunit is probably too old for your version of Zend. The class PHPUnit\Framework\ExpectationFailedException have been renamed in PhpUnit 6.X from PHPUnit_Framework_ExpectationFailedException to ExpectationFailedException

Please check your PhpUnit version: phpunit --version, it should be 6.X. Update it to the last version to avoid this error.

Sign up to request clarification or add additional context in comments.

1 Comment

the problem is that phpunit 6.X is not working with php 5.X
3

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

Comments

3

This is a configuration flaw in zend-test. It consumes classes from Phpunit 6 but per it's Composer requirements, Phpunit before that version are OK to require:

    "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0",

Most likely as your system because of the PHP version does not satisfy the requirements of Phpunit 6, the next lower version was installed.

As the code in the base test case (https://github.com/zendframework/zend-test/blob/master/src/PHPUnit/Controller/AbstractControllerTestCase.php#L444) makes use of Phpunit 6 classes, I strongly assume that when the configuration flaw is made aware to the Zend-Test project, you won't be even able to install on your system any longer.

Therefore upgrade to a recent PHP version and then run

composer update

If you're stuk with the PHP version, downgrade zend-test to a version that supports an older Phpunit version. I don't know that project well, so it's just a suggestion, I don't know if such a version exists or can't even recommend one.

I filed a report, perhaps using that one class was an oversight or there is a less hard way to resolve the dependency: https://github.com/zendframework/zend-test/issues/50

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.