ParticipantService - getParticipantDetails() method - returns full data of participant with given e-mail of given survey

This commit is contained in:
Meritoo
2017-10-01 20:51:03 +02:00
parent f5334f816f
commit db6a6f22e2
2 changed files with 61 additions and 1 deletions

View File

@@ -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 int $surveyId ID of survey
* @param string $email E-mail address of the participant * @param string $email E-mail address of the participant
@@ -197,6 +197,31 @@ class ParticipantService
->getParticipantOfSurvey($surveyId, $email); ->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 * Returns information if participant with given e-mail has filled given survey
* *

View File

@@ -192,6 +192,41 @@ class ParticipantServiceTest extends BaseTestCase
static::assertEquals('john@scott.com', $participant->getEmail()); 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() public function testHasParticipantFilledSurveyWithException()
{ {
$this->expectException(MissingParticipantOfSurveyException::class); $this->expectException(MissingParticipantOfSurveyException::class);