From b79704fc42b120b49965248e70ac04312c3cf8c1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 28 Nov 2023 18:15:25 +0100 Subject: [PATCH] Unit test argument logic --- .../Unit/ServeCommandOptionsUnitTest.php | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php b/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php index ae80ed40361..9b73aa63aa0 100644 --- a/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php +++ b/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php @@ -6,6 +6,7 @@ use Mockery; use Hyde\Testing\UnitTestCase; +use Hyde\Foundation\HydeKernel; use Illuminate\Console\OutputStyle; use Hyde\Console\Commands\ServeCommand; use Illuminate\Support\Facades\Process; @@ -202,6 +203,37 @@ public function test_checkArgvForOption() } public function testWithOpenArgument() + { + HydeKernel::setInstance(new HydeKernel()); + + $command = new class(['open' => true]) extends ServeCommandMock + { + public bool $openInBrowserCalled = false; + + // Void unrelated methods + protected function configureOutput(): void + { + } + + protected function printStartMessage(): void + { + } + + protected function runServerProcess(string $command): void + { + } + + protected function openInBrowser(): void + { + $this->openInBrowserCalled = true; + } + }; + + $command->safeHandle(); + $this->assertTrue($command->openInBrowserCalled); + } + + public function test_openInBrowser() { $output = $this->createMock(OutputStyle::class); $output->expects($this->never())->method('writeln'); @@ -222,7 +254,7 @@ public function testWithOpenArgument() $command->openInBrowser(); } - public function testWithOpenArgumentThatFails() + public function test_openInBrowserThatFails() { $output = Mockery::mock(OutputStyle::class); $output->shouldReceive('getFormatter')->andReturn($this->createMock(OutputFormatterInterface::class));