Skip to content

Commit

Permalink
VSVGVQ-106 Add unit test for QuestionAskedListener.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc Wollants committed Aug 6, 2018
1 parent 1c982b9 commit 2f1f66e
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/Quiz/EventListeners/QuestionAskedListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php declare(strict_types=1);

namespace VSV\GVQ_API\Quiz\EventListeners;

use Broadway\Domain\DomainMessage;
use Broadway\Domain\Metadata;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use VSV\GVQ_API\Factory\ModelsFactory;
use VSV\GVQ_API\Quiz\Repositories\CurrentQuestionRepository;

class QuestionAskedListenerTest extends TestCase
{
/**
* @var CurrentQuestionRepository|MockObject
*/
private $currentQuestionRepository;

/**
* @var QuestionAskedListener
*/
private $questionAskedListener;

protected function setUp(): void
{
/** @var CurrentQuestionRepository|MockObject $currentQuestionRepository */
$currentQuestionRepository = $this->createMock(CurrentQuestionRepository::class);
$this->currentQuestionRepository = $currentQuestionRepository;

$this->questionAskedListener = new QuestionAskedListener(
$this->currentQuestionRepository
);
}

/**
* @test
* @throws \Exception
*/
public function it_handles_question_asked(): void
{
$questionAsked = ModelsFactory::createQuestionAsked();

$domainMessage = DomainMessage::recordNow(
$questionAsked->getId(),
0,
new Metadata(),
$questionAsked
);

$this->currentQuestionRepository->expects($this->once())
->method('save')
->with(
$questionAsked->getId(),
$questionAsked->getQuestion()
);

$this->questionAskedListener->handle($domainMessage);
}
}

0 comments on commit 2f1f66e

Please sign in to comment.