Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Fatal incompatibility between Hamcrest and PEST #1352

Open
vbulash opened this issue Feb 9, 2025 · 3 comments
Open

[Bug]: Fatal incompatibility between Hamcrest and PEST #1352

vbulash opened this issue Feb 9, 2025 · 3 comments
Labels

Comments

@vbulash
Copy link

vbulash commented Feb 9, 2025

What Happened

Run Pest results:

vbulash@iMac-Valerij 12:00:13 ~/PhpstormProjects/example-app # ./vendor/bin/pest .
PHP Fatal error:  Declaration of Hamcrest\Core\CombinableMatcherTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in /Users/vbulash/PhpstormProjects/example-app/vendor/hamcrest/hamcrest-php/tests/Hamcrest/Core/CombinableMatcherTest.php on line 10

   ERROR  Fatal error: Declaration of Hamcrest\Core\CombinableMatcherTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in /Users/vbulash/PhpstormProjects/example-app/vendor/hamcrest/hamcrest-php/tests/Hamcrest/Core/CombinableMatcherTest.php on line 10.

How to Reproduce

Newly installed Laravel 11 example-app by:

composer create-project laravel/laravel example-app
npm install && npm run build

then install Pest:

composer remove phpunit/phpunit
composer require pestphp/pest --dev --with-all-dependencies

Run Pest (still without any tests):

./vendor/bin/pest .

Sample Repository

No response

Pest Version

3.7

PHP Version

8.4.3

Operation System

macOS

Notes

No response

@vbulash vbulash added the bug label Feb 9, 2025
@owenvoke
Copy link
Member

owenvoke commented Feb 9, 2025

Using . as a selector will search for all tests in the current directory, including vendor/. This includes tests from Hamcrest because they haven't excluded them from releases (they did in 2022, but haven't done a subsequent release).

Try just running vendor/bin/pest to use the locations from the phpunit.xml configuration.

@vbulash
Copy link
Author

vbulash commented Feb 9, 2025

Unfortunately, PHPStorm automation substitute folder as '.' and there is no way to change it to 'tests'.
Yes, it's not problem of Pest.

But when I change Pest command line with existing Laravel app from auto-generated /usr/bin/php /var/www/html/vendor/bin/pest --teamcity --configuration /var/www/html/phpunit.xml . to /usr/bin/php /var/www/html/vendor/bin/pest --teamcity --configuration /var/www/html/phpunit.xml tests, then Pest didn't see DB connection:

root@8089a3bccd0f:/var/www/html# /usr/bin/php /var/www/html/vendor/bin/pest --configuration /var/www/html/phpunit.xml tests

   FAIL  Tests\Feature\V2TemplateUnionTest
   FAILED  Tests\Feature\MQTTBatchTest >                                                                                                                                                         Error   
  Call to a member function connection() on null

  at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1851
    1847▕      * @return \Illuminate\Database\Connection
    1848▕      */
    1849▕     public static function resolveConnection($connection = null)
    1850▕     {
  ➜ 1851▕         return static::$resolver->connection($connection);
    1852▕     }
    1853▕ 
    1854▕     /**
    1855▕      * Get the connection resolver instance.

      +8 vendor frames 
  9   tests/Feature/MQTTBatchTest.php:50

while php artisan test use this connection without any problem
phpunit.xml.zip

@vbulash
Copy link
Author

vbulash commented Feb 9, 2025

So, forget about it
I found the way how to fix all problems with Pest start inside PhpStorm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants