From cd6dbf72bca4e03a35d6c02c5fe9ffe7acacab05 Mon Sep 17 00:00:00 2001 From: Meritoo Date: Fri, 29 Sep 2017 15:16:17 +0200 Subject: [PATCH] Tests - add missing tests of Participants::addParticipant() method --- tests/Result/Collection/ParticipantsTest.php | 49 +++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/tests/Result/Collection/ParticipantsTest.php b/tests/Result/Collection/ParticipantsTest.php index bfdb304..56a8fef 100644 --- a/tests/Result/Collection/ParticipantsTest.php +++ b/tests/Result/Collection/ParticipantsTest.php @@ -67,7 +67,7 @@ class ParticipantsTest extends BaseTestCase (new Participants())->has(new Participant()); } - public function testAddParticipantsWithoutParticipants() + public function testAddParticipantsUsingEmptyCollection() { $surveyId = 1; @@ -121,6 +121,53 @@ class ParticipantsTest extends BaseTestCase static::assertCount(2, $this->participantsOfOneSurvey->getBySurvey($surveyId)); } + public function testAddParticipantFirstParticipant() + { + $surveyId = 1; + $email = 'john@scott.com'; + $participant = new Participant(); + + $participant->setValues([ + 'firstname' => 'John', + 'lastname' => 'Scott', + 'email' => $email, + 'completed' => 'Y', + ]); + + $participants = new Participants(); + $result = $participants->addParticipant($participant, $surveyId); + + static::assertEquals($participants, $result); + static::assertEquals($participant, $participants->getParticipantOfSurvey($surveyId, $email)); + + static::assertTrue($participants->hasParticipantsOfSurvey($surveyId)); + static::assertFalse($participants->hasParticipantsOfSurvey(2)); + } + + public function testAddParticipantNotFirstParticipant() + { + $surveyId = 1; + $email = 'john@scott.com'; + $participant = new Participant(); + + $participant->setValues([ + 'firstname' => 'John', + 'lastname' => 'Scott', + 'email' => $email, + 'completed' => 'Y', + ]); + + $result = $this + ->participantsOfOneSurvey + ->addParticipant($participant, $surveyId); + + static::assertEquals($this->participantsOfOneSurvey, $result); + static::assertEquals($participant, $this->participantsOfOneSurvey->getParticipantOfSurvey($surveyId, $email)); + + static::assertTrue($this->participantsOfOneSurvey->hasParticipantsOfSurvey($surveyId)); + static::assertFalse($this->participantsOfOneSurvey->hasParticipantsOfSurvey(2)); + } + /** * {@inheritdoc} */