Skip to content

Commit

Permalink
Add test for quiz step duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Dani Santamaría committed Apr 8, 2021
1 parent 12ea6eb commit 0b1331f
Showing 1 changed file with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 0b1331f

Please sign in to comment.