From e423d8a04e9b783cef5ec8e813f14c52ad4fe4d4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 9 Sep 2024 10:58:26 +0200 Subject: [PATCH] Extract helper method create mocks --- .../framework/tests/Unit/BuildTaskServiceUnitTest.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index 0ea55cd8935..e4515a92d80 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -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() @@ -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); @@ -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); @@ -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