From 8ab499efb612fbeb59af32b2e297919583067460 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 Dec 2024 19:17:50 +0100 Subject: [PATCH] Cleanup code and use real app --- .../InteractivePublishCommandHelper.php | 2 +- .../InteractivePublishCommandHelperTest.php | 38 +++++++------------ 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/packages/framework/src/Console/Helpers/InteractivePublishCommandHelper.php b/packages/framework/src/Console/Helpers/InteractivePublishCommandHelper.php index 17af8424783..09bb7fa7247 100644 --- a/packages/framework/src/Console/Helpers/InteractivePublishCommandHelper.php +++ b/packages/framework/src/Console/Helpers/InteractivePublishCommandHelper.php @@ -71,7 +71,7 @@ protected function findAllFilesForTag(): array } /** - * @param \Symfony\Component\Finder\SplFileInfo[] $search + * @param \Symfony\Component\Finder\SplFileInfo[] $search * @return array */ protected function mapPublishableFiles(array $search): array diff --git a/packages/framework/tests/Unit/InteractivePublishCommandHelperTest.php b/packages/framework/tests/Unit/InteractivePublishCommandHelperTest.php index 7e47c969909..d603734a5bd 100644 --- a/packages/framework/tests/Unit/InteractivePublishCommandHelperTest.php +++ b/packages/framework/tests/Unit/InteractivePublishCommandHelperTest.php @@ -4,15 +4,17 @@ namespace Hyde\Framework\Testing\Unit; -use Hyde\Console\Helpers\InteractivePublishCommandHelper; -use Hyde\Foundation\Providers\ViewServiceProvider; +use Hyde\Testing\CreatesApplication; +use Illuminate\Filesystem\Filesystem; +use Mockery; use Hyde\Hyde; use Hyde\Testing\UnitTestCase; +use Hyde\Foundation\Providers\ViewServiceProvider; +use Hyde\Console\Helpers\InteractivePublishCommandHelper; use Illuminate\Container\Container; use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Facade; use Illuminate\Support\Facades\File; -use Mockery; use Symfony\Component\Finder\SplFileInfo; /** @@ -22,22 +24,22 @@ */ class InteractivePublishCommandHelperTest extends UnitTestCase { - protected static bool $needsKernel = true; + use CreatesApplication; - /** @var \Illuminate\Filesystem\Filesystem&\Mockery\MockInterface */ - protected $filesystem; + protected static bool $needsKernel = true; - protected $originalApp; + protected Filesystem|Mockery\MockInterface $filesystem; protected function setUp(): void { + $app = $this->createApplication(); + Container::setInstance($app); + $this->filesystem = $this->mockFilesystemStrict(); File::swap($this->filesystem); Blade::partialMock()->shouldReceive('component'); - $app = $this->setupMockApplication(); - (new ViewServiceProvider($app))->boot(); } @@ -45,7 +47,7 @@ protected function tearDown(): void { $this->verifyMockeryExpectations(); - Container::setInstance($this->originalApp); + Container::setInstance(); Facade::clearResolvedInstances(); } @@ -80,8 +82,8 @@ public function testHandle() $this->filesystem->shouldReceive('copy')->twice(); $helper->handle([ - "resources/views/vendor/hyde/layouts/app.blade.php", - "resources/views/vendor/hyde/layouts/page.blade.php", + 'resources/views/vendor/hyde/layouts/app.blade.php', + 'resources/views/vendor/hyde/layouts/page.blade.php', ]); $this->filesystem->shouldHaveReceived('ensureDirectoryExists') @@ -98,16 +100,4 @@ public function testHandle() Hyde::path('resources/views/vendor/hyde/layouts/page.blade.php') )->once(); } - - protected function setupMockApplication(): Container - { - $this->originalApp = Container::getInstance(); - - $app = Mockery::mock(app())->makePartial(); - $app->shouldReceive('resourcePath')->andReturnUsing(fn (string $path) => "resources/$path"); - - Container::setInstance($app); - - return $app; - } }