Skip to content

Commit

Permalink
Extract helper method create mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Sep 9, 2024
1 parent 6f21293 commit e423d8a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/framework/tests/Unit/BuildTaskServiceUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function testCanSetOutputWithNull()

public function testCanSetOutputWithOutputStyle()
{
$this->can(fn () => $this->service->setOutput(Mockery::mock(OutputStyle::class)));
$this->can(fn () => $this->service->setOutput($this->mockOutput()));
}

public function testGenerateBuildManifestExtendsPostBuildTask()
Expand Down Expand Up @@ -255,7 +255,7 @@ public function testRunPostBuildTasksCallsRunMethodsWithNullWhenServiceHasNoOutp

public function testRunPreBuildTasksCallsRunMethodsWithOutputWhenServiceHasOutput()
{
$output = Mockery::mock(OutputStyle::class)->makePartial();
$output = $this->mockOutput();
$task = $this->setupMock(TestPreBuildTask::class, 'run')->with($output)->once()->getMock();

$this->service->setOutput($output);
Expand All @@ -265,7 +265,7 @@ public function testRunPreBuildTasksCallsRunMethodsWithOutputWhenServiceHasOutpu

public function testRunPostBuildTasksCallsRunMethodsWithOutputWhenServiceHasOutput()
{
$output = Mockery::mock(OutputStyle::class)->makePartial();
$output = $this->mockOutput();
$task = $this->setupMock(TestPostBuildTask::class, 'run')->with($output)->once()->getMock();

$this->service->setOutput($output);
Expand Down Expand Up @@ -336,6 +336,11 @@ protected function setupMock(string $class, string $method): Mockery\Expectation
{
return Mockery::mock($class)->makePartial()->shouldReceive($method)->once();
}

protected function mockOutput(): Mockery\LegacyMockInterface|Mockery\MockInterface|OutputStyle
{
return Mockery::mock(OutputStyle::class)->makePartial();
}
}

class InstantiableTestBuildTask extends BuildTask
Expand Down

0 comments on commit e423d8a

Please sign in to comment.