diff --git a/tests/Builders/builders.php b/tests/Builders/builders.php index 831f090..49be1d2 100644 --- a/tests/Builders/builders.php +++ b/tests/Builders/builders.php @@ -1,7 +1,6 @@ mockFileService(), + $this->mockAnalyzeService(), + ); + + $handler->handle( + $this->mockInputInterface(), + $this->mockOutputInterface(), + ); + } + + private function mockFileService(): FileService + { + $fileService = Mockery::mock(FileService::class); + + $fileService->expects('all')->andReturn($this->makeFileAggregator()); + + return $fileService; + } + + private function makeFileAggregator(): FileAggregator + { + return fileAggregator()->withFile()->build(); + } + + private function mockAnalyzeService(): AnalyzeService + { + return Mockery::mock(AnalyzeService::class)->shouldIgnoreMissing(); + } + + private function mockInputInterface(): InspectInput + { + $input = Mockery::mock(InspectInput::class); + + $input->expects('path')->andReturn(Path::from('.')); + $input->expects('withMethod')->andReturn(false); + + return $input; + } + + private function mockOutputInterface(): InspectOutput + { + $output = Mockery::mock(InspectOutput::class)->shouldIgnoreMissing(); + + $output->expects('error') + ->never() + ->withAnyArgs() + ->andReturnUsing(function ($th) { + $this->fail('Unexpected call to error with exception: ' . $th->getMessage()); + }); + + $output->expects('present') + ->withArgs(function ($argument) { + return $argument instanceof WordAggregator; + }); + + return $output; + } +} diff --git a/tests/Unit/Application/InspectTestCase.php b/tests/Unit/Application/InspectTestCase.php deleted file mode 100644 index 6640b08..0000000 --- a/tests/Unit/Application/InspectTestCase.php +++ /dev/null @@ -1,88 +0,0 @@ -fileService = Mockery::mock(FileService::class); - $this->analyzeService = Mockery::mock(AnalyzeService::class)->shouldIgnoreMissing(); - $this->input = Mockery::mock(InspectInput::class); - $this->output = Mockery::mock(InspectOutput::class)->shouldIgnoreMissing(); - } - - #[Test] - public function it_can_find_the_number_of_words_in_files(): void - { - $this->shouldNotPresentAnyErrors(); - - $this->setupExpectationsForSuccessScenario(); - - $this->runUseCase(); - } - - private function shouldNotPresentAnyErrors(): void - { - $this->output->expects('error') - ->never() - ->withAnyArgs() - ->andReturnUsing(function ($th) { - $this->fail('Unexpected call to error with exception: ' . $th->getMessage()); - }); - } - - private function setupExpectationsForSuccessScenario(): void - { - $this->fileService->expects('all') - ->andReturn($this->makeFileAggregator()); - - $this->input->expects('path') - ->andReturn(Path::from('.')); - - $this->input->expects('withMethod') - ->andReturn(false); - - $this->output->expects('present') - ->withArgs(function ($argument) { - return $argument instanceof WordAggregator; - }); - } - - private function runUseCase(): void - { - $handler = new InspectHandler( - $this->fileService, - $this->analyzeService, - ); - - $handler->handle($this->input, $this->output); - } - - private function makeFileAggregator(): FileAggregator - { - return $this->fileAggregator()->withFile()->build(); - } - - protected function tearDown(): void - { - Mockery::close(); - } -}