mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 02:11:45 +01:00
Participants collection - store instances of ParticipantShort instead of Participant
Related to fetch full data of participant of given survey
This commit is contained in:
@@ -10,6 +10,7 @@ namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
@@ -80,6 +81,52 @@ class ParticipantShortTest extends BaseTestCase
|
||||
static::assertEquals('dolor@sit.com', $this->participant2ndInstance->getEmail());
|
||||
}
|
||||
|
||||
public function testFromParticipantUsingEmptyParticipant()
|
||||
{
|
||||
$participant = new Participant();
|
||||
$participantShort = ParticipantShort::fromParticipant($participant);
|
||||
|
||||
static::assertEquals(0, $participantShort->getId());
|
||||
static::assertEquals('', $participantShort->getFirstName());
|
||||
static::assertEquals('', $participantShort->getLastName());
|
||||
static::assertEquals('', $participantShort->getEmail());
|
||||
|
||||
static::assertEquals($participant->getId(), $participantShort->getId());
|
||||
static::assertEquals($participant->getFirstName(), $participantShort->getFirstName());
|
||||
static::assertEquals($participant->getLastName(), $participantShort->getLastName());
|
||||
static::assertEquals($participant->getEmail(), $participantShort->getEmail());
|
||||
}
|
||||
|
||||
public function testFromParticipant()
|
||||
{
|
||||
$participant1 = new Participant([
|
||||
'tid' => $this->rawData[0]['tid'],
|
||||
'firstname' => $this->rawData[0]['participant_info']['firstname'],
|
||||
'lastname' => $this->rawData[0]['participant_info']['lastname'],
|
||||
'email' => $this->rawData[0]['participant_info']['email'],
|
||||
]);
|
||||
|
||||
$participant2 = new Participant([
|
||||
'tid' => $this->rawData[1]['tid'],
|
||||
'firstname' => $this->rawData[1]['participant_info']['firstname'],
|
||||
'lastname' => $this->rawData[1]['participant_info']['lastname'],
|
||||
'email' => $this->rawData[1]['participant_info']['email'],
|
||||
]);
|
||||
|
||||
$participantShort1 = ParticipantShort::fromParticipant($participant1);
|
||||
$participantShort2 = ParticipantShort::fromParticipant($participant2);
|
||||
|
||||
static::assertEquals($participant1->getId(), $participantShort1->getId());
|
||||
static::assertEquals($participant1->getFirstName(), $participantShort1->getFirstName());
|
||||
static::assertEquals($participant1->getLastName(), $participantShort1->getLastName());
|
||||
static::assertEquals($participant1->getEmail(), $participantShort1->getEmail());
|
||||
|
||||
static::assertEquals($participant2->getId(), $participantShort2->getId());
|
||||
static::assertEquals($participant2->getFirstName(), $participantShort2->getFirstName());
|
||||
static::assertEquals($participant2->getLastName(), $participantShort2->getLastName());
|
||||
static::assertEquals($participant2->getEmail(), $participantShort2->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns raw data of participants
|
||||
*
|
||||
|
||||
@@ -20,6 +20,7 @@ use Meritoo\LimeSurvey\ApiClient\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\SessionManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Service\ParticipantService;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
@@ -185,7 +186,7 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
static::assertNull($this->serviceWithoutParticipants->getParticipant(1, 'john@scott.com'));
|
||||
$participant = $this->serviceWithParticipants->getParticipant(1, 'john@scott.com');
|
||||
|
||||
static::assertInstanceOf(Participant::class, $participant);
|
||||
static::assertInstanceOf(ParticipantShort::class, $participant);
|
||||
static::assertEquals('John', $participant->getFirstName());
|
||||
static::assertEquals('Scott', $participant->getLastName());
|
||||
static::assertEquals('john@scott.com', $participant->getEmail());
|
||||
@@ -314,20 +315,25 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
|
||||
$allParticipants = new Participants([
|
||||
1 => new Collection([
|
||||
new Participant([
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
'completed' => 'Y',
|
||||
new ParticipantShort([
|
||||
'tid' => 1,
|
||||
'participant_info' => [
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
],
|
||||
]),
|
||||
new Participant([
|
||||
'firstname' => 'Mary',
|
||||
'lastname' => 'Jane',
|
||||
'email' => 'mary@jane.com',
|
||||
new ParticipantShort([
|
||||
'tid' => 2,
|
||||
'participant_info' => [
|
||||
'firstname' => 'Mary',
|
||||
'lastname' => 'Jane',
|
||||
'email' => 'mary@jane.com',
|
||||
],
|
||||
]),
|
||||
]),
|
||||
2 => new Collection([
|
||||
new Participant(),
|
||||
new ParticipantShort(),
|
||||
]),
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user