Skip to content

Commit

Permalink
Refactor to extract a testing helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Apr 28, 2024
1 parent 6a80a13 commit 885a24e
Showing 1 changed file with 31 additions and 66 deletions.
97 changes: 31 additions & 66 deletions packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,28 +223,7 @@ 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(string $path = '/'): void
{
$this->openInBrowserCalled = true;
}
};
$command = $this->getOpenServeCommandMock(['open' => true]);

$command->safeHandle();

Expand All @@ -255,28 +234,7 @@ 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 = $this->getOpenServeCommandMock(['open' => '']);

$command->safeHandle();

Expand All @@ -287,28 +245,7 @@ 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 = $this->getOpenServeCommandMock(['open' => 'dashboard']);

$command->safeHandle();

Expand Down Expand Up @@ -395,6 +332,34 @@ protected function getMock(array $options = []): ServeCommandMock
{
return new ServeCommandMock($options);
}

protected function getOpenServeCommandMock(array $arguments): ServeCommandMock
{
return new class($arguments) extends ServeCommandMock
{
public bool $openInBrowserCalled = false;
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->openInBrowserCalled = true;
$this->openInBrowserPath = $path;
}
};
}
}

/**
Expand Down

0 comments on commit 885a24e

Please sign in to comment.