laravel-5.7laravel-testinglaravel-unit-test

Laravel 5.7 testing with RefreshDatabase trait throws ErrorException: Trying to access array offset on value of type int


so as I stated in the title, I am working on Laravel 5.7 project and am making first tests in this application (big system). We did not make any tests in here yet, so this problem is the first time here.

For every test, this is how the controller uses the trait

use RefreshDatabase;

protected function setUp()
{
    parent::setUp();
    $this->withoutMiddleware(\App\Http\Middleware\VerifyCsrfToken::class);
    $this->withoutExceptionHandling();
}

As you can see, I am just trying to use the trait to refresh the DB after the tests are done.

The problem arises when I call to execute the tests.

ErrorException: Trying to access array offset on value of type int

C:\laragon\www\demi\systems\damaro\vendor\symfony\console\Input\ArrayInput.php:135 C:\laragon\www\demi\systems\damaro\vendor\symfony\console\Input\Input.php:55 C:\laragon\www\demi\systems\damaro\vendor\symfony\console\Command\Command.php:214 C:\laragon\www\demi\systems\damaro\vendor\laravel\framework\src\Illuminate\Console\Command.php:170 C:\laragon\www\demi\systems\damaro\vendor\symfony\console\Application.php:886 C:\laragon\www\demi\systems\damaro\vendor\symfony\console\Application.php:262 C:\laragon\www\demi\systems\damaro\vendor\symfony\console\Application.php:145 C:\laragon\www\demi\systems\damaro\vendor\laravel\framework\src\Illuminate\Console\Application.php:89 C:\laragon\www\demi\systems\damaro\vendor\laravel\framework\src\Illuminate\Console\Application.php:188 C:\laragon\www\demi\systems\damaro\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:250 C:\laragon\www\demi\systems\damaro\vendor\laravel\framework\src\Illuminate\Foundation\Testing\PendingCommand.php:136 C:\laragon\www\demi\systems\damaro\vendor\laravel\framework\src\Illuminate\Foundation\Testing\PendingCommand.php:218 C:\laragon\www\demi\systems\damaro\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithConsole.php:55 C:\laragon\www\demi\systems\damaro\vendor\laravel\framework\src\Illuminate\Foundation\Testing\RefreshDatabase.php:55 C:\laragon\www\demi\systems\damaro\vendor\laravel\framework\src\Illuminate\Foundation\Testing\RefreshDatabase.php:18 C:\laragon\www\demi\systems\damaro\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestCase.php:104 C:\laragon\www\demi\systems\damaro\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestCase.php:71

This is the whole trace. Some solutions I found are:

Do you have any idea?


Solution

  • So I have not found an answer to this question, but I have found a workaround.

    Instead of using RefreshDatabase trait I decided to use DatabaseTransactions trait.