我正在尝试使用PhpUnit测试 Laravel 5.1 控制器,因为我正在创建一个继承自 TestCase 的类,并使用 DatabaseTransactions 和没有中间件特征。
在类中实现 setUpBeforeClass 方法,其中包含:
Artisan::call('migrate:refresh');
当我尝试运行测试时,我收到以下错误:
1) JugadoresControllerTest::test_Index_trae_arreglo_de_jugadores
ErrorException: explode() expects parameter 2 to be string, array given
/home/vagrant/.composer/vendor/illuminate/support/helpers.php:390
/home/vagrant/Code/marcadores/vendor/laravel/framework/src/Illuminate/Support/Arr.php:319
/home/vagrant/Code/marcadores/vendor/laravel/framework/src/Illuminate/Support/Collection.php:428
/home/vagrant/Code/marcadores/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1548
/home/vagrant/Code/marcadores/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php:53
/home/vagrant/Code/marcadores/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:79
/home/vagrant/Code/marcadores/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:74
/home/vagrant/Code/marcadores/vendor/laravel/framework/src/Illuminate/Container/Container.php:503
/home/vagrant/Code/marcadores/vendor/laravel/framework/src/Illuminate/Console/Command.php:150
/home/vagrant/Code/marcadores/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:259
/home/vagrant/Code/marcadores/vendor/laravel/framework/src/Illuminate/Console/Command.php:136
/home/vagrant/Code/marcadores/vendor/laravel/framework/src/Illuminate/Console/Application.php:62
/home/vagrant/Code/marcadores/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:152
/home/vagrant/Code/marcadores/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:210
/home/vagrant/Code/marcadores/tests/unit/JugadoresControllerTest.php:34
/home/vagrant/Code/marcadores/tests/unit/JugadoresControllerTest.php:34
/home/vagrant/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:151
/home/vagrant/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:103
希望有人能帮忙!
答案 0 :(得分:2)
我不知道你是否想过这个问题,但是当我尝试在laravel 5.1下运行phpunit测试时遇到了类似的问题。显然我在我的全局作曲家安装上有一些过时的供应商构建(正如你的错误所尊重的那样:/home/vagrant/.composer/vendor/illuminate/support/helpers.php:390
)
我所做的只是cd到我的作曲家目录:
cd /home/vagrant/.composer
并运行composer update
这更新了我的全球作曲家,一切都按预期工作。