lundi 20 août 2018

Files being created when faking storage in Laravel tests

I am using Storage::fake to test uploads in a Laravel 5.6 app.

My problem is that the files are not being stored in a temporary folder and deleted after the test, as the docs say should happen.

This could be because I have set up the filesystems config to use the public/storage folder (instead of the app/storage/public folder and a symlink).

config/filesystems.php:

'public' => [
    'driver' => 'local',
    'root' => public_path('storage'),
    'url' => env('APP_URL').'/public/storage',
    'visibility' => 'public',
],

test.php:

/** @test */
public function foobar_test()
{
    Storage::fake('public');

    $file = UploadedFile::fake()->image('image.jpg', 3000, 2000);

    $this->baseObject['image'] = $file;

    $response = $this->postJson($this->endpoint, $this->baseObject)->assertStatus(201);

    Storage::disk('public')->assertExists('images/image.jpg');
}

At the end of this test files have been created in my public/storage/images folder. They should not be there. My assertExists assertion also fails.

Aucun commentaire:

Enregistrer un commentaire