|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types = 1); |
| 4 | + |
| 5 | +namespace CodelyTv\StepShotgunSurgery\Tests\Application; |
| 6 | + |
| 7 | +use CodelyTv\StepShotgunSurgery\Application\GetStepDuration; |
| 8 | +use CodelyTv\StepShotgunSurgery\Domain\Question; |
| 9 | +use CodelyTv\StepShotgunSurgery\Domain\QuizStep; |
| 10 | +use CodelyTv\StepShotgunSurgery\Domain\Step; |
| 11 | +use CodelyTv\StepShotgunSurgery\Domain\StepRepository; |
| 12 | +use CodelyTv\StepShotgunSurgery\Domain\VideoStep; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +final class GetStepDurationTest extends TestCase |
| 16 | +{ |
| 17 | + private StepRepository $stepRepository; |
| 18 | + private GetStepDuration $getStepDuration; |
| 19 | + |
| 20 | + protected function setUp(): void |
| 21 | + { |
| 22 | + $this->stepRepository = $this->createMock(StepRepository::class); |
| 23 | + $this->getStepDuration = new GetStepDuration($this->stepRepository); |
| 24 | + } |
| 25 | + |
| 26 | + /** @test */ |
| 27 | + public function shouldReturnVideoStepDuration(): void |
| 28 | + { |
| 29 | + $videoStep = new VideoStep('videoId', 10); |
| 30 | + $this->givenStepRepositoryHas($videoStep); |
| 31 | + |
| 32 | + $duration = ($this->getStepDuration)('videoId'); |
| 33 | + |
| 34 | + self::assertSame(11.0, $duration); |
| 35 | + } |
| 36 | + |
| 37 | + /** @test */ |
| 38 | + public function shouldReturnQuizStepDuration(): void |
| 39 | + { |
| 40 | + $questions = [ |
| 41 | + new Question(), |
| 42 | + new Question(), |
| 43 | + ]; |
| 44 | + $quizStep = new QuizStep('videoId', ...$questions); |
| 45 | + $this->givenStepRepositoryHas($quizStep); |
| 46 | + |
| 47 | + $duration = ($this->getStepDuration)('videoId'); |
| 48 | + |
| 49 | + self::assertSame(15.0, $duration); |
| 50 | + } |
| 51 | + |
| 52 | + public function givenStepRepositoryHas(Step $step): void |
| 53 | + { |
| 54 | + $this->stepRepository |
| 55 | + ->method('find') |
| 56 | + ->willReturn($step); |
| 57 | + } |
| 58 | +} |
0 commit comments