use(WithFaker::class); test('passes if directory exists', function (): void { /** @var FilesystemAdapter $fs */ $fs = Storage::fake(fake()->word()); $file = File::fake()->create(fake()->word()); $path = $fs->putFile(fake()->word(), $file); $attribute = fake()->word(); $validator = Validator::make( [$attribute => $path], [$attribute => new StorageFileDirectoryExistsRule($fs)] ); expect($validator->passes())->toBeTrue(); }); test('fails if directory does not exist', function (): void { $fs = Storage::fake(fake()->word()); $attribute = fake()->word(); $validator = Validator::make( [$attribute => fake()->filePath()], [$attribute => new StorageFileDirectoryExistsRule($fs)] ); expect($validator->passes())->toBeFalse(); });