mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 02:11:45 +01:00
Fetch all participants of survey (instead of first 10 only - default behaviour)
This commit is contained in:
73
tests/Exception/MissingSurveySummaryExceptionTest.php
Normal file
73
tests/Exception/MissingSurveySummaryExceptionTest.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Exception;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\MissingSurveySummaryException;
|
||||
|
||||
/**
|
||||
* Test case of an exception used when survey's summary is missing
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class MissingSurveySummaryExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(MissingSurveySummaryException::className, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideSurveyId
|
||||
*/
|
||||
public function testConstructorMessage($surveyId, $expectedMessage)
|
||||
{
|
||||
$exception = new MissingSurveySummaryException($surveyId);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides ID of survey
|
||||
*
|
||||
* @return array
|
||||
* //return Generator
|
||||
*/
|
||||
public function provideSurveyId()
|
||||
{
|
||||
$template = 'Summary of survey with ID %d is missing. Does the survey exist?';
|
||||
|
||||
return [
|
||||
[
|
||||
1,
|
||||
sprintf($template, 1),
|
||||
],
|
||||
[
|
||||
'123',
|
||||
sprintf($template, '123'),
|
||||
],
|
||||
];
|
||||
|
||||
/*
|
||||
yield[
|
||||
1,
|
||||
sprintf($template, 1),
|
||||
];
|
||||
|
||||
yield[
|
||||
'123',
|
||||
sprintf($template, '123'),
|
||||
];
|
||||
*/
|
||||
}
|
||||
}
|
||||
194
tests/Result/Collection/SurveysSummariesTest.php
Normal file
194
tests/Result/Collection/SurveysSummariesTest.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Collection;
|
||||
|
||||
use Meritoo\Common\Exception\Method\DisabledMethodException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\SurveysSummaries;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\SurveySummary;
|
||||
|
||||
/**
|
||||
* Test case of the collection of surveys' summaries (the SurveySummary class instances)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveysSummariesTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Empty collection of surveys' summaries
|
||||
*
|
||||
* @var SurveysSummaries
|
||||
*/
|
||||
private $emptySurveysSummaries;
|
||||
|
||||
/**
|
||||
* Non-empty collection of surveys' summaries
|
||||
*
|
||||
* @var SurveysSummaries
|
||||
*/
|
||||
private $nonEmptySurveysSummaries;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(SurveysSummaries::className, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$this->setExpectedException(DisabledMethodException::className);
|
||||
(new SurveysSummaries())->add('');
|
||||
}
|
||||
|
||||
public function testAddMultiple()
|
||||
{
|
||||
$this->setExpectedException(DisabledMethodException::className);
|
||||
(new SurveysSummaries())->addMultiple([]);
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$this->setExpectedException(DisabledMethodException::className);
|
||||
(new SurveysSummaries())->has(new SurveySummary());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $summaries Surveys' summaries to add
|
||||
* @dataProvider provideSurveysSummaries
|
||||
*/
|
||||
public function testAddSurveysSummaries(array $summaries)
|
||||
{
|
||||
$existingSummariesCount = $this->nonEmptySurveysSummaries->count();
|
||||
|
||||
$this->emptySurveysSummaries->addSurveysSummaries($summaries);
|
||||
$this->nonEmptySurveysSummaries->addSurveysSummaries($summaries);
|
||||
|
||||
static::assertCount(count($summaries), $this->emptySurveysSummaries);
|
||||
static::assertCount(count($summaries) + $existingSummariesCount, $this->nonEmptySurveysSummaries);
|
||||
}
|
||||
|
||||
public function testHasSurveySummaryUsingNonExistingSurvey()
|
||||
{
|
||||
static::assertFalse($this->emptySurveysSummaries->hasSurveySummary(1));
|
||||
static::assertFalse($this->emptySurveysSummaries->hasSurveySummary(2));
|
||||
|
||||
static::assertFalse($this->nonEmptySurveysSummaries->hasSurveySummary(3));
|
||||
static::assertFalse($this->nonEmptySurveysSummaries->hasSurveySummary(4));
|
||||
}
|
||||
|
||||
public function testHasSurveySummaryUsingExistingSurvey()
|
||||
{
|
||||
static::assertTrue($this->nonEmptySurveysSummaries->hasSurveySummary(1));
|
||||
static::assertTrue($this->nonEmptySurveysSummaries->hasSurveySummary(2));
|
||||
}
|
||||
|
||||
public function testGetSurveySummaryUsingNonExistingSurvey()
|
||||
{
|
||||
static::assertNull($this->emptySurveysSummaries->getSurveySummary(1));
|
||||
static::assertNull($this->emptySurveysSummaries->getSurveySummary(2));
|
||||
|
||||
static::assertNull($this->nonEmptySurveysSummaries->getSurveySummary(3));
|
||||
static::assertNull($this->nonEmptySurveysSummaries->getSurveySummary(4));
|
||||
}
|
||||
|
||||
public function testGetSurveySummaryUsingExistingSurvey()
|
||||
{
|
||||
$surveySummary1 = $this->nonEmptySurveysSummaries->getSurveySummary(1);
|
||||
$surveySummary2 = $this->nonEmptySurveysSummaries->getSurveySummary(2);
|
||||
|
||||
static::assertInstanceOf(SurveySummary::className, $surveySummary1);
|
||||
static::assertInstanceOf(SurveySummary::className, $surveySummary2);
|
||||
|
||||
static::assertEquals(0, $surveySummary1->getTokenCount());
|
||||
static::assertEquals(5, $surveySummary2->getTokenCount());
|
||||
|
||||
static::assertEquals(0, $surveySummary1->getFullResponsesCount());
|
||||
static::assertEquals(3, $surveySummary2->getFullResponsesCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides surveys' summaries
|
||||
*
|
||||
* @return array
|
||||
* //return Generator
|
||||
*/
|
||||
public function provideSurveysSummaries()
|
||||
{
|
||||
return [
|
||||
[
|
||||
[],
|
||||
],
|
||||
[
|
||||
[
|
||||
123 => new SurveySummary(),
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
100 => new SurveySummary(),
|
||||
500 => new SurveySummary(),
|
||||
800 => new SurveySummary(),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/*
|
||||
yield[
|
||||
[],
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
123 => new SurveySummary(),
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
100 => new SurveySummary(),
|
||||
500 => new SurveySummary(),
|
||||
800 => new SurveySummary(),
|
||||
],
|
||||
];
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->emptySurveysSummaries = new SurveysSummaries();
|
||||
|
||||
$this->nonEmptySurveysSummaries = new SurveysSummaries([
|
||||
1 => new SurveySummary([
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
]),
|
||||
2 => new SurveySummary([
|
||||
'token_count' => '5',
|
||||
'token_invalid' => '2',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '2',
|
||||
'completed_responses' => '1',
|
||||
'incomplete_responses' => '2',
|
||||
'full_responses' => '3',
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
138
tests/Result/Item/SurveySummaryTest.php
Normal file
138
tests/Result/Item/SurveySummaryTest.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\SurveySummary;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: survey's summary (contains aggregated data)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveySummaryTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(SurveySummary::className, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $rawData Raw data of survey's summary
|
||||
* @dataProvider provideRawData
|
||||
*/
|
||||
public function testCreateOfTheSurveySummary(array $rawData)
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
$processed = $processor->process(MethodType::GET_SUMMARY, $rawData);
|
||||
|
||||
/* @var SurveySummary $processed */
|
||||
static::assertEquals($rawData['token_count'], $processed->getTokenCount());
|
||||
static::assertEquals($rawData['token_invalid'], $processed->getTokenInvalidCount());
|
||||
static::assertEquals($rawData['token_sent'], $processed->getTokenSentCount());
|
||||
static::assertEquals($rawData['token_opted_out'], $processed->getTokenOptedOutCount());
|
||||
static::assertEquals($rawData['token_completed'], $processed->getTokenCompletedCount());
|
||||
static::assertEquals($rawData['completed_responses'], $processed->getCompleteResponsesCount());
|
||||
static::assertEquals($rawData['incomplete_responses'], $processed->getIncompleteResponsesCount());
|
||||
static::assertEquals($rawData['full_responses'], $processed->getFullResponsesCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides raw data of survey's summary
|
||||
*
|
||||
* @return array
|
||||
* //return Generator
|
||||
*/
|
||||
public function provideRawData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'token_count' => '28',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '5',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '6',
|
||||
'completed_responses' => '6',
|
||||
'incomplete_responses' => '10',
|
||||
'full_responses' => '16',
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'token_count' => '28',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '2',
|
||||
'completed_responses' => '2',
|
||||
'incomplete_responses' => '12',
|
||||
'full_responses' => '14',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/*
|
||||
yield[
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
'token_count' => '28',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '5',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '6',
|
||||
'completed_responses' => '6',
|
||||
'incomplete_responses' => '10',
|
||||
'full_responses' => '16',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
'token_count' => '28',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '2',
|
||||
'completed_responses' => '2',
|
||||
'incomplete_responses' => '12',
|
||||
'full_responses' => '14',
|
||||
],
|
||||
];
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,8 @@ use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\MissingParticipantOfSurveyException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\SessionManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\ParticipantsDetails;
|
||||
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;
|
||||
@@ -34,6 +33,13 @@ use PHPUnit_Framework_MockObject_MockObject;
|
||||
*/
|
||||
class ParticipantServiceTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Raw data of participants
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $participantsRawData;
|
||||
|
||||
/**
|
||||
* Service that serves participants.
|
||||
* Without participants.
|
||||
@@ -52,7 +58,7 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(ParticipantService::className, OopVisibilityType::IS_PUBLIC, 3, 1);
|
||||
static::assertConstructorVisibilityAndArguments(ParticipantService::className, OopVisibilityType::IS_PUBLIC, 2, 1);
|
||||
}
|
||||
|
||||
public function testGetClient()
|
||||
@@ -73,45 +79,6 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
static::assertEquals($client, $participantService->getClient());
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipants()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(3);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertCount(0, $this->serviceWithoutParticipants->getSurveyParticipants(1));
|
||||
static::assertCount(0, $this->serviceWithoutParticipants->getSurveyParticipants(2));
|
||||
|
||||
static::assertCount(2, $this->serviceWithParticipants->getSurveyParticipants(1));
|
||||
static::assertCount(1, $this->serviceWithParticipants->getSurveyParticipants(2));
|
||||
static::assertCount(0, $this->serviceWithParticipants->getSurveyParticipants(3));
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipantsWithImportantException()
|
||||
{
|
||||
$this->setExpectedException(CannotProcessDataException::className);
|
||||
$exception = new CannotProcessDataException(ReasonType::NO_TOKEN_TABLE);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
$this->serviceWithParticipants->getSurveyParticipants(3);
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipantsWithNoParticipantsException()
|
||||
{
|
||||
$exception = new CannotProcessDataException(ReasonType::NO_PARTICIPANTS_FOUND);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
static::assertCount(0, $this->serviceWithParticipants->getSurveyParticipants(3));
|
||||
}
|
||||
|
||||
public function testHasParticipantUsingServiceWithoutParticipants()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2);
|
||||
@@ -125,25 +92,6 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
public function testHasParticipant()
|
||||
{
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
'tid' => '123',
|
||||
'participant_id' => null,
|
||||
'mpid' => null,
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
'emailstatus' => 'OK',
|
||||
'token' => uniqid(),
|
||||
'language' => 'pl',
|
||||
'blacklisted' => 'N',
|
||||
'sent' => 'Y',
|
||||
'remindersent' => 'N',
|
||||
'remindercount' => 0,
|
||||
'completed' => 'N',
|
||||
'usesleft' => 10,
|
||||
'validfrom' => null,
|
||||
'validuntil' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
],
|
||||
[
|
||||
null,
|
||||
],
|
||||
@@ -152,7 +100,7 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(3, $runMethodCallResults);
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
@@ -161,72 +109,16 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
static::assertFalse($this->serviceWithParticipants->hasParticipant(3, 'john@scott.com'));
|
||||
}
|
||||
|
||||
public function testAddParticipantForNotExistingSurvey()
|
||||
public function testGetParticipantDetailsWithException()
|
||||
{
|
||||
$this->setExpectedException(CannotProcessDataException::className);
|
||||
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
|
||||
$this->setExpectedException(CannotProcessDataException::className, $exception->getMessage());
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$surveyId = 1;
|
||||
$firstName = 'John';
|
||||
$lastName = 'Scott';
|
||||
$email = 'john@scott.com';
|
||||
|
||||
$this->serviceWithoutParticipants->addParticipant($surveyId, $firstName, $lastName, $email);
|
||||
$this->serviceWithParticipants->addParticipant($surveyId, $firstName, $lastName, $email);
|
||||
}
|
||||
|
||||
public function testAddParticipant()
|
||||
{
|
||||
$surveyId = 1;
|
||||
$firstName = 'John';
|
||||
$lastName = 'Scott';
|
||||
$email = 'john@scott.com';
|
||||
$runMethodCallCount = 1;
|
||||
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
[
|
||||
'firstname' => $firstName,
|
||||
'lastname' => $lastName,
|
||||
'email' => $email,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager($runMethodCallCount, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$result = $this->serviceWithoutParticipants->addParticipant($surveyId, $firstName, $lastName, $email);
|
||||
|
||||
static::assertInstanceOf(Participant::className, $result);
|
||||
static::assertEquals($firstName, $result->getFirstName());
|
||||
static::assertEquals($lastName, $result->getLastName());
|
||||
static::assertEquals($email, $result->getEmail());
|
||||
}
|
||||
|
||||
public function testGetParticipant()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(1);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$participant1 = $this->serviceWithoutParticipants->getParticipant(1, 'john@scott.com');
|
||||
$participant2 = $this->serviceWithParticipants->getParticipant(1, 'john@scott.com');
|
||||
|
||||
static::assertNull($participant1);
|
||||
static::assertInstanceOf(ParticipantShort::className, $participant2);
|
||||
static::assertEquals('John', $participant2->getFirstName());
|
||||
static::assertEquals('Scott', $participant2->getLastName());
|
||||
static::assertEquals('john@scott.com', $participant2->getEmail());
|
||||
$this->serviceWithParticipants->getParticipantDetails(1, 'lorem@ipsum.com');
|
||||
}
|
||||
|
||||
public function testGetParticipantDetails()
|
||||
@@ -236,30 +128,19 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(1);
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$id = 1;
|
||||
$firstName = 'John';
|
||||
$lastName = 'Scott';
|
||||
$email = 'john@scott.com';
|
||||
$token = uniqid();
|
||||
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
'tid' => $id,
|
||||
'firstname' => $firstName,
|
||||
'lastname' => $lastName,
|
||||
'email' => $email,
|
||||
'token' => $token,
|
||||
'sent' => 'N',
|
||||
'completed' => 'N',
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(1, $runMethodCallResults);
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(0);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$participant1 = $this->serviceWithoutParticipants->getParticipantDetails(1, 'john@scott.com');
|
||||
$participant2 = $this->serviceWithParticipants->getParticipantDetails(1, 'john@scott.com');
|
||||
|
||||
$rawData = $this->participantsRawData[0];
|
||||
$id = $rawData['tid'];
|
||||
$firstName = $rawData['firstname'];
|
||||
$lastName = $rawData['lastname'];
|
||||
$email = $rawData['email'];
|
||||
$token = $rawData['token'];
|
||||
|
||||
static::assertNull($participant1);
|
||||
static::assertInstanceOf(Participant::className, $participant2);
|
||||
static::assertEquals($id, $participant2->getId());
|
||||
@@ -267,9 +148,9 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
static::assertEquals($lastName, $participant2->getLastName());
|
||||
static::assertEquals($email, $participant2->getEmail());
|
||||
static::assertEquals($token, $participant2->getToken());
|
||||
static::assertFalse($participant2->isSent());
|
||||
static::assertFalse($participant2->isCompleted());
|
||||
static::assertNull($participant2->isBlacklisted());
|
||||
static::assertTrue($participant2->isSent());
|
||||
static::assertTrue($participant2->isCompleted());
|
||||
static::assertFalse($participant2->isBlacklisted());
|
||||
static::assertNull($participant2->getValidFrom());
|
||||
}
|
||||
|
||||
@@ -286,16 +167,7 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
|
||||
public function testHasParticipantFilledSurveyUsingExistingParticipant()
|
||||
{
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
'completed' => (new DateTime())->format('Y-m-d H:i'),
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(1, $runMethodCallResults);
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(0);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
@@ -313,6 +185,55 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
$this->serviceWithParticipants->hasParticipantFilledSurvey(3, 'mary@jane.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->participantsRawData = [
|
||||
[
|
||||
'tid' => 1,
|
||||
'participant_id' => null,
|
||||
'mpid' => null,
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
'emailstatus' => 'OK',
|
||||
'token' => uniqid(),
|
||||
'language' => 'pl',
|
||||
'blacklisted' => 'N',
|
||||
'sent' => 'Y',
|
||||
'remindersent' => 'N',
|
||||
'remindercount' => 0,
|
||||
'completed' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
'usesleft' => 10,
|
||||
'validfrom' => null,
|
||||
'validuntil' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
],
|
||||
[
|
||||
'tid' => 2,
|
||||
'participant_id' => null,
|
||||
'mpid' => null,
|
||||
'firstname' => 'Mary',
|
||||
'lastname' => 'Jane',
|
||||
'email' => 'mary@jane.com',
|
||||
'emailstatus' => 'OK',
|
||||
'token' => uniqid(),
|
||||
'language' => 'pl',
|
||||
'blacklisted' => 'N',
|
||||
'sent' => 'Y',
|
||||
'remindersent' => 'N',
|
||||
'remindercount' => 0,
|
||||
'completed' => 'N',
|
||||
'usesleft' => 10,
|
||||
'validfrom' => null,
|
||||
'validuntil' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
@@ -408,30 +329,16 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
|
||||
$allParticipants = new Participants([
|
||||
$participantsDetails = new ParticipantsDetails([
|
||||
1 => new Collection([
|
||||
new ParticipantShort([
|
||||
'tid' => 1,
|
||||
'participant_info' => [
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
],
|
||||
]),
|
||||
new ParticipantShort([
|
||||
'tid' => 2,
|
||||
'participant_info' => [
|
||||
'firstname' => 'Mary',
|
||||
'lastname' => 'Jane',
|
||||
'email' => 'mary@jane.com',
|
||||
],
|
||||
]),
|
||||
new Participant($this->participantsRawData[0]),
|
||||
new Participant($this->participantsRawData[1]),
|
||||
]),
|
||||
2 => new Collection([
|
||||
new ParticipantShort(),
|
||||
new Participant(),
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->serviceWithParticipants = new ParticipantService($client, $allParticipants);
|
||||
$this->serviceWithParticipants = new ParticipantService($client, $participantsDetails);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,22 +9,26 @@
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Service;
|
||||
|
||||
use Exception;
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\MissingSurveySummaryException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\SessionManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Surveys;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Service\SurveyService;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
|
||||
/**
|
||||
* Test case of the service that serves surveys
|
||||
* Test case of the service that serves surveys and participants of surveys
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
@@ -32,7 +36,7 @@ use PHPUnit_Framework_MockObject_MockObject;
|
||||
class SurveyServiceTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Service that serves surveys.
|
||||
* Service that serves surveys and participants of surveys.
|
||||
* Without surveys.
|
||||
*
|
||||
* @var SurveyService
|
||||
@@ -40,13 +44,29 @@ class SurveyServiceTest extends BaseTestCase
|
||||
private $serviceWithoutSurveys;
|
||||
|
||||
/**
|
||||
* Service that serves surveys.
|
||||
* Service that serves surveys and participants of surveys.
|
||||
* With surveys.
|
||||
*
|
||||
* @var SurveyService
|
||||
*/
|
||||
private $serviceWithSurveys;
|
||||
|
||||
/**
|
||||
* Service that serves surveys and participants of surveys.
|
||||
* Without participants.
|
||||
*
|
||||
* @var SurveyService
|
||||
*/
|
||||
private $serviceWithoutParticipants;
|
||||
|
||||
/**
|
||||
* Service that serves surveys and participants of surveys.
|
||||
* With participants.
|
||||
*
|
||||
* @var SurveyService
|
||||
*/
|
||||
private $serviceWithParticipants;
|
||||
|
||||
/**
|
||||
* Base url of LimeSurvey's instance.
|
||||
* Used to prepare configuration of connection.
|
||||
@@ -57,7 +77,7 @@ class SurveyServiceTest extends BaseTestCase
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(SurveyService::className, OopVisibilityType::IS_PUBLIC, 2, 1);
|
||||
static::assertConstructorVisibilityAndArguments(SurveyService::className, OopVisibilityType::IS_PUBLIC, 4, 1);
|
||||
}
|
||||
|
||||
public function testGetClient()
|
||||
@@ -78,7 +98,7 @@ class SurveyServiceTest extends BaseTestCase
|
||||
static::assertEquals($client, $surveyService->getClient());
|
||||
}
|
||||
|
||||
public function testGetAllSurveysWithImportantException()
|
||||
public function testGetAllSurveysWithNoTableException()
|
||||
{
|
||||
$this->setExpectedException(CannotProcessDataException::className);
|
||||
$exception = new CannotProcessDataException(ReasonType::NO_TOKEN_TABLE);
|
||||
@@ -185,6 +205,262 @@ class SurveyServiceTest extends BaseTestCase
|
||||
static::assertEquals($expectedUrl, $this->serviceWithSurveys->getStartSurveyUrl($surveyId, $participant));
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipantsWithNotExistingSurveyException()
|
||||
{
|
||||
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
|
||||
$this->setExpectedException(CannotProcessDataException::className, $exception->getMessage());
|
||||
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
[
|
||||
'status' => ReasonType::NOT_EXISTING_SURVEY_ID,
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$this->serviceWithParticipants->getSurveyParticipants(3);
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipantsWithNoParticipantsFoundException()
|
||||
{
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
[
|
||||
'status' => ReasonType::NO_PARTICIPANTS_FOUND,
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
$participants = $this->serviceWithParticipants->getSurveyParticipants(3);
|
||||
|
||||
static::assertInstanceOf(Collection::className, $participants);
|
||||
static::assertCount(0, $participants);
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipants()
|
||||
{
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
null,
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
null,
|
||||
[
|
||||
'token_count' => '2',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(6, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertCount(0, $this->serviceWithoutParticipants->getSurveyParticipants(1));
|
||||
static::assertCount(0, $this->serviceWithoutParticipants->getSurveyParticipants(2));
|
||||
|
||||
static::assertCount(2, $this->serviceWithParticipants->getSurveyParticipants(1));
|
||||
static::assertCount(1, $this->serviceWithParticipants->getSurveyParticipants(2));
|
||||
static::assertCount(0, $this->serviceWithParticipants->getSurveyParticipants(3));
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipantsWithNoTableException()
|
||||
{
|
||||
$this->setExpectedException(CannotProcessDataException::className);
|
||||
$exception = new CannotProcessDataException(ReasonType::NO_TOKEN_TABLE);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
$this->serviceWithParticipants->getSurveyParticipants(3);
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipantsWithNoParticipantsException()
|
||||
{
|
||||
$this->setExpectedException(CannotProcessDataException::className);
|
||||
$exception = new CannotProcessDataException(ReasonType::NO_PARTICIPANTS_FOUND);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
static::assertCount(0, $this->serviceWithParticipants->getSurveyParticipants(3));
|
||||
}
|
||||
|
||||
public function testAddParticipantForNotExistingSurvey()
|
||||
{
|
||||
$this->setExpectedException(CannotProcessDataException::className);
|
||||
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$surveyId = 1;
|
||||
$firstName = 'John';
|
||||
$lastName = 'Scott';
|
||||
$email = 'john@scott.com';
|
||||
|
||||
$this->serviceWithoutParticipants->addParticipant($surveyId, $firstName, $lastName, $email);
|
||||
$this->serviceWithParticipants->addParticipant($surveyId, $firstName, $lastName, $email);
|
||||
}
|
||||
|
||||
public function testAddParticipant()
|
||||
{
|
||||
$surveyId = 1;
|
||||
$firstName = 'John';
|
||||
$lastName = 'Scott';
|
||||
$email = 'john@scott.com';
|
||||
$runMethodCallCount = 1;
|
||||
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
[
|
||||
'firstname' => $firstName,
|
||||
'lastname' => $lastName,
|
||||
'email' => $email,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager($runMethodCallCount, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$result = $this->serviceWithoutParticipants->addParticipant($surveyId, $firstName, $lastName, $email);
|
||||
|
||||
static::assertInstanceOf(Participant::className, $result);
|
||||
static::assertEquals($firstName, $result->getFirstName());
|
||||
static::assertEquals($lastName, $result->getLastName());
|
||||
static::assertEquals($email, $result->getEmail());
|
||||
}
|
||||
|
||||
public function testGetParticipant()
|
||||
{
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
null,
|
||||
[
|
||||
[
|
||||
'tid' => 1,
|
||||
'participant_info' => [
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
],
|
||||
],
|
||||
[
|
||||
'tid' => 2,
|
||||
'participant_info' => [
|
||||
'firstname' => 'Mary',
|
||||
'lastname' => 'Jane',
|
||||
'email' => 'mary@jane.com',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'token_count' => '2',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$participant1 = $this->serviceWithoutParticipants->getParticipant(1, 'john@scott.com');
|
||||
$participant2 = $this->serviceWithParticipants->getParticipant(1, 'john@scott.com');
|
||||
|
||||
static::assertNull($participant1);
|
||||
static::assertInstanceOf(ParticipantShort::className, $participant2);
|
||||
static::assertEquals('John', $participant2->getFirstName());
|
||||
static::assertEquals('Scott', $participant2->getLastName());
|
||||
static::assertEquals('john@scott.com', $participant2->getEmail());
|
||||
}
|
||||
|
||||
public function testGetSurveyTokenCountWithException()
|
||||
{
|
||||
$this->setExpectedException(MissingSurveySummaryException::className);
|
||||
|
||||
$runMethodCallResults = [
|
||||
null,
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(1, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
|
||||
|
||||
$this->serviceWithoutSurveys->getSurveyTokenCount(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
@@ -216,10 +492,22 @@ class SurveyServiceTest extends BaseTestCase
|
||||
{
|
||||
$rpcClientManager = $this->createMock(JsonRpcClientManager::className);
|
||||
|
||||
$rpcClientManager
|
||||
$mocker = $rpcClientManager
|
||||
->expects(static::exactly($runMethodCallCount))
|
||||
->method('runMethod')
|
||||
->will(static::returnValue($runMethodCallResults));
|
||||
->method('runMethod');
|
||||
|
||||
if (!empty($runMethodCallResults)) {
|
||||
$function = [
|
||||
$mocker,
|
||||
'willReturnOnConsecutiveCalls',
|
||||
];
|
||||
|
||||
/*
|
||||
* I have to use the call_user_func_array() function to pass elements of $runMethodCallResults array as
|
||||
* arguments of the willReturnOnConsecutiveCalls() method
|
||||
*/
|
||||
call_user_func_array($function, $runMethodCallResults);
|
||||
}
|
||||
|
||||
return $rpcClientManager;
|
||||
}
|
||||
@@ -287,4 +575,55 @@ class SurveyServiceTest extends BaseTestCase
|
||||
|
||||
$this->serviceWithSurveys = new SurveyService($client, $allSurveys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service without participants
|
||||
*
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $sessionManager Manager of session started while connecting to LimeSurvey's API
|
||||
*/
|
||||
private function createServiceWithoutParticipants(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
$this->serviceWithoutParticipants = new SurveyService($client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service with participants
|
||||
*
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $sessionManager Manager of session started while connecting to LimeSurvey's API
|
||||
*/
|
||||
private function createServiceWithParticipants(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
|
||||
$allParticipants = new Participants([
|
||||
1 => new Collection([
|
||||
new ParticipantShort([
|
||||
'tid' => 1,
|
||||
'participant_info' => [
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
],
|
||||
]),
|
||||
new ParticipantShort([
|
||||
'tid' => 2,
|
||||
'participant_info' => [
|
||||
'firstname' => 'Mary',
|
||||
'lastname' => 'Jane',
|
||||
'email' => 'mary@jane.com',
|
||||
],
|
||||
]),
|
||||
]),
|
||||
2 => new Collection([
|
||||
new ParticipantShort(),
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->serviceWithParticipants = new SurveyService($client, null, $allParticipants);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,6 +250,7 @@ class MethodTypeTest extends BaseTypeTestCase
|
||||
'EXPORT_STATISTICS' => MethodType::EXPORT_STATISTICS,
|
||||
'GET_PARTICIPANT_PROPERTIES' => MethodType::GET_PARTICIPANT_PROPERTIES,
|
||||
'GET_QUESTION_PROPERTIES' => MethodType::GET_QUESTION_PROPERTIES,
|
||||
'GET_SUMMARY' => MethodType::GET_SUMMARY,
|
||||
'LIST_PARTICIPANTS' => MethodType::LIST_PARTICIPANTS,
|
||||
'LIST_QUESTIONS' => MethodType::LIST_QUESTIONS,
|
||||
'LIST_SURVEYS' => MethodType::LIST_SURVEYS,
|
||||
|
||||
Reference in New Issue
Block a user