@deshiloh It looks like the issue is that the file name stored in the database and the file name that you are asserting against in your test are not the same. This is likely because the file name generated by the hashName() method is different each time the test is run.
One way to fix this issue is to store the file name generated by the hashName() method in a variable, and then use that variable in both the database assertion and the storage assertion.
Here's an example of how you could do that:
public function testAddCarouselSuccess()
{
\Storage::fake('local');
$file = UploadedFile::fake()->image('test.png');
$name = $file->hashName();
Livewire::test(CarouselDataTable::class)
->set('photo', $file)
->set('position', 1)
->call('saveImage')
->assertHasNoErrors()
;
\Storage::disk('local')->assertExists('photos/'.$name);
$this->assertDatabaseHas('carousels', [
'file_name' => $name
]);
}
Another way is to use storeAs() instead of store(), this way you can specify the name of the file, it's helpful when you want to test certain file name and you want to assert if it's stored correctly or not.
$this->photo->storeAs('photos', $name);
You can also use Storage::assertExists('photos/'.$name) instead of \Storage::disk('local')->assertExists('photos/'.$name);
It should resolve your problem and the test should pass.