Skip to content

Commit 0b1331f

Browse files
author
Dani Santamaría
committed
Add test for quiz step duration
1 parent 12ea6eb commit 0b1331f

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

examples/php/php-step_shotgun_surgery-01_base/tests/Application/GetStepDurationTest.php

+37-7
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,54 @@
55
namespace CodelyTv\StepShotgunSurgery\Tests\Application;
66

77
use CodelyTv\StepShotgunSurgery\Application\GetStepDuration;
8+
use CodelyTv\StepShotgunSurgery\Domain\Question;
9+
use CodelyTv\StepShotgunSurgery\Domain\QuizStep;
10+
use CodelyTv\StepShotgunSurgery\Domain\Step;
811
use CodelyTv\StepShotgunSurgery\Domain\StepRepository;
912
use CodelyTv\StepShotgunSurgery\Domain\VideoStep;
1013
use PHPUnit\Framework\TestCase;
1114

1215
final class GetStepDurationTest extends TestCase
1316
{
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+
1426
/** @test */
1527
public function shouldReturnVideoStepDuration()
1628
{
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);
2331

24-
$duration = $getStepDuration->__invoke('videoId');
32+
$duration = ($this->getStepDuration)('videoId');
2533

2634
$this->assertSame(11.0, $duration);
2735
}
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+
}
2858
}

0 commit comments

Comments
 (0)