From 0b1331f7b82b0c3f10ebf4acaf04edb1dac31739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=20Santamar=C3=ADa?= Date: Thu, 8 Apr 2021 16:38:43 +0200 Subject: [PATCH] Add test for quiz step duration --- .../tests/Application/GetStepDurationTest.php | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/examples/php/php-step_shotgun_surgery-01_base/tests/Application/GetStepDurationTest.php b/examples/php/php-step_shotgun_surgery-01_base/tests/Application/GetStepDurationTest.php index c9d9a247..d7c16c8b 100644 --- a/examples/php/php-step_shotgun_surgery-01_base/tests/Application/GetStepDurationTest.php +++ b/examples/php/php-step_shotgun_surgery-01_base/tests/Application/GetStepDurationTest.php @@ -5,24 +5,54 @@ namespace CodelyTv\StepShotgunSurgery\Tests\Application; use CodelyTv\StepShotgunSurgery\Application\GetStepDuration; +use CodelyTv\StepShotgunSurgery\Domain\Question; +use CodelyTv\StepShotgunSurgery\Domain\QuizStep; +use CodelyTv\StepShotgunSurgery\Domain\Step; use CodelyTv\StepShotgunSurgery\Domain\StepRepository; use CodelyTv\StepShotgunSurgery\Domain\VideoStep; use PHPUnit\Framework\TestCase; final class GetStepDurationTest extends TestCase { + private StepRepository $stepRepository; + private GetStepDuration $getStepDuration; + + protected function setUp() + { + $this->stepRepository = $this->createMock(StepRepository::class); + $this->getStepDuration = new GetStepDuration($this->stepRepository); + } + /** @test */ public function shouldReturnVideoStepDuration() { - $steps = $this->createMock(StepRepository::class); - $steps - ->method('find') - ->willReturn(new VideoStep('videoId', 10)); - - $getStepDuration = new GetStepDuration($steps); + $videoStep = new VideoStep('videoId', 10); + $this->givenStepRepositoryHas($videoStep); - $duration = $getStepDuration->__invoke('videoId'); + $duration = ($this->getStepDuration)('videoId'); $this->assertSame(11.0, $duration); } + + /** @test */ + public function shouldReturnQuizStepDuration() + { + $questions = [ + new Question(), + new Question(), + ]; + $quizStep = new QuizStep('videoId', ...$questions); + $this->givenStepRepositoryHas($quizStep); + + $duration = ($this->getStepDuration)('videoId'); + + $this->assertSame(15.0, $duration); + } + + public function givenStepRepositoryHas(Step $step): void + { + $this->stepRepository + ->method('find') + ->willReturn($step); + } }