From d9bb52adee743da4afda6428685b7bc1773e6fb3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 24 Jun 2024 10:04:36 +0200 Subject: [PATCH] Mock the filesystem --- .../framework/tests/Unit/DataCollectionUnitTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/framework/tests/Unit/DataCollectionUnitTest.php b/packages/framework/tests/Unit/DataCollectionUnitTest.php index 016dd5adc24..3a78022ee93 100644 --- a/packages/framework/tests/Unit/DataCollectionUnitTest.php +++ b/packages/framework/tests/Unit/DataCollectionUnitTest.php @@ -123,6 +123,17 @@ public static function mockFiles(array $files): void assert(str_contains($file, '.'), 'File must have an extension.'); } + $filesystem = Mockery::mock(Filesystem::class); + $filesystem->shouldReceive('get') + ->andReturnUsing(function (string $file) use ($files) { + $file = unslash(str_replace(Hyde::path(), '', $file)); + $files = static::arrayGlob($files, $file, 'md'); + + return array_values($files)[0] ?? ''; + }); + + app()->instance(Filesystem::class, $filesystem); + static::$mockFiles = $files; }