From db6a6f22e24ddcac35acbc99049753f1983f1be5 Mon Sep 17 00:00:00 2001 From: Meritoo Date: Sun, 1 Oct 2017 20:51:03 +0200 Subject: [PATCH] ParticipantService - getParticipantDetails() method - returns full data of participant with given e-mail of given survey --- src/Service/ParticipantService.php | 27 +++++++++++++++++- tests/Service/ParticipantServiceTest.php | 35 ++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/Service/ParticipantService.php b/src/Service/ParticipantService.php index 79fa24f..3d83a01 100644 --- a/src/Service/ParticipantService.php +++ b/src/Service/ParticipantService.php @@ -179,7 +179,7 @@ class ParticipantService } /** - * Returns participant with given e-mail of given survey + * Returns short data of one participant with given e-mail of given survey * * @param int $surveyId ID of survey * @param string $email E-mail address of the participant @@ -197,6 +197,31 @@ class ParticipantService ->getParticipantOfSurvey($surveyId, $email); } + /** + * Returns full data of participant with given e-mail of given survey + * + * @param int $surveyId ID of survey + * @param string $email E-mail address of the participant + * @return Participant|null + */ + public function getParticipantDetails($surveyId, $email) + { + $arguments = [ + $surveyId, + [ + 'email' => $email, + ], + ]; + + $participant = $this + ->client + ->run(MethodType::GET_PARTICIPANT_PROPERTIES, $arguments) + ->getData(); + + /* @var Participant $participant */ + return $participant; + } + /** * Returns information if participant with given e-mail has filled given survey * diff --git a/tests/Service/ParticipantServiceTest.php b/tests/Service/ParticipantServiceTest.php index f95a38f..3e217b2 100644 --- a/tests/Service/ParticipantServiceTest.php +++ b/tests/Service/ParticipantServiceTest.php @@ -192,6 +192,41 @@ class ParticipantServiceTest extends BaseTestCase static::assertEquals('john@scott.com', $participant->getEmail()); } + public function testGetParticipantDetails() + { + $sessionManager = $this->getSessionManager(); + + $rpcClientManager = $this->getJsonRpcClientManager(1); + $this->createServiceWithoutParticipants($rpcClientManager, $sessionManager); + + $runMethodCallResults = [ + 'tid' => 1, + 'firstname' => 'John', + 'lastname' => 'Scott', + 'email' => 'john@scott.com', + 'token' => uniqid(), + 'sent' => 'N', + 'completed' => 'N', + ]; + + $rpcClientManager = $this->getJsonRpcClientManager(1, $runMethodCallResults); + $this->createServiceWithParticipants($rpcClientManager, $sessionManager); + + static::assertNull($this->serviceWithoutParticipants->getParticipantDetails(1, 'john@scott.com')); + $participant = $this->serviceWithParticipants->getParticipantDetails(1, 'john@scott.com'); + + static::assertInstanceOf(Participant::class, $participant); + static::assertEquals($runMethodCallResults['tid'], $participant->getId()); + static::assertEquals($runMethodCallResults['firstname'], $participant->getFirstName()); + static::assertEquals($runMethodCallResults['lastname'], $participant->getLastName()); + static::assertEquals($runMethodCallResults['email'], $participant->getEmail()); + static::assertEquals($runMethodCallResults['token'], $participant->getToken()); + static::assertFalse($participant->isSent()); + static::assertFalse($participant->isCompleted()); + static::assertNull($participant->isBlacklisted()); + static::assertNull($participant->getValidFrom()); + } + public function testHasParticipantFilledSurveyWithException() { $this->expectException(MissingParticipantOfSurveyException::class);