laravel / browser-kit-testing

Provides backwards compatibility for BrowserKit testing in the latest Laravel release.
MIT License
508 stars 75 forks source link

exception when executing phpunit #98

Closed xiaohuilam closed 5 years ago

xiaohuilam commented 5 years ago

Description:

PHPUnit 7.1.4 by Sebastian Bergmann and contributors.

PHP Fatal error:  Declaration of Laravel\BrowserKitTesting\Constraints\PageConstraint::fail($crawler, $description, ?SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL) must be compatible with PHPUnit\Framework\Constraint\Constraint::fail($other, $description, ?SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL): void in /Project/nginx/laravel-admin-select2/vendor/laravel/browser-kit-testing/src/Constraints/PageConstraint.php on line 124

In PageConstraint.php line 124:

  Declaration of Laravel\BrowserKitTesting\Constraints\PageConstraint::fail($crawler, $description, ?SebastianBergmann\Comparator\ComparisonFailur  
  e $comparisonFailure = NULL) must be compatible with PHPUnit\Framework\Constraint\Constraint::fail($other, $description, ?SebastianBergmann\Comp  
  arator\ComparisonFailure $comparisonFailure = NULL): void                                                                                         

Fatal error: Declaration of Laravel\BrowserKitTesting\Constraints\PageConstraint::fail($crawler, $description, ?SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL) must be compatible with PHPUnit\Framework\Constraint\Constraint::fail($other, $description, ?SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL): void in /Project/nginx/laravel-admin-select2/vendor/laravel/browser-kit-testing/src/Constraints/PageConstraint.php on line 124

Extra infomation:

I can see vendor/laravel/browser-kit-testing/src/Constraints/PageConstraint.php's fail method declaring

    /**
     * Throw an exception for the given comparison and test description.
     *
     * @param  \Symfony\Component\DomCrawler\Crawler|string  $crawler
     * @param  string  $description
     * @param  \SebastianBergmann\Comparator\ComparisonFailure|null  $comparisonFailure
     * @return void
     *
     * @throws \PHPUnit\Framework\ExpectationFailedException
     */
    protected function fail($crawler, $description, ComparisonFailure $comparisonFailure = null)
    {

and vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php's declaring


    /**
     * Throws an exception for the given compared value and test description
     *
     * @param mixed             $other             Evaluated value or object.
     * @param string            $description       Additional information about the test
     * @param ComparisonFailure $comparisonFailure
     *
     * @throws ExpectationFailedException
     */
    protected function fail($other, $description, ComparisonFailure $comparisonFailure = null)
    {

They have different parameter declares. Please check the compatible with phpunit which version i pasted.

driesvints commented 5 years ago

Hey there,

Unfortunately we don't support this version anymore. Please check out our support policy on which versions we are currently supporting. Can you please try to upgrade to the latest version and see if your problem persists? If so feel free to reply and we'll try to have a look.

Thanks!

xrobau commented 2 years ago

Necro-commenting on this issue, as it's the first result in google when searching for the error string - which is still almost the same, 4 years later!

As discovered in this related issue, the actual problem is caused by you running a locally installed phar phpunit, instead of the one in vendor/bin/phpunit. Fix your PATH, remove the /usr/bin/phpunit, or whatever you want so you use the correct one.

https://github.com/laravel/framework/issues/36393#issuecomment-1015969247

dereckson commented 2 years ago

FYI, i can repro this issue in Composer-installed PHPUnit too, pinning 9.5.19 as version, while it's fine with 9.5.20.