Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to find PHPUnit\Framework\Constraint\Constraint in Laravel BrowserKit package after upgrade to 5.4

I'm upgrading an old Laravel personal project from 5.2 to 5.4. The upgrade to 5.3 seems to have gone OK, but now I'm moving to 5.4 I've run into an issue.

The project used the old testing layer so I've installed the BrowserKit testing package to maintain backward compatibility. I also created the following base test case for the Browserkit tests:

<?php

namespace Tests;

use Laravel\BrowserKitTesting\TestCase as BaseTestCase;

abstract class BrowserKitTestCase extends BaseTestCase
{
    use CreatesApplication;

    public $baseUrl = 'http://localhost';
}

The tests for the models, which 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 hasn't been much use with this and the error message is not terribly illuminating. It seems to be something to do with the namespace because the class PHPUnit\Framework\Constraint\Constraint doesn't appear to exist, but I'm not sure how to resolve the issue. I've upgraded the version of PHPUnit to 5.7 as necessary, but that doesn't resolve the issue. Can anyone suggest what the issue might be?

EDIT: Just thought to try downgrading the version to 1.0 and that seems to solve the problem for now, so maybe version 2.0 is intended to work with PHPUnit 6? Still, hopefully this post will help someone out in future.

like image 282
Matthew Daly Avatar asked Jun 25 '17 10:06

Matthew Daly


2 Answers

I ran into this today also.

Instead of downgrading laravel/browser-kit-testing from ~2.0 to ~1.0, I upgraded "phpunit/phpunit" from 5.7 to ~6.0 and that fixed the problem.

I agree that it is related to the PHPUnit namespaces. There is a commit to laravel/browser-kit-testing from May 25 with a title of "Use PHPUnit 6.0 namespaced classes."

like image 129
mmccaff Avatar answered Sep 26 '22 22:09

mmccaff


Downgrading laravel/browser-kit-testing to 1.0 seemed to resolve the issue, so I'm guessing it's something to do with the namespaces for PHPUnit.

like image 33
Matthew Daly Avatar answered Sep 25 '22 22:09

Matthew Daly