1

I am testing my laravel application using laravel dusk but the problem is that I am unable to use assertDatabaseHasfunction. When I run php artisan dusk command I got this error:

PHP Fatal error:  Class 'PHPUnit_Framework_Constraint' not found in 
vendor\laravel\framework\src\Illuminate\Foundation\Testing\Constraints\HasIn
Database.php on line 8

enter image description here

Here is my code:

$this->assertDatabaseHas('teams', [
    'name' => $data['team_name'],
]);

1 Answer 1

1

Please check your version of phpunit:

phpunit --version

If you are are running v6 you might have trouble because it expects a namespaced class. In that case you either have to switch to an older version of phpunit, e.g. locally installed for your project and then run like this:

php vendor/bin/phpunit --version

or you might have to update your Laravel-project, which is probably more work as you might have to change parts of your code.

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

3 Comments

Thanks, Problem solved after switching to PHPUnit 5.7 version. :)
@ZeeshanAhmed you should stay on 6.1 and use PHPUnit\Framework\Constraint instead. Then just extend Constraint
@MarcoAurélioDeleu well it's a class from Laravel framework. Changing code there is not a good idea, as you usually don't want to maintain your own fork. The better option would be an upgrade as I mentioned above, but unfortunately Laravel has breaking changes in minor versions, making it non-trivial for some existing projects to switch to a newer version.

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.