Could not find PHPUnit \ Framework \ Constraint \ Constraint in Laravel BrowserKit after upgrading to 5.4

I am updating my old Laravel personal project from 5.2 to 5.4. Upgrading to 5.3 seems to have gone fine, but now I'm moving on to 5.4. I ran into a problem.

The project used the old test level, so I installed the BrowserKit test package to support backward compatibility. I also created the following basic test case for Browserkit tests:

<?php namespace Tests; use Laravel\BrowserKitTesting\TestCase as BaseTestCase; abstract class BrowserKitTestCase extends BaseTestCase { use CreatesApplication; public $baseUrl = 'http://localhost'; } 

Tests for models that use the normal test case work fine, but when I run any of the tests that use the BrowserKit test case, I see the following error message:

 PHP Fatal error: Class 'PHPUnit\Framework\Constraint\Constraint' not found in /home/matthew/Projects/myproject/vendor/laravel/browser-kit-testing/src/Constraints/PageConstraint.php on line 10 PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/matthew/Projects/myproject/vendor/laravel/framework/src/Illuminate/Container/Container.php:895 Stack trace: #0 /home/matthew/Projects/myproject/vendor/laravel/framework/src/Illuminate/Container/Container.php(735): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...') #1 /home/matthew/Projects/myproject/vendor/laravel/framework/src/Illuminate/Container/Container.php(608): Illuminate\Container\Container->build('Illuminate\\Cont...') #2 /home/matthew/Projects/myproject/vendor/laravel/framework/src/Illuminate/Container/Container.php(575): Illuminate\Container\Container->resolve('Illuminate\\Cont...') #3 /home/matthew/Projects/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(728): Illuminate\Container\Container->make('Illuminate\\Cont...') #4 /home/matthew/Projects/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExce in /home/matthew/Projects/myproject/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 895 

Google has not used this very well, and the error message is not terribly covered. This looks like a namespace because the PHPUnit\Framework\Constraint\Constraint class does not exist, but I'm not sure how to solve the problem. I upgraded version of PHPUnit to 5.7 if necessary, but this does not solve the problem. Can anyone suggest what might be the problem?

EDIT: Just thinking about trying to downgrade to version 1.0 and it seems to solve the problem for now, so maybe version 2.0 is designed to work with PHPUnit 6? However, I hope this post helps someone in the future.

+5
source share
2 answers

Lowering laravel / browser-kit-testing to 1.0 seems to have solved the problem, so I assume this has something to do with namespaces for PHPUnit.

+2
source

I came across this today.

Instead of lowering the laravel / browser-kit testing level from ~ 2.0 to ~ 1.0, I updated phpunit / phpunit from 5.7 to ~ 6.0 and fixed the problem.

I agree that it is associated with PHPUnit namespaces. Since May 25th there is a commit for testing laravel / browser-kit with the heading "Use classes with PHPUnit 6.0 names".

+4
source

Source: https://habr.com/ru/post/1269198/


All Articles