In order to move my current Laravel 5.5 project to the latest version, I was trying to setup some tests (I've never done that before).
To do so, I added <env name="DB_CONNECTION" value="mysql_testing" />
in the phpunit.xml
, under the <php>
section, and created a copy of the current mysql
configuration under config/database.php
naming it mysql_testing
, which has 'database' => env('DB_NAME_TESTING', 'forge')
.
In the .env
file I put DB_NAME_TESTING=testDB
. The database exists, is empty and the user has all permissions on it.
I haven't created any Test, yet, just tried the Examples provided by Laravel. If I run the tests as they are, they all pass. If I add the RefreshDatabase
trait on them, instead, I get
ErrorException : Trying to access array offset on value of type int
C:\[path to project]\vendor\symfony\console\Input\ArrayInput.php:135
which corresponds to } elseif ('-' === $key[0]) {
.
After a bit of tracing, I found out that the $key
is 'migrate:fresh'
, which is the Artisan command that RefreshDatabase
is trying to run. In later versions this segment has been replaced with } elseif (str_starts_with($key, '-')) {
, but this is only available since PHP 8, and I'm currently stuck with PHP 7.4.
My question now is: what am I doing wrong in setting up my testing database?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire