-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VSVGVQ-106 Add unit test for QuestionAskedListener.
- Loading branch information
Luc Wollants
committed
Aug 6, 2018
1 parent
1c982b9
commit 2f1f66e
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |