From 204ab8acc145961badf5c84cb800f37b7f8817c2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 Dec 2024 21:19:21 +0100 Subject: [PATCH] Optimize test with mocked app --- .../InteractivePublishCommandHelperTest.php | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Unit/InteractivePublishCommandHelperTest.php b/packages/framework/tests/Unit/InteractivePublishCommandHelperTest.php index ae1049c7a18..755f09ecc1f 100644 --- a/packages/framework/tests/Unit/InteractivePublishCommandHelperTest.php +++ b/packages/framework/tests/Unit/InteractivePublishCommandHelperTest.php @@ -24,15 +24,16 @@ */ class InteractivePublishCommandHelperTest extends UnitTestCase { - use CreatesApplication; - protected static bool $needsKernel = true; protected Filesystem|Mockery\MockInterface $filesystem; + protected $originalApp; + protected function setUp(): void { - $app = $this->createApplication(); + $app = $this->setupMockApplication(); + Container::setInstance($app); $this->filesystem = $this->mockFilesystemStrict(); @@ -50,6 +51,7 @@ protected function tearDown(): void Container::setInstance(); Facade::clearResolvedInstances(); + Facade::setFacadeApplication(null); } public function testGetFileChoices() @@ -114,4 +116,16 @@ public function testFormatOutput() $this->assertSame('Published files [app.blade.php, page.blade.php, post.blade.php]', $output); } + + 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; + } }