我将一个旧的Laravel个人项目从5.2升级到5.4。升级到5.3似乎一切正常,但是现在我已经遇到了5.4遇到问题了。
该项目使用了旧的测试层,因此我已经安装了BrowserKit测试包以保持向后兼容性。我还为浏览器测试创建了以下基本测试用例:
<?php
namespace Tests;
use LaravelBrowserKitTestingTestCase as BaseTestCase;
abstract class BrowserKitTestCase extends BaseTestCase
{
use CreatesApplication;
public $baseUrl = 'http://localhost';
}
使用普通测试用例的模型测试正常工作,但是当我运行使用BrowserKit Test案例的任何测试时,我会看到以下错误消息:
PHP Fatal error: Class 'PHPUnitFrameworkConstraintConstraint' not found in /home/matthew/Projects/myproject/vendor/laravel/browser-kit-testing/src/Constraints/PageConstraint.php on line 10
PHP Fatal error: Uncaught IlluminateContractsContainerBindingResolutionException: Target [IlluminateContractsDebugExceptionHandler] 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): IlluminateContainerContainer->notInstantiable('Illuminate\Cont...')
#1 /home/matthew/Projects/myproject/vendor/laravel/framework/src/Illuminate/Container/Container.php(608): IlluminateContainerContainer->build('Illuminate\Cont...')
#2 /home/matthew/Projects/myproject/vendor/laravel/framework/src/Illuminate/Container/Container.php(575): IlluminateContainerContainer->resolve('Illuminate\Cont...')
#3 /home/matthew/Projects/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(728): IlluminateContainerContainer->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对此并不多,错误消息并没有引人注目。这似乎与命名空间有关,因为PHPUnitFrameworkConstraintConstraint
类似乎不存在,但是我不确定如何解决问题。我根据需要将Phpunit版本升级为5.7,但这并不能解决问题。谁能提出可能是什么问题?
编辑:只是想尝试将版本降级到1.0,这似乎可以解决该问题,因此也许版本2.0旨在与Phpunit 6一起使用?不过,希望这篇文章将来会帮助某人。
我今天也遇到了这一点。
我将laravel/浏览器 - kit测试从〜2.0降低到〜1.0,而是将" phpunit/phpunit"从5.7升级到〜6.0,并解决了问题。
>我同意它与phpunit名称空间有关。从5月25日开始,有一个诺维尔/浏览器 - 浏览器测试的标题为"使用phpunit 6.0命名级"。
将laravel/browser-kit测试降低到1.0似乎已经解决了问题,所以我猜这与phpunit的名称空间有关。
我认为您需要指示测试跑步者使用包含phpunit类别名的bootstrap自动加载文件。
尝试
phpunit -bootstrap bootstrap/autoload_test.php
如果使用phpunit.xml配置文件,请确保您的phpunit标签包含bootstrap =" bootstrap/autoload_test.php"中的其他设置选项,如以下内容:
:<phpunit bootstrap="bootstrap/autoload_test.php">
您可以指示测试跑步者像这样读取您的phpunit.xml:
phpunit -configuration phpunit.xml