Skip to content

Commit

Permalink
Refacto InspectHandler test
Browse files Browse the repository at this point in the history
  • Loading branch information
DeGraciaMathieu committed May 13, 2024
1 parent 58a2ff2 commit 4a5b25e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 90 deletions.
3 changes: 1 addition & 2 deletions tests/Builders/builders.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

namespace Tests\Builders;

use Tests\Builders\FileAggregatorBuilder;
function fileAggregator() {
return new FileAggregatorBuilder();
}
80 changes: 80 additions & 0 deletions tests/Unit/Application/InspectHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace Tests\Unit\Application;

use Mockery;
use App\Domain\Ports\FileService;
use App\Domain\ValueObjects\Path;
use App\Domain\Ports\AnalyzeService;
use PHPUnit\Framework\Attributes\Test;
use App\Application\UseCases\InspectInput;
use App\Domain\Aggregators\FileAggregator;
use App\Domain\Aggregators\WordAggregator;
use App\Application\UseCases\InspectOutput;
use App\Application\UseCases\InspectHandler;
use Mockery\Adapter\Phpunit\MockeryTestCase;

class InspectHandlerTest extends MockeryTestCase
{
#[Test]
public function it_can_find_the_number_of_words_in_files(): void
{
$handler = new InspectHandler(
$this->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;
}
}
88 changes: 0 additions & 88 deletions tests/Unit/Application/InspectTestCase.php

This file was deleted.

0 comments on commit 4a5b25e

Please sign in to comment.