diff --git a/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php b/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php index e80a4e4d426..5ae0645892c 100644 --- a/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php +++ b/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php @@ -245,6 +245,70 @@ protected function openInBrowser(string $path = '/'): void $this->assertTrue($command->openInBrowserCalled); } + public function testWithOpenArgumentWhenString() + { + HydeKernel::setInstance(new HydeKernel()); + + $command = new class(['open' => '']) 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(string $path = '/'): void + { + $this->openInBrowserCalled = true; + } + }; + + $command->safeHandle(); + + $this->assertTrue($command->openInBrowserCalled); + } + + public function testWithOpenArgumentWhenPath() + { + HydeKernel::setInstance(new HydeKernel()); + + $command = new class(['open' => 'dashboard']) extends ServeCommandMock + { + public string $openInBrowserPath = ''; + + // Void unrelated methods + protected function configureOutput(): void + { + } + + protected function printStartMessage(): void + { + } + + protected function runServerProcess(string $command): void + { + } + + protected function openInBrowser(string $path = '/'): void + { + $this->openInBrowserPath = $path; + } + }; + + $command->safeHandle(); + + $this->assertSame('dashboard', $command->openInBrowserPath); + } + public function testOpenInBrowser() { $output = $this->createMock(OutputStyle::class); @@ -262,6 +326,31 @@ public function testOpenInBrowser() $command->openInBrowser(); } + public function testOpenInBrowserWithPath() + { + Process::shouldReceive('command')->once()->with("{$this->getTestRunnerBinary()} http://localhost:8080/dashboard")->andReturnSelf(); + Process::shouldReceive('run')->once()->andReturnSelf(); + Process::shouldReceive('failed')->once()->andReturn(false); + + $this->getMock()->openInBrowser('dashboard'); + } + + public function testOpenInBrowserWithPathNormalizesPaths() + { + Process::shouldReceive('run')->andReturnSelf(); + Process::shouldReceive('failed')->andReturn(false); + + Process::shouldReceive('command')->times(3)->with("{$this->getTestRunnerBinary()} http://localhost:8080")->andReturnSelf(); + Process::shouldReceive('command')->once()->with("{$this->getTestRunnerBinary()} http://localhost:8080/dashboard")->andReturnSelf(); + Process::shouldReceive('command')->once()->with("{$this->getTestRunnerBinary()} http://localhost:8080/foo/bar")->andReturnSelf(); + + $this->getMock()->openInBrowser(''); + $this->getMock()->openInBrowser('/'); + $this->getMock()->openInBrowser('//'); + $this->getMock()->openInBrowser('dashboard/'); + $this->getMock()->openInBrowser('foo/bar/'); + } + public function testOpenInBrowserThatFails() { $output = Mockery::mock(OutputStyle::class);