|
5 | 5 | namespace CodelyTv\StepShotgunSurgery\Tests\Application;
|
6 | 6 |
|
7 | 7 | use CodelyTv\StepShotgunSurgery\Application\GetStepDuration;
|
| 8 | +use CodelyTv\StepShotgunSurgery\Domain\Question; |
| 9 | +use CodelyTv\StepShotgunSurgery\Domain\QuizStep; |
| 10 | +use CodelyTv\StepShotgunSurgery\Domain\Step; |
8 | 11 | use CodelyTv\StepShotgunSurgery\Domain\StepRepository;
|
9 | 12 | use CodelyTv\StepShotgunSurgery\Domain\VideoStep;
|
10 | 13 | use PHPUnit\Framework\TestCase;
|
11 | 14 |
|
12 | 15 | final class GetStepDurationTest extends TestCase
|
13 | 16 | {
|
| 17 | + private StepRepository $stepRepository; |
| 18 | + private GetStepDuration $getStepDuration; |
| 19 | + |
| 20 | + protected function setUp() |
| 21 | + { |
| 22 | + $this->stepRepository = $this->createMock(StepRepository::class); |
| 23 | + $this->getStepDuration = new GetStepDuration($this->stepRepository); |
| 24 | + } |
| 25 | + |
14 | 26 | /** @test */
|
15 | 27 | public function shouldReturnVideoStepDuration()
|
16 | 28 | {
|
17 |
| - $steps = $this->createMock(StepRepository::class); |
18 |
| - $steps |
19 |
| - ->method('find') |
20 |
| - ->willReturn(new VideoStep('videoId', 10)); |
21 |
| - |
22 |
| - $getStepDuration = new GetStepDuration($steps); |
| 29 | + $videoStep = new VideoStep('videoId', 10); |
| 30 | + $this->givenStepRepositoryHas($videoStep); |
23 | 31 |
|
24 |
| - $duration = $getStepDuration->__invoke('videoId'); |
| 32 | + $duration = ($this->getStepDuration)('videoId'); |
25 | 33 |
|
26 | 34 | $this->assertSame(11.0, $duration);
|
27 | 35 | }
|
| 36 | + |
| 37 | + /** @test */ |
| 38 | + public function shouldReturnQuizStepDuration() |
| 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 | + $this->assertSame(15.0, $duration); |
| 50 | + } |
| 51 | + |
| 52 | + public function givenStepRepositoryHas(Step $step): void |
| 53 | + { |
| 54 | + $this->stepRepository |
| 55 | + ->method('find') |
| 56 | + ->willReturn($step); |
| 57 | + } |
28 | 58 | }
|
0 commit comments