Part of my code creates an on-demand storage disk using config values that are stored in the database. I am writing a feature test for this code, how do I get my test to use fake storage when this disk is created instead of trying to actually create the real connection? With any named storage disks I just do Storage::fake('mydisk') at the start of my test but since it is on-demand it doesn't have a name.
Managed to crack it in the end:
$localDisk = Storage::fake('local');
Storage::shouldReceive('build')->with([
'driver' => 'sftp',
'host' => $endpoint->host,
'username' => $endpoint->username,
'password' => $endpoint->password,
'port' => $endpoint->port ?? 22,
])->andReturn($localDisk);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With