Bump :)
Mar 11, 2017
3
Level 50
Testing uploaded file
Hey.
I have some test in place to test a product creation. The product must have an image.
I wrote a test that uses the new Storage::fake() functionality:
Storage::fake('products');
$admin = factory(User::class)->states('admin')->create();
$this->actingAs($admin)
->post('products', $this->validProductInput([
'sku' => 'DL-3070',
'photo' => UploadedFile::fake()->image('product.jpg')
]))
->assertRedirect('products')
->assertSessionhas(['toastr.message', 'toastr.level']);
Storage::disk('products')->assertExists('products/DL-3070.jpeg');
$this->assertCount(1, Product::all());
In my controller code, I have code that should satisfy the test but for some reason, it seems like when you call the storeAs() method on an UploadedFile instance, it does not use the fake driver?
$attributes = $request->except('photo');
$attributes['photo'] = $request->photo->storeAs('public/products', "{$request->sku}.{$request->photo->extension()}");
Product::create($attributes);
toast('some message', 'success');
return redirect('products');
What I always get is the failure of the test assertion saying it could not find the file.
However, I can see the file present in the storage/app/public/products folder. It seems like it's using the "production" driver.
Any idea why is that happening?
Please or to participate in this conversation.