diff --git a/packages/framework/tests/Unit/InteractsWithDirectoriesConcernTest.php b/packages/framework/tests/Unit/InteractsWithDirectoriesConcernTest.php index d788f101506..dc9b92b5514 100644 --- a/packages/framework/tests/Unit/InteractsWithDirectoriesConcernTest.php +++ b/packages/framework/tests/Unit/InteractsWithDirectoriesConcernTest.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Testing\Unit; +use Hyde\Testing\UnitTestCase; use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Hyde; use Hyde\Testing\TestCase; @@ -12,72 +13,82 @@ /** * @covers \Hyde\Framework\Concerns\InteractsWithDirectories */ -class InteractsWithDirectoriesConcernTest extends TestCase +class InteractsWithDirectoriesConcernTest extends UnitTestCase { use InteractsWithDirectories; - protected function setUp(): void - { - parent::setUp(); + protected static bool $needsKernel = true; - File::deleteDirectory(Hyde::path('foo')); - } + /** @var \Illuminate\Filesystem\Filesystem&\Mockery\MockInterface */ + protected $filesystem; - protected function tearDown(): void + protected function setUp(): void { - File::deleteDirectory(Hyde::path('foo')); - - parent::tearDown(); + $this->filesystem = $this->mockFilesystemStrict(); } - public function testMethodsCanBeCalledStatically() + protected function tearDown(): void { - static::needsDirectory('foo'); - $this->assertDirectoryExists(Hyde::path('foo')); - - static::needsDirectories(['foo']); - $this->assertDirectoryExists(Hyde::path('foo')); + $this->verifyMockeryExpectations(); } public function testNeedsDirectoryCreatesTheDirectory() { + $this->filesystem->expects('exists')->with(Hyde::path('foo'))->andReturnFalse(); + $this->filesystem->expects('makeDirectory')->with(Hyde::path('foo'), 0755, true); $this->needsDirectory('foo'); $this->assertDirectoryExists(Hyde::path('foo')); } public function testNeedsDirectoryCreatesTheDirectoryRecursively() { + $this->filesystem->expects('exists')->with(Hyde::path('foo/bar/baz'))->andReturnFalse(); + $this->filesystem->expects('makeDirectory')->with(Hyde::path('foo/bar/baz'), 0755, true); + $this->needsDirectory('foo/bar/baz'); - $this->assertDirectoryExists(Hyde::path('foo/bar/baz')); } public function testNeedsDirectoryHandlesExistingDirectory() { + $this->filesystem->expects('exists')->with(Hyde::path('foo'))->andReturnTrue()->twice(); + $this->filesystem->expects('makeDirectory')->never(); + $this->needsDirectory('foo'); $this->needsDirectory('foo'); - - $this->assertDirectoryExists(Hyde::path('foo')); } public function testNeedsDirectoriesCreatesSingleDirectory() { + $this->filesystem->expects('exists')->with(Hyde::path('foo'))->andReturnFalse(); + $this->filesystem->expects('makeDirectory')->with(Hyde::path('foo'), 0755, true); + $this->needsDirectories(['foo']); - $this->assertDirectoryExists(Hyde::path('foo')); } public function testNeedsDirectoriesCreatesMultipleDirectories() { - $this->needsDirectories(['foo', 'bar']); + $this->filesystem->expects('exists')->with(Hyde::path('foo'))->andReturnFalse(); + $this->filesystem->expects('exists')->with(Hyde::path('bar'))->andReturnFalse(); + $this->filesystem->expects('makeDirectory')->with(Hyde::path('foo'), 0755, true); + $this->filesystem->expects('makeDirectory')->with(Hyde::path('bar'), 0755, true); - $this->assertDirectoryExists(Hyde::path('foo')); - $this->assertDirectoryExists(Hyde::path('bar')); - - File::deleteDirectory(Hyde::path('bar')); + $this->needsDirectories(['foo', 'bar']); } public function testNeedsParentDirectoryCreatesDirectoryForTheParentFile() { + $this->filesystem->expects('exists')->with(Hyde::path('foo/bar'))->andReturnFalse(); + $this->filesystem->expects('makeDirectory')->with(Hyde::path('foo/bar'), 0755, true); + $this->needsParentDirectory(Hyde::path('foo/bar/baz.txt')); - $this->assertDirectoryExists(Hyde::path('foo/bar')); + } + + public function testMethodsCanBeCalledStatically() + { + $this->filesystem->expects('exists')->with(Hyde::path('foo'))->andReturnFalse()->twice(); + $this->filesystem->expects('makeDirectory')->with(Hyde::path('foo'), 0755, true)->twice(); + + static::needsDirectory('foo'); + static::needsDirectories(['foo']); } }