mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 10:11:49 +01:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3b0e66fb3 | ||
|
|
0fbfc9780d | ||
|
|
92315bd853 | ||
|
|
c3e6935dd8 | ||
|
|
07bc4ab4af | ||
|
|
fd1ec32e1a | ||
|
|
72480ecc27 | ||
|
|
20d7d2f50d | ||
|
|
f5bafdc969 | ||
|
|
0eb6cc85a2 | ||
|
|
e803d82844 | ||
|
|
01439aaa1f | ||
|
|
844f04c877 | ||
|
|
959e9481fd | ||
|
|
af2df98d14 | ||
|
|
d0badf1ec6 | ||
|
|
2dc215a3e4 | ||
|
|
10c0bf8e41 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
### Composer
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
/composer.lock
|
||||
/composer.phar
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"description": "Client of LimeSurvey API",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.6",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Meritoo",
|
||||
@@ -15,13 +15,13 @@
|
||||
"meritoo/common-library": "~0.0.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.35 || ^5.4.3",
|
||||
"squizlabs/php_codesniffer": "^2.8",
|
||||
"phpunit/phpunit": "^5.7",
|
||||
"squizlabs/php_codesniffer": "^2.9",
|
||||
"phpmd/phpmd": "^2.6",
|
||||
"sebastian/phpcpd": "^3.0",
|
||||
"pdepend/pdepend": "^2.5",
|
||||
"phploc/phploc": "^4.0",
|
||||
"friendsofphp/php-cs-fixer": "^2.5"
|
||||
"friendsofphp/php-cs-fixer": "^2.6"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
||||
3581
composer.lock
generated
3581
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -77,7 +77,8 @@ class Client
|
||||
public function run($method, $arguments = [])
|
||||
{
|
||||
/*
|
||||
* Let's validate method
|
||||
* Let's validate method.
|
||||
* It's called in the JsonRpcClientManager::runMethod() too, but I want to verify it before getting session key.
|
||||
*/
|
||||
$method = MethodType::getValidatedMethod($method);
|
||||
|
||||
@@ -92,7 +93,7 @@ class Client
|
||||
->getSessionKey($username, $password);
|
||||
|
||||
/*
|
||||
* Use the session's key as of the method's arguments
|
||||
* Use the session's key as one of the method's arguments
|
||||
*/
|
||||
array_unshift($arguments, $sessionKey);
|
||||
|
||||
@@ -103,6 +104,18 @@ class Client
|
||||
->getRpcClientManager()
|
||||
->runMethod($method, $arguments);
|
||||
|
||||
/*
|
||||
* Raw data is unknown?
|
||||
* Let's use an empty array instead
|
||||
*
|
||||
* Required to avoid bug:
|
||||
* Argument 2 passed to Meritoo\LimeSurvey\ApiClient\Result\Result::__construct() must be of the type array,
|
||||
* null given
|
||||
*/
|
||||
if (null === $rawData) {
|
||||
$rawData = [];
|
||||
}
|
||||
|
||||
return new Result($method, $rawData);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,15 +59,26 @@ class ConnectionConfiguration
|
||||
*/
|
||||
private $debugMode = false;
|
||||
|
||||
/**
|
||||
* If is set to true, the SSL certificate verification is turned on. Otherwise - turned off.
|
||||
* It's useful while running application with custom, non-official SSL certificate, e.g. while development process.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $verifySslCertificate = true;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $baseUrl Base url. Protocol & domain.
|
||||
* @param string $username Name of user used to authenticate to LimeSurvey
|
||||
* @param string $password Password used to authenticate to LimeSurvey
|
||||
* @param bool $debugMode (optional) If is set to true, the "debug" mode is turned on. Otherwise - turned off.
|
||||
* @param string $baseUrl Base url. Protocol & domain.
|
||||
* @param string $username Name of user used to authenticate to LimeSurvey
|
||||
* @param string $password Password used to authenticate to LimeSurvey
|
||||
* @param bool $debugMode (optional) If is set to true, the "debug" mode is turned on. Otherwise -
|
||||
* turned off.
|
||||
* @param bool $verifySslCertificate (optional) If is set to true, the SSL certificate verification is turned
|
||||
* on. Otherwise - turned off.
|
||||
*/
|
||||
public function __construct($baseUrl, $username, $password, $debugMode = false)
|
||||
public function __construct($baseUrl, $username, $password, $debugMode = false, $verifySslCertificate = true)
|
||||
{
|
||||
$this
|
||||
->setBaseUrl($baseUrl)
|
||||
@@ -201,6 +212,30 @@ class ConnectionConfiguration
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if the SSL certificate verification is turned on
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isVerifySslCertificateOn()
|
||||
{
|
||||
return $this->verifySslCertificate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets information if the SSL certificate verification is turned on
|
||||
*
|
||||
* @param bool $verifySslCertificate (optional) If is set to true, the SSL certificate verification is turned on.
|
||||
* Otherwise - turned off.
|
||||
* @return $this
|
||||
*/
|
||||
public function setVerifySslCertificate($verifySslCertificate = true)
|
||||
{
|
||||
$this->verifySslCertificate = $verifySslCertificate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/*
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
* Additional / extra methods (neither getters, nor setters)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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\ApiClient\Exception;
|
||||
|
||||
/**
|
||||
* An exception used while raw data returned by the LimeSurvey's API cannot be processed
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class CannotProcessDataException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $reason Reason why data cannot be processed, e.g. "Invalid user name or password"
|
||||
*/
|
||||
public function __construct($reason)
|
||||
{
|
||||
$template = 'Raw data returned by the LimeSurvey\'s API cannot be processed. Reason: \'%s\'.';
|
||||
$message = sprintf($template, $reason);
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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\ApiClient\Exception;
|
||||
|
||||
use Exception;
|
||||
use Meritoo\Common\Utilities\Arrays;
|
||||
|
||||
/**
|
||||
* An exception used when an error occurred while running method
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class InvalidResultOfMethodRunException extends Exception
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param Exception $previousException The previous exception, source of an error
|
||||
* @param string $methodName Name of called method
|
||||
* @param array $methodArguments (optional) Arguments of the called method
|
||||
*/
|
||||
public function __construct(Exception $previousException, $methodName, array $methodArguments = [])
|
||||
{
|
||||
$template = "Oops, an error occurred while running method. Is there everything ok? Details:\n"
|
||||
. "- error: %s,\n"
|
||||
. "- method: %s,\n"
|
||||
. '- arguments: %s.';
|
||||
|
||||
if (empty($methodArguments)) {
|
||||
$methodArguments = '(no arguments)';
|
||||
} else {
|
||||
$methodArguments = Arrays::valuesKeys2string($methodArguments, ', ', '=', '"');
|
||||
}
|
||||
|
||||
$message = sprintf($template, $previousException->getMessage(), $methodName, $methodArguments);
|
||||
parent::__construct($message, $previousException->getCode());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
<?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\ApiClient\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Manager;
|
||||
|
||||
use JsonRPC\Client as RpcClient;
|
||||
use JsonRPC\Exception\InvalidJsonFormatException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\InvalidResultOfMethodRunException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownMethodException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
@@ -47,14 +49,22 @@ class JsonRpcClientManager
|
||||
* @return mixed
|
||||
*
|
||||
* @throws UnknownMethodException
|
||||
* @throws InvalidResultOfMethodRunException
|
||||
*/
|
||||
public function runMethod($method, $arguments = [])
|
||||
{
|
||||
$result = null;
|
||||
$method = MethodType::getValidatedMethod($method);
|
||||
|
||||
return $this
|
||||
->getRpcClient()
|
||||
->execute($method, $arguments);
|
||||
try {
|
||||
$result = $this
|
||||
->getRpcClient()
|
||||
->execute($method, $arguments);
|
||||
} catch (InvalidJsonFormatException $exception) {
|
||||
throw new InvalidResultOfMethodRunException($exception, $method);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +85,20 @@ class JsonRpcClientManager
|
||||
* The "debug" mode is turned on?
|
||||
*/
|
||||
if ($this->connectionConfiguration->isDebugModeOn()) {
|
||||
$this->rpcClient->getHttpClient()->withDebug();
|
||||
$this
|
||||
->rpcClient
|
||||
->getHttpClient()
|
||||
->withDebug();
|
||||
}
|
||||
|
||||
/*
|
||||
* The SSL certificate verification is turned off?
|
||||
*/
|
||||
if (!$this->connectionConfiguration->isVerifySslCertificateOn()) {
|
||||
$this
|
||||
->rpcClient
|
||||
->getHttpClient()
|
||||
->withoutSslVerification();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
<?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\ApiClient\Result\Collection;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\Common\Exception\Method\DisabledMethodException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
|
||||
/**
|
||||
* Participants of survey.
|
||||
* All participants grouped per survey.
|
||||
*
|
||||
* It's a collection of participants' collections.
|
||||
* The survey ID is used as an index per each collection of participants, so they are grouped by survey.
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class Participants extends Collection
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($element, $index = null)
|
||||
{
|
||||
throw new DisabledMethodException(__METHOD__, 'addParticipants');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addMultiple($elements, $useIndexes = false)
|
||||
{
|
||||
throw new DisabledMethodException(__METHOD__, 'addParticipants');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds participants of given survey
|
||||
*
|
||||
* @param Collection $participants Participants to add. Collection of Participant classes.
|
||||
* @param int $surveyId ID of survey
|
||||
* @return $this
|
||||
*/
|
||||
public function addParticipants(Collection $participants, $surveyId)
|
||||
{
|
||||
/*
|
||||
* No participants?
|
||||
* Nothing to do
|
||||
*/
|
||||
if ($participants->isEmpty()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this
|
||||
->getBySurvey($surveyId)
|
||||
->addMultiple($participants);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds participant of given survey
|
||||
*
|
||||
* @param Participant $participant Participant to add
|
||||
* @param int $surveyId ID of survey
|
||||
* @return $this
|
||||
*/
|
||||
public function addParticipant(Participant $participant, $surveyId)
|
||||
{
|
||||
$this
|
||||
->getBySurvey($surveyId)
|
||||
->add($participant);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if there are participants of given survey
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @return bool
|
||||
*/
|
||||
public function hasParticipantsOfSurvey($surveyId)
|
||||
{
|
||||
return false === $this
|
||||
->getBySurvey($surveyId)
|
||||
->isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns participants of given survey
|
||||
*
|
||||
* If there are no participants of given survey, adds an empty collection who will store participants.
|
||||
* So, this method will return collection always.
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBySurvey($surveyId)
|
||||
{
|
||||
/*
|
||||
* There are no participants of given survey?
|
||||
* Let's add an empty collection who will store participants
|
||||
*/
|
||||
if (!isset($this[$surveyId])) {
|
||||
$this[$surveyId] = new Collection();
|
||||
}
|
||||
|
||||
return $this[$surveyId];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns participant of given survey
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $participantEmail E-mail of searched participant
|
||||
* @return Participant|null
|
||||
*/
|
||||
public function getParticipantOfSurvey($surveyId, $participantEmail)
|
||||
{
|
||||
/* @var Collection $participants */
|
||||
$participants = $this->getBySurvey($surveyId);
|
||||
|
||||
if ($participants->isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* @var Participant $participant */
|
||||
foreach ($participants as $participant) {
|
||||
if ($participant->getEmail() == $participantEmail) {
|
||||
return $participant;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -55,9 +55,9 @@ class ResultProcessor
|
||||
*/
|
||||
if (MethodType::isResultIterable($method)) {
|
||||
$items = [];
|
||||
$emptyItem = clone $item;
|
||||
|
||||
foreach ($rawData as $itemData) {
|
||||
$emptyItem = clone $item;
|
||||
$items[] = $emptyItem->setValues($itemData);
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ class ResultProcessor
|
||||
$method = MethodType::getValidatedMethod($method);
|
||||
|
||||
switch ($method) {
|
||||
case MethodType::ADD_PARTICIPANTS:
|
||||
case MethodType::GET_PARTICIPANT_PROPERTIES:
|
||||
$item = new Participant();
|
||||
break;
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Meritoo\LimeSurvey\ApiClient\Result;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
@@ -35,6 +36,13 @@ class Result
|
||||
*/
|
||||
private $rawData;
|
||||
|
||||
/**
|
||||
* Status, information returned instead of usual/normal result
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* Processor of the raw data fetched while talking to the LimeSurvey's API
|
||||
*
|
||||
@@ -52,7 +60,7 @@ class Result
|
||||
public function __construct($method, array $rawData)
|
||||
{
|
||||
$this->method = MethodType::getValidatedMethod($method);
|
||||
$this->rawData = $rawData;
|
||||
$this->setRawDataAndStatus($rawData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,14 +79,41 @@ class Result
|
||||
* @param bool $raw (optional) If is set to true, raw data provided by the LimeSurvey's API will be returned.
|
||||
* Otherwise - prepared/processed.
|
||||
* @return array|Collection|BaseItem
|
||||
* @throws CannotProcessDataException
|
||||
*/
|
||||
public function getData($raw = false)
|
||||
{
|
||||
/*
|
||||
* Raw data should be returned only?
|
||||
* Let's do it
|
||||
*/
|
||||
if ($raw) {
|
||||
return $this->rawData;
|
||||
}
|
||||
|
||||
return $this->getProcessedData($this->rawData);
|
||||
/*
|
||||
* Status is unknown?
|
||||
* Let's process the raw data
|
||||
*/
|
||||
if (empty($this->status)) {
|
||||
return $this->getProcessedData($this->rawData);
|
||||
}
|
||||
|
||||
/*
|
||||
* Oops, the raw data returned by the LimeSurvey's API cannot be processed, because status was provided.
|
||||
* Well, probably something is broken and... there is no data.
|
||||
*/
|
||||
throw new CannotProcessDataException($this->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns status, information returned instead of usual/normal result
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,4 +154,23 @@ class Result
|
||||
|
||||
return $this->resultProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets status, information returned instead of usual/normal result and raw data returned by the LimeSurvey's API
|
||||
*
|
||||
* @param array $rawData Raw data returned by the LimeSurvey's API
|
||||
*/
|
||||
private function setRawDataAndStatus(array $rawData)
|
||||
{
|
||||
/*
|
||||
* Status was provided?
|
||||
* Well, probably something is broken and... there is no data
|
||||
*/
|
||||
if (isset($rawData['status'])) {
|
||||
$this->status = trim($rawData['status']);
|
||||
$rawData = [];
|
||||
}
|
||||
|
||||
$this->rawData = $rawData;
|
||||
}
|
||||
}
|
||||
|
||||
142
src/Meritoo/LimeSurvey/ApiClient/Service/ParticipantService.php
Normal file
142
src/Meritoo/LimeSurvey/ApiClient/Service/ParticipantService.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?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\ApiClient\Service;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Serves participants
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantService
|
||||
{
|
||||
/**
|
||||
* Client of the LimeSurvey's API
|
||||
*
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* Participants of survey.
|
||||
* All participants grouped per survey.
|
||||
*
|
||||
* @var Participants
|
||||
*/
|
||||
private $allParticipants;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param Client $client Client of the LimeSurvey's API
|
||||
* @param Participants $allParticipants (optional) Participants of survey. All participants grouped per survey.
|
||||
*/
|
||||
public function __construct(Client $client, Participants $allParticipants = null)
|
||||
{
|
||||
if (null === $allParticipants) {
|
||||
$allParticipants = new Participants();
|
||||
}
|
||||
|
||||
$this->client = $client;
|
||||
$this->allParticipants = $allParticipants;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns participants of given survey
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @return Collection
|
||||
*/
|
||||
public function getSurveyParticipants($surveyId)
|
||||
{
|
||||
$hasSurvey = $this
|
||||
->allParticipants
|
||||
->hasParticipantsOfSurvey($surveyId);
|
||||
|
||||
if (!$hasSurvey) {
|
||||
$arguments = [
|
||||
$surveyId,
|
||||
];
|
||||
|
||||
$participants = $this
|
||||
->client
|
||||
->run(MethodType::LIST_PARTICIPANTS, $arguments)
|
||||
->getData();
|
||||
|
||||
$this
|
||||
->allParticipants
|
||||
->addParticipants($participants, $surveyId);
|
||||
}
|
||||
|
||||
return $this
|
||||
->allParticipants
|
||||
->getBySurvey($surveyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if given survey has participant with given e-mail
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $email E-mail address of the participant
|
||||
* @return bool
|
||||
*/
|
||||
public function hasParticipant($surveyId, $email)
|
||||
{
|
||||
/*
|
||||
* I have to get all participants of survey to avoid problem when participants exist but are not loaded
|
||||
*/
|
||||
$this->getSurveyParticipants($surveyId);
|
||||
|
||||
return null !== $this
|
||||
->allParticipants
|
||||
->getParticipantOfSurvey($surveyId, $email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds participant with given data to survey with given ID
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $firstName First name of the participant to add
|
||||
* @param string $lastName Last ame of the participant to add
|
||||
* @param string $email E-mail address of the participant to add
|
||||
* @return Participant
|
||||
*/
|
||||
public function addParticipant($surveyId, $firstName, $lastName, $email)
|
||||
{
|
||||
$participantsData = [
|
||||
[
|
||||
'firstname' => $firstName,
|
||||
'lastname' => $lastName,
|
||||
'email' => $email,
|
||||
],
|
||||
];
|
||||
|
||||
$arguments = [
|
||||
$surveyId,
|
||||
$participantsData,
|
||||
];
|
||||
|
||||
$participantCollection = $this
|
||||
->client
|
||||
->run(MethodType::ADD_PARTICIPANTS, $arguments)
|
||||
->getData();
|
||||
|
||||
$this
|
||||
->allParticipants
|
||||
->addParticipants($participantCollection, $surveyId);
|
||||
|
||||
return $participantCollection->getFirst();
|
||||
}
|
||||
}
|
||||
104
src/Meritoo/LimeSurvey/ApiClient/Service/SurveyService.php
Normal file
104
src/Meritoo/LimeSurvey/ApiClient/Service/SurveyService.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?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\ApiClient\Service;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Serves surveys
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveyService
|
||||
{
|
||||
/**
|
||||
* Client of the LimeSurvey's API
|
||||
*
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* All surveys
|
||||
*
|
||||
* @var Collection
|
||||
*/
|
||||
private $allSurveys;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param Client $client Client of the LimeSurvey's API
|
||||
* @param Collection $allSurveys (optional) All surveys
|
||||
*/
|
||||
public function __construct(Client $client, Collection $allSurveys = null)
|
||||
{
|
||||
if (null === $allSurveys) {
|
||||
$allSurveys = new Collection();
|
||||
}
|
||||
|
||||
$this->client = $client;
|
||||
$this->allSurveys = $allSurveys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all surveys
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllSurveys()
|
||||
{
|
||||
if ($this->allSurveys->isEmpty()) {
|
||||
$surveys = $this
|
||||
->client
|
||||
->run(MethodType::LIST_SURVEYS)
|
||||
->getData();
|
||||
|
||||
if (null !== $surveys) {
|
||||
$this->allSurveys = $surveys;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->allSurveys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if survey with given ID exists
|
||||
*
|
||||
* @param int $surveyId ID of survey to verify
|
||||
* @return bool
|
||||
*/
|
||||
public function isExistingSurvey($surveyId)
|
||||
{
|
||||
$allSurveys = $this->getAllSurveys();
|
||||
|
||||
/*
|
||||
* No surveys?
|
||||
* Nothing to do
|
||||
*/
|
||||
if ($allSurveys->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$surveyId = (int)$surveyId;
|
||||
|
||||
/* @var Survey $survey */
|
||||
foreach ($allSurveys as $survey) {
|
||||
if ($survey->getId() == $surveyId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,16 @@ use Meritoo\LimeSurvey\ApiClient\Exception\UnknownMethodException;
|
||||
*/
|
||||
class MethodType extends BaseType
|
||||
{
|
||||
/**
|
||||
* Add participants to the tokens collection of the survey
|
||||
*
|
||||
* Returns the inserted data including additional new information like the Token entry ID and the token string.
|
||||
* In case of errors in some data, return it in errors.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ADD_PARTICIPANTS = 'add_participants';
|
||||
|
||||
/**
|
||||
* Add a response to the survey responses collection.
|
||||
* Returns the id of the inserted survey response.
|
||||
@@ -86,7 +96,7 @@ class MethodType extends BaseType
|
||||
*/
|
||||
public static function getValidatedMethod($method)
|
||||
{
|
||||
if ((new static())->isCorrectType($method)) {
|
||||
if ((new static())->isCorrectType($method) || (new SystemMethodType())->isCorrectType($method)) {
|
||||
return $method;
|
||||
}
|
||||
|
||||
@@ -104,6 +114,7 @@ class MethodType extends BaseType
|
||||
$method = static::getValidatedMethod($method);
|
||||
|
||||
return in_array($method, [
|
||||
static::ADD_PARTICIPANTS,
|
||||
static::LIST_PARTICIPANTS,
|
||||
static::LIST_QUESTIONS,
|
||||
static::LIST_SURVEYS,
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Base\Result;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Test case of the base class for one item of result/data fetched while talking to the LimeSurvey's API
|
||||
@@ -18,14 +17,11 @@ use ReflectionClass;
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class BaseItemTest extends PHPUnit_Framework_TestCase
|
||||
class BaseItemTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$reflection = new ReflectionClass(BaseItem::class);
|
||||
$constructor = $reflection->getConstructor();
|
||||
|
||||
static::assertNull($constructor);
|
||||
static::assertHasNoConstructor(BaseItem::class);
|
||||
}
|
||||
|
||||
public function testSetValues()
|
||||
|
||||
@@ -34,6 +34,11 @@ class ClientTest extends BaseTestCase
|
||||
*/
|
||||
private $configuration;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(Client::class, OopVisibilityType::IS_PUBLIC, 3, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $incorrectMethod Incorrect name of method to call
|
||||
* @dataProvider provideIncorrectMethod
|
||||
@@ -71,12 +76,12 @@ class ClientTest extends BaseTestCase
|
||||
|
||||
public function testGetRpcClientManagerVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(Client::class, 'getRpcClientManager', OopVisibilityType::IS_PRIVATE);
|
||||
static::assertMethodVisibilityAndArguments(Client::class, 'getRpcClientManager', OopVisibilityType::IS_PRIVATE);
|
||||
}
|
||||
|
||||
public function testGetSessionManagerVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(Client::class, 'getRpcClientManager', OopVisibilityType::IS_PRIVATE);
|
||||
static::assertMethodVisibilityAndArguments(Client::class, 'getRpcClientManager', OopVisibilityType::IS_PRIVATE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Meritoo\LimeSurvey\Test\ApiClient\Configuration;
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Regex\InvalidUrlException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
|
||||
/**
|
||||
@@ -21,6 +22,18 @@ use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
*/
|
||||
class ConnectionConfigurationTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Simple instance of the configuration
|
||||
*
|
||||
* @var ConnectionConfiguration
|
||||
*/
|
||||
private $simpleConfiguration;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 5, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $emptyBaseUrl Empty base url
|
||||
* @dataProvider provideEmptyBaseUrl
|
||||
@@ -43,69 +56,67 @@ class ConnectionConfigurationTest extends BaseTestCase
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
|
||||
static::assertEquals('http://test.com', $configuration->getBaseUrl());
|
||||
static::assertEquals('test1', $configuration->getUsername());
|
||||
static::assertEquals('test2', $configuration->getPassword());
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
static::assertEquals('http://test.com', $this->simpleConfiguration->getBaseUrl());
|
||||
static::assertEquals('test1', $this->simpleConfiguration->getUsername());
|
||||
static::assertEquals('test2', $this->simpleConfiguration->getPassword());
|
||||
static::assertFalse($this->simpleConfiguration->isDebugModeOn());
|
||||
}
|
||||
|
||||
public function testSetBaseUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$this->simpleConfiguration->setBaseUrl('http://lorem.ipsum');
|
||||
static::assertEquals('http://lorem.ipsum', $this->simpleConfiguration->getBaseUrl());
|
||||
|
||||
$configuration->setBaseUrl('http://lorem.ipsum');
|
||||
static::assertEquals('http://lorem.ipsum', $configuration->getBaseUrl());
|
||||
|
||||
$configuration->setBaseUrl('http://lorem.ipsum/');
|
||||
static::assertEquals('http://lorem.ipsum', $configuration->getBaseUrl());
|
||||
$this->simpleConfiguration->setBaseUrl('http://lorem.ipsum/');
|
||||
static::assertEquals('http://lorem.ipsum', $this->simpleConfiguration->getBaseUrl());
|
||||
}
|
||||
|
||||
public function testSetRemoteControlUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setRemoteControlUrl('/lorem/ipsum');
|
||||
|
||||
static::assertEquals('/lorem/ipsum', $configuration->getRemoteControlUrl());
|
||||
$this->simpleConfiguration->setRemoteControlUrl('/lorem/ipsum');
|
||||
static::assertEquals('/lorem/ipsum', $this->simpleConfiguration->getRemoteControlUrl());
|
||||
}
|
||||
|
||||
public function testSetUsername()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setUsername('lorem');
|
||||
|
||||
static::assertEquals('lorem', $configuration->getUsername());
|
||||
$this->simpleConfiguration->setUsername('lorem');
|
||||
static::assertEquals('lorem', $this->simpleConfiguration->getUsername());
|
||||
}
|
||||
|
||||
public function testSetPassword()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setPassword('ipsum');
|
||||
|
||||
static::assertEquals('ipsum', $configuration->getPassword());
|
||||
$this->simpleConfiguration->setPassword('ipsum');
|
||||
static::assertEquals('ipsum', $this->simpleConfiguration->getPassword());
|
||||
}
|
||||
|
||||
public function testSetDebugMode()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$this->simpleConfiguration->setDebugMode();
|
||||
static::assertFalse($this->simpleConfiguration->isDebugModeOn());
|
||||
|
||||
$configuration->setDebugMode();
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
$this->simpleConfiguration->setDebugMode(false);
|
||||
static::assertFalse($this->simpleConfiguration->isDebugModeOn());
|
||||
|
||||
$configuration->setDebugMode(false);
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
$this->simpleConfiguration->setDebugMode(true);
|
||||
static::assertTrue($this->simpleConfiguration->isDebugModeOn());
|
||||
}
|
||||
|
||||
$configuration->setDebugMode(true);
|
||||
static::assertTrue($configuration->isDebugModeOn());
|
||||
public function testSetVerifySslCertificate()
|
||||
{
|
||||
$this->simpleConfiguration->setVerifySslCertificate();
|
||||
static::assertTrue($this->simpleConfiguration->isVerifySslCertificateOn());
|
||||
|
||||
$this->simpleConfiguration->setVerifySslCertificate(false);
|
||||
static::assertFalse($this->simpleConfiguration->isVerifySslCertificateOn());
|
||||
|
||||
$this->simpleConfiguration->setVerifySslCertificate(true);
|
||||
static::assertTrue($this->simpleConfiguration->isVerifySslCertificateOn());
|
||||
}
|
||||
|
||||
public function testGetFullUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setRemoteControlUrl('lorem/ipsum');
|
||||
|
||||
static::assertEquals('http://test.com/lorem/ipsum', $configuration->getFullUrl());
|
||||
$this->simpleConfiguration->setRemoteControlUrl('lorem/ipsum');
|
||||
static::assertEquals('http://test.com/lorem/ipsum', $this->simpleConfiguration->getFullUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,4 +154,13 @@ class ConnectionConfigurationTest extends BaseTestCase
|
||||
'htp:/dolor.com',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->simpleConfiguration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?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 Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while raw data returned by the LimeSurvey's API cannot be processed
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class CannotProcessDataExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(CannotProcessDataException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $reason Reason why data cannot be processed, e.g. "Invalid user name or password"
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideReason
|
||||
*/
|
||||
public function testConstructorMessage($reason, $expectedMessage)
|
||||
{
|
||||
$exception = new CannotProcessDataException($reason);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides reason why data cannot be processed
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideReason()
|
||||
{
|
||||
$template = 'Raw data returned by the LimeSurvey\'s API cannot be processed. Reason: \'%s\'.';
|
||||
|
||||
yield[
|
||||
'unknown',
|
||||
sprintf($template, 'unknown'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Invalid user name or password',
|
||||
sprintf($template, 'Invalid user name or password'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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 Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CreateSessionKeyFailedException;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while create of the session key has failed
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class CreateSessionKeyFailedExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(CreateSessionKeyFailedException::class, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $reason Reason of failure, e.g. "Invalid user name or password"
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideReason
|
||||
*/
|
||||
public function testConstructorMessage($reason, $expectedMessage)
|
||||
{
|
||||
$exception = new CreateSessionKeyFailedException($reason);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides reason of failure
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideReason()
|
||||
{
|
||||
$shortMessage = 'Create of the session key has failed';
|
||||
$longMessageTemplate = sprintf('%s. Reason: \'%s\'.', $shortMessage, '%s');
|
||||
|
||||
yield[
|
||||
'',
|
||||
$shortMessage,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Invalid user name or password',
|
||||
sprintf($longMessageTemplate, 'Invalid user name or password'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?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 Exception;
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\InvalidResultOfMethodRunException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used when an error occurred while running method
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class InvalidResultOfMethodRunExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(InvalidResultOfMethodRunException::class, OopVisibilityType::IS_PUBLIC, 3, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Exception $previousException The previous exception, source of an error
|
||||
* @param string $methodName Name of called method
|
||||
* @param array $methodArguments Arguments of the called method
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider providePreviousExceptionAndMethod
|
||||
*/
|
||||
public function testConstructorMessage(Exception $previousException, $methodName, array $methodArguments, $expectedMessage)
|
||||
{
|
||||
$exception = new InvalidResultOfMethodRunException($previousException, $methodName, $methodArguments);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides previous exception, name and arguments of called method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function providePreviousExceptionAndMethod()
|
||||
{
|
||||
$template = "Oops, an error occurred while running method. Is there everything ok? Details:\n"
|
||||
. "- error: %s,\n"
|
||||
. "- method: %s,\n"
|
||||
. '- arguments: %s.';
|
||||
|
||||
yield[
|
||||
new Exception('Lorem ipsum'),
|
||||
MethodType::ADD_RESPONSE,
|
||||
[],
|
||||
sprintf($template, 'Lorem ipsum', MethodType::ADD_RESPONSE, '(no arguments)'),
|
||||
];
|
||||
|
||||
yield[
|
||||
new Exception('Dolor sit amet'),
|
||||
MethodType::LIST_SURVEYS,
|
||||
[
|
||||
'fist_name' => 'John',
|
||||
'last_name' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
],
|
||||
sprintf($template, 'Dolor sit amet', MethodType::LIST_SURVEYS, 'fist_name="John", last_name="Scott", email="john@scott.com"'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?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 Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownInstanceOfResultItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while instance of one item used by result, with data fetched from the LimeSurvey's
|
||||
* API, is unknown
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class UnknownInstanceOfResultItemTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(UnknownInstanceOfResultItem::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method Name of called method while talking to the LimeSurvey's API. One of the
|
||||
* MethodType class constants.
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideMethodName
|
||||
*/
|
||||
public function testConstructorMessage($method, $expectedMessage)
|
||||
{
|
||||
$exception = new UnknownInstanceOfResultItem($method);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of called method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMethodName()
|
||||
{
|
||||
$template = 'Instance of one item used by result the of \'%s\' LimeSurvey API\'s method is unknown. Proper'
|
||||
. ' class is not mapped in %s::%s() method. Did you forget about this?';
|
||||
|
||||
yield[
|
||||
MethodType::LIST_SURVEYS,
|
||||
sprintf($template, MethodType::LIST_SURVEYS, ResultProcessor::class, 'getItemInstance'),
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::ADD_PARTICIPANTS,
|
||||
sprintf($template, MethodType::ADD_PARTICIPANTS, ResultProcessor::class, 'getItemInstance'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?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 Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownMethodException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while name of method used while talking to the LimeSurvey's API is unknown
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class UnknownMethodExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(UnknownMethodException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $unknownType The unknown type of something (value of constant)
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideUnknownType
|
||||
*/
|
||||
public function testConstructorMessage($unknownType, $expectedMessage)
|
||||
{
|
||||
$exception = new UnknownMethodException($unknownType);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of called method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUnknownType()
|
||||
{
|
||||
$allMethods = implode(', ', (new MethodType())->getAll());
|
||||
|
||||
$template = 'The \'%s\' type of name of method used while talking to the LimeSurvey\'s API is unknown. Probably'
|
||||
. ' doesn\'t exist or there is a typo. You should use one of these types: %s.';
|
||||
|
||||
yield[
|
||||
MethodType::ADD_PARTICIPANTS,
|
||||
sprintf($template, MethodType::ADD_PARTICIPANTS, $allMethods),
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::ADD_PARTICIPANTS,
|
||||
sprintf($template, MethodType::ADD_PARTICIPANTS, $allMethods),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,11 @@
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Manager;
|
||||
|
||||
use JsonRPC\Client as RpcClient;
|
||||
use JsonRPC\Exception\InvalidJsonFormatException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\InvalidResultOfMethodRunException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\Test\ApiClient\Result\Item\SurveyTest;
|
||||
@@ -33,10 +35,10 @@ class JsonRpcClientManagerTest extends BaseTestCase
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyConstructorVisibilityAndArguments(JsonRpcClientManager::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
static::assertConstructorVisibilityAndArguments(JsonRpcClientManager::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
public function testRunMethod()
|
||||
public function testRunMethodWithEmptyArrayReturned()
|
||||
{
|
||||
$rpcClient = $this->createMock(RpcClient::class);
|
||||
|
||||
@@ -51,12 +53,12 @@ class JsonRpcClientManagerTest extends BaseTestCase
|
||||
->getMock();
|
||||
|
||||
$rpcClient
|
||||
->expects(static::any())
|
||||
->expects(static::once())
|
||||
->method('execute')
|
||||
->willReturn([]);
|
||||
|
||||
$manager
|
||||
->expects(static::any())
|
||||
->expects(static::once())
|
||||
->method('getRpcClient')
|
||||
->willReturn($rpcClient);
|
||||
|
||||
@@ -64,18 +66,18 @@ class JsonRpcClientManagerTest extends BaseTestCase
|
||||
static::assertEquals([], $manager->runMethod(MethodType::LIST_SURVEYS));
|
||||
}
|
||||
|
||||
public function testRunMethodWithMockedRpcClient()
|
||||
public function testRunMethodWithRawDataReturned()
|
||||
{
|
||||
$rpcClient = $this->createMock(RpcClient::class);
|
||||
$manager = $this->createPartialMock(JsonRpcClientManager::class, ['getRpcClient']);
|
||||
|
||||
$rpcClient
|
||||
->expects(static::any())
|
||||
->expects(static::once())
|
||||
->method('execute')
|
||||
->willReturn(SurveyTest::getSurveysRawData());
|
||||
|
||||
$manager
|
||||
->expects(static::any())
|
||||
->expects(static::once())
|
||||
->method('getRpcClient')
|
||||
->willReturn($rpcClient);
|
||||
|
||||
@@ -83,9 +85,30 @@ class JsonRpcClientManagerTest extends BaseTestCase
|
||||
static::assertEquals(SurveyTest::getSurveysRawData(), $manager->runMethod(MethodType::LIST_SURVEYS));
|
||||
}
|
||||
|
||||
public function testRunMethodWithException()
|
||||
{
|
||||
$this->expectException(InvalidResultOfMethodRunException::class);
|
||||
|
||||
$manager = $this->createPartialMock(JsonRpcClientManager::class, ['getRpcClient']);
|
||||
$rpcClient = $this->createMock(RpcClient::class);
|
||||
|
||||
$rpcClient
|
||||
->expects(self::once())
|
||||
->method('execute')
|
||||
->willThrowException(new InvalidJsonFormatException('bla bla'));
|
||||
|
||||
$manager
|
||||
->expects(static::once())
|
||||
->method('getRpcClient')
|
||||
->willReturn($rpcClient);
|
||||
|
||||
/* @var JsonRpcClientManager $manager */
|
||||
$manager->runMethod(MethodType::LIST_SURVEYS);
|
||||
}
|
||||
|
||||
public function testGetRpcClientVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(JsonRpcClientManager::class, 'getRpcClient', OopVisibilityType::IS_PROTECTED);
|
||||
static::assertMethodVisibilityAndArguments(JsonRpcClientManager::class, 'getRpcClient', OopVisibilityType::IS_PROTECTED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ class SessionManagerTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyConstructorVisibilityAndArguments(SessionManager::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
static::assertConstructorVisibilityAndArguments(SessionManager::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
public function testGetSessionKeyWhenFailedWithoutReason()
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
<?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\Collection\Collection;
|
||||
use Meritoo\Common\Exception\Method\DisabledMethodException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
|
||||
/**
|
||||
* Test case of the participants of survey
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantsTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* An empty collection of participants
|
||||
*
|
||||
* @var Participants
|
||||
*/
|
||||
private $participantsEmpty;
|
||||
|
||||
/**
|
||||
* Participants of 1 survey
|
||||
*
|
||||
* @var Participants
|
||||
*/
|
||||
private $participantsOfOneSurvey;
|
||||
|
||||
/**
|
||||
* Participants of more than 1 survey
|
||||
*
|
||||
* @var Participants
|
||||
*/
|
||||
private $participantsOfManySurvey;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(Participants::class, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$this->expectException(DisabledMethodException::class);
|
||||
(new Participants())->add('');
|
||||
}
|
||||
|
||||
public function testAddMultiple()
|
||||
{
|
||||
$this->expectException(DisabledMethodException::class);
|
||||
(new Participants())->addMultiple([]);
|
||||
}
|
||||
|
||||
public function testAddParticipantsWithoutParticipants()
|
||||
{
|
||||
$surveyId = 1;
|
||||
|
||||
$participants = new Participants();
|
||||
$result = $participants->addParticipants(new Collection(), $surveyId);
|
||||
|
||||
static::assertFalse($participants->hasParticipantsOfSurvey($surveyId));
|
||||
static::assertFalse($participants->hasParticipantsOfSurvey(2));
|
||||
|
||||
static::assertEquals($participants, $result);
|
||||
static::assertCount(0, $participants->getBySurvey($surveyId));
|
||||
}
|
||||
|
||||
public function testAddParticipantsFirstParticipants()
|
||||
{
|
||||
$surveyId = 1;
|
||||
|
||||
$participantsData = new Collection([
|
||||
new Participant(),
|
||||
new Participant(),
|
||||
]);
|
||||
|
||||
$result = $this
|
||||
->participantsEmpty
|
||||
->addParticipants($participantsData, $surveyId);
|
||||
|
||||
static::assertTrue($this->participantsEmpty->hasParticipantsOfSurvey($surveyId));
|
||||
static::assertFalse($this->participantsEmpty->hasParticipantsOfSurvey(2));
|
||||
|
||||
static::assertEquals($this->participantsEmpty, $result);
|
||||
static::assertCount(2, $this->participantsEmpty->getBySurvey($surveyId));
|
||||
}
|
||||
|
||||
public function testAddParticipantsMoreParticipants()
|
||||
{
|
||||
$surveyId = 2;
|
||||
|
||||
$participantsData = new Collection([
|
||||
new Participant(),
|
||||
new Participant(),
|
||||
]);
|
||||
|
||||
$result = $this
|
||||
->participantsOfOneSurvey
|
||||
->addParticipants($participantsData, $surveyId);
|
||||
|
||||
static::assertTrue($this->participantsOfOneSurvey->hasParticipantsOfSurvey($surveyId));
|
||||
static::assertFalse($this->participantsOfOneSurvey->hasParticipantsOfSurvey(3));
|
||||
|
||||
static::assertEquals($this->participantsOfOneSurvey, $result);
|
||||
static::assertCount(2, $this->participantsOfOneSurvey->getBySurvey($surveyId));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->participantsEmpty = new Participants();
|
||||
$this->participantsOfOneSurvey = new Participants();
|
||||
$this->participantsOfManySurvey = new Participants();
|
||||
|
||||
$participants1Survey = new Collection();
|
||||
$participants2Survey = new Collection();
|
||||
$participants3Survey = new Collection();
|
||||
|
||||
$this
|
||||
->participantsOfOneSurvey
|
||||
->addParticipants($participants1Survey, 1);
|
||||
|
||||
$this
|
||||
->participantsOfManySurvey
|
||||
->addParticipants($participants1Survey, 2)
|
||||
->addParticipants($participants2Survey, 3)
|
||||
->addParticipants($participants3Survey, 4);
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: short data of participant
|
||||
@@ -19,7 +19,7 @@ use PHPUnit_Framework_TestCase;
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantShortTest extends PHPUnit_Framework_TestCase
|
||||
class ParticipantShortTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Raw data of participants
|
||||
@@ -42,6 +42,11 @@ class ParticipantShortTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
private $participant2ndInstance;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(ParticipantShort::class);
|
||||
}
|
||||
|
||||
public function testCreateOfTheParticipant()
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use DateTime;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: full data of participant
|
||||
@@ -20,7 +20,7 @@ use PHPUnit_Framework_TestCase;
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantTest extends PHPUnit_Framework_TestCase
|
||||
class ParticipantTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Raw data of participants
|
||||
@@ -43,6 +43,11 @@ class ParticipantTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
private $participant2ndInstance;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(Participant::class);
|
||||
}
|
||||
|
||||
public function testCreateOfTheParticipant()
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
|
||||
@@ -42,6 +42,11 @@ class QuestionShortTest extends BaseTestCase
|
||||
*/
|
||||
private $question2ndInstance;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(QuestionShort::class);
|
||||
}
|
||||
|
||||
public function testCreateOfTheQuestionShort()
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Question;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: full data of one question of survey
|
||||
@@ -19,7 +19,7 @@ use PHPUnit_Framework_TestCase;
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class QuestionTest extends PHPUnit_Framework_TestCase
|
||||
class QuestionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Raw data of questions
|
||||
@@ -42,6 +42,11 @@ class QuestionTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
private $question2ndInstance;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(Question::class);
|
||||
}
|
||||
|
||||
public function testCreateOfTheQuestionShort()
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use DateTime;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: survey
|
||||
@@ -20,7 +20,7 @@ use PHPUnit_Framework_TestCase;
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveyTest extends PHPUnit_Framework_TestCase
|
||||
class SurveyTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Raw data of surveys
|
||||
@@ -43,6 +43,11 @@ class SurveyTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
private $survey2ndInstance;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(Survey::class);
|
||||
}
|
||||
|
||||
public function testCreateOfTheSurvey()
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
|
||||
@@ -12,10 +12,10 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownInstanceOfResultItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\Test\ApiClient\Result\Item\SurveyTest;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Test case of the processor of the raw data fetched while talking to the LimeSurvey's API
|
||||
@@ -27,10 +27,7 @@ class ResultProcessorTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$reflection = new ReflectionClass(ResultProcessor::class);
|
||||
$constructor = $reflection->getConstructor();
|
||||
|
||||
static::assertNull($constructor);
|
||||
static::assertHasNoConstructor(ResultProcessor::class);
|
||||
}
|
||||
|
||||
public function testProcessWithEmptyRawData()
|
||||
@@ -43,12 +40,24 @@ class ResultProcessorTest extends BaseTestCase
|
||||
|
||||
public function testProcessWithIterableData()
|
||||
{
|
||||
$surveysRawData = SurveyTest::getSurveysRawData();
|
||||
$processor = new ResultProcessor();
|
||||
$processed = $processor->process(MethodType::LIST_SURVEYS, SurveyTest::getSurveysRawData());
|
||||
$processed = $processor->process(MethodType::LIST_SURVEYS, $surveysRawData);
|
||||
|
||||
static::assertNotEmpty($processed);
|
||||
static::assertTrue(is_array($processed));
|
||||
static::assertCount(2, $processed);
|
||||
|
||||
/* @var Survey $firstSurvey */
|
||||
$firstSurvey = $processed[0];
|
||||
|
||||
/* @var Survey $secondSurvey */
|
||||
$secondSurvey = $processed[1];
|
||||
|
||||
static::assertEquals($surveysRawData[0]['sid'], $firstSurvey->getId());
|
||||
static::assertEquals($surveysRawData[1]['sid'], $secondSurvey->getId());
|
||||
|
||||
static::assertEquals($surveysRawData[0]['surveyls_title'], $firstSurvey->getTitle());
|
||||
static::assertEquals($surveysRawData[1]['surveyls_title'], $secondSurvey->getTitle());
|
||||
}
|
||||
|
||||
public function testProcessWithNotIterableData()
|
||||
@@ -68,7 +77,7 @@ class ResultProcessorTest extends BaseTestCase
|
||||
|
||||
public function testGetItemInstanceVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(ResultProcessor::class, 'getItemInstance', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
static::assertMethodVisibilityAndArguments(ResultProcessor::class, 'getItemInstance', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
}
|
||||
|
||||
public function testRunWithUnknownResultClass()
|
||||
|
||||
@@ -12,6 +12,7 @@ use DateTime;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Result;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
@@ -46,45 +47,60 @@ class ResultTest extends BaseTestCase
|
||||
private $notIterableData;
|
||||
|
||||
/**
|
||||
* Mock of the tested class.
|
||||
* With empty data returned by the LimeSurvey's API.
|
||||
* Status provided instead of real data.
|
||||
* An array with one key: "status".
|
||||
*
|
||||
* @var PHPUnit_Framework_MockObject_MockObject
|
||||
* @var array
|
||||
*/
|
||||
private $emptyDataMock;
|
||||
private $statusInsteadData;
|
||||
|
||||
/**
|
||||
* Result with empty data returned by the LimeSurvey's API.
|
||||
* Mock of the tested class.
|
||||
* With iterable, not empty data.
|
||||
*
|
||||
* @var PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $iterableDataMock;
|
||||
private $emptyDataResult;
|
||||
|
||||
/**
|
||||
* Result with iterable, not empty data.
|
||||
* Mock of the tested class.
|
||||
* With not iterable, not empty data.
|
||||
*
|
||||
* @var PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $notIterableDataMock;
|
||||
private $iterableDataResult;
|
||||
|
||||
/**
|
||||
* Result with not iterable, not empty data.
|
||||
* Mock of the tested class.
|
||||
*
|
||||
* @var PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $notIterableDataResult;
|
||||
|
||||
/**
|
||||
* Result with status provided instead of real data
|
||||
*
|
||||
* @var Result
|
||||
*/
|
||||
private $statusInsteadDataResult;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyConstructorVisibilityAndArguments(Result::class, OopVisibilityType::IS_PUBLIC, 2, 2);
|
||||
static::assertConstructorVisibilityAndArguments(Result::class, OopVisibilityType::IS_PUBLIC, 2, 2);
|
||||
}
|
||||
|
||||
public function testIsEmpty()
|
||||
{
|
||||
static::assertTrue($this->emptyDataMock->isEmpty());
|
||||
static::assertFalse($this->iterableDataMock->isEmpty());
|
||||
static::assertTrue($this->emptyDataResult->isEmpty());
|
||||
static::assertFalse($this->iterableDataResult->isEmpty());
|
||||
}
|
||||
|
||||
public function testGetDataUsingProcessedData()
|
||||
{
|
||||
$emptyData = $this->emptyDataMock->getData();
|
||||
$iterableData = $this->iterableDataMock->getData();
|
||||
$notIterableData = $this->notIterableDataMock->getData();
|
||||
$emptyData = $this->emptyDataResult->getData();
|
||||
$iterableData = $this->iterableDataResult->getData();
|
||||
$notIterableData = $this->notIterableDataResult->getData();
|
||||
|
||||
static::assertEmpty($emptyData);
|
||||
static::assertNotEmpty($iterableData);
|
||||
@@ -97,8 +113,8 @@ class ResultTest extends BaseTestCase
|
||||
|
||||
public function testGetDataUsingRawData()
|
||||
{
|
||||
$emptyData = $this->emptyDataMock->getData(true);
|
||||
$iterableData = $this->iterableDataMock->getData(true);
|
||||
$emptyData = $this->emptyDataResult->getData(true);
|
||||
$iterableData = $this->iterableDataResult->getData(true);
|
||||
|
||||
static::assertEmpty($emptyData);
|
||||
static::assertNotEmpty($iterableData);
|
||||
@@ -110,14 +126,34 @@ class ResultTest extends BaseTestCase
|
||||
static::assertEquals($this->iterableData, $iterableData);
|
||||
}
|
||||
|
||||
public function testGetDataUsingProcessedDataWhoCannotBeProcessed()
|
||||
{
|
||||
$this->expectException(CannotProcessDataException::class);
|
||||
$this->statusInsteadDataResult->getData();
|
||||
}
|
||||
|
||||
public function testGetProcessedDataVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(Result::class, 'getProcessedData', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
static::assertMethodVisibilityAndArguments(Result::class, 'getProcessedData', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
}
|
||||
|
||||
public function testGetResultProcessorVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(Result::class, 'getResultProcessor', OopVisibilityType::IS_PRIVATE);
|
||||
static::assertMethodVisibilityAndArguments(Result::class, 'getResultProcessor', OopVisibilityType::IS_PRIVATE);
|
||||
}
|
||||
|
||||
public function testGetStatusWhenIsNotProvided()
|
||||
{
|
||||
$result = new Result(MethodType::ADD_PARTICIPANTS, []);
|
||||
|
||||
static::assertEquals(null, $result->getStatus());
|
||||
static::assertEquals([], $result->getData(true));
|
||||
}
|
||||
|
||||
public function testGetStatusWhenIsProvided()
|
||||
{
|
||||
static::assertEquals($this->statusInsteadData['status'], $this->statusInsteadDataResult->getStatus());
|
||||
static::assertEquals([], $this->statusInsteadDataResult->getData(true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,24 +185,29 @@ class ResultTest extends BaseTestCase
|
||||
],
|
||||
];
|
||||
|
||||
$emptyDataArguments = [
|
||||
$this->statusInsteadData = [
|
||||
'status' => 'Invalid data',
|
||||
];
|
||||
|
||||
$emptyData = [
|
||||
MethodType::LIST_SURVEYS,
|
||||
$this->emptyData,
|
||||
];
|
||||
|
||||
$iterableDataArguments = [
|
||||
$iterableData = [
|
||||
MethodType::LIST_SURVEYS,
|
||||
$this->iterableData,
|
||||
];
|
||||
|
||||
$notIterableDataArguments = [
|
||||
$notIterableData = [
|
||||
MethodType::GET_PARTICIPANT_PROPERTIES,
|
||||
$this->notIterableData,
|
||||
];
|
||||
|
||||
$this->emptyDataMock = $this->getResultMock($emptyDataArguments);
|
||||
$this->iterableDataMock = $this->getResultMock($iterableDataArguments);
|
||||
$this->notIterableDataMock = $this->getResultMock($notIterableDataArguments);
|
||||
$this->emptyDataResult = $this->getResultMock($emptyData);
|
||||
$this->iterableDataResult = $this->getResultMock($iterableData);
|
||||
$this->notIterableDataResult = $this->getResultMock($notIterableData);
|
||||
$this->statusInsteadDataResult = new Result(MethodType::LIST_PARTICIPANTS, $this->statusInsteadData);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
<?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\Service;
|
||||
|
||||
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\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\Service\ParticipantService;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
|
||||
/**
|
||||
* Test case of the service that serves participants
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantServiceTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Serves participants.
|
||||
* Service without participants.
|
||||
*
|
||||
* @var ParticipantService
|
||||
*/
|
||||
private $serviceWithoutParticipants;
|
||||
|
||||
/**
|
||||
* Serves participants.
|
||||
* Service with participants.
|
||||
*
|
||||
* @var ParticipantService
|
||||
*/
|
||||
private $serviceWithParticipants;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(ParticipantService::class, OopVisibilityType::IS_PUBLIC, 2, 1);
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipantsFromEmptyParticipants()
|
||||
{
|
||||
$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 testHasParticipant()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(3);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertFalse($this->serviceWithoutParticipants->hasParticipant(1, 'john@scott.com'));
|
||||
static::assertFalse($this->serviceWithoutParticipants->hasParticipant(2, 'john@scott.com'));
|
||||
|
||||
static::assertTrue($this->serviceWithParticipants->hasParticipant(1, 'john@scott.com'));
|
||||
static::assertFalse($this->serviceWithParticipants->hasParticipant(2, 'john@scott.com'));
|
||||
static::assertFalse($this->serviceWithParticipants->hasParticipant(3, 'john@scott.com'));
|
||||
}
|
||||
|
||||
public function testAddParticipant()
|
||||
{
|
||||
$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(1, $firstName, $lastName, $email);
|
||||
static::assertInstanceOf(Participant::class, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return ConnectionConfiguration
|
||||
*/
|
||||
private function getConnectionConfiguration()
|
||||
{
|
||||
return new ConnectionConfiguration('http://test.com', 'test', 'test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of session started while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getSessionManager()
|
||||
{
|
||||
return $this->createMock(SessionManager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @param int $runMethodCallCount Count of calls of the runMethod() method (who is mocked)
|
||||
* @param array $runMethodCallResults (optional) Results of calls of the runMethod() method (who is mocked)
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getJsonRpcClientManager($runMethodCallCount, array $runMethodCallResults = [])
|
||||
{
|
||||
$rpcClientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$rpcClientManager
|
||||
->expects(static::exactly($runMethodCallCount))
|
||||
->method('runMethod')
|
||||
->will(static::returnValue($runMethodCallResults));
|
||||
|
||||
return $rpcClientManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ParticipantService($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 Participant())->setValues([
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
]),
|
||||
new Participant(),
|
||||
]),
|
||||
2 => new Collection([
|
||||
new Participant(),
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->serviceWithParticipants = new ParticipantService($client, $allParticipants);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<?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\Service;
|
||||
|
||||
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\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\SessionManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Service\SurveyService;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
|
||||
/**
|
||||
* Test case of the service that serves surveys
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveyServiceTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Serves surveys.
|
||||
* Service without surveys.
|
||||
*
|
||||
* @var SurveyService
|
||||
*/
|
||||
private $serviceWithoutSurveys;
|
||||
|
||||
/**
|
||||
* Serves surveys.
|
||||
* Service with surveys.
|
||||
*
|
||||
* @var SurveyService
|
||||
*/
|
||||
private $serviceWithSurveys;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(SurveyService::class, OopVisibilityType::IS_PUBLIC, 2, 1);
|
||||
}
|
||||
|
||||
public function testGetAllSurveys()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(1);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithSurveys($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertCount(0, $this->serviceWithoutSurveys->getAllSurveys());
|
||||
static::assertCount(2, $this->serviceWithSurveys->getAllSurveys());
|
||||
}
|
||||
|
||||
public function testIsExistingSurvey()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithSurveys($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertFalse($this->serviceWithoutSurveys->isExistingSurvey(1));
|
||||
static::assertFalse($this->serviceWithoutSurveys->isExistingSurvey(2));
|
||||
|
||||
static::assertTrue($this->serviceWithSurveys->isExistingSurvey(1));
|
||||
static::assertTrue($this->serviceWithSurveys->isExistingSurvey(2));
|
||||
static::assertFalse($this->serviceWithSurveys->isExistingSurvey(3));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return ConnectionConfiguration
|
||||
*/
|
||||
private function getConnectionConfiguration()
|
||||
{
|
||||
return new ConnectionConfiguration('http://test.com', 'test', 'test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of session started while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getSessionManager()
|
||||
{
|
||||
return $this->createMock(SessionManager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @param int $runMethodCallCount Count of calls of the runMethod() method (who is mocked)
|
||||
* @param array $runMethodCallResults (optional) Results of calls of the runMethod() method (who is mocked)
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getJsonRpcClientManager($runMethodCallCount, array $runMethodCallResults = [])
|
||||
{
|
||||
$rpcClientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$rpcClientManager
|
||||
->expects(static::exactly($runMethodCallCount))
|
||||
->method('runMethod')
|
||||
->will(static::returnValue($runMethodCallResults));
|
||||
|
||||
return $rpcClientManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service without surveys
|
||||
*
|
||||
* @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 createServiceWithoutSurveys(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
$this->serviceWithoutSurveys = new SurveyService($client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service with surveys
|
||||
*
|
||||
* @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 createServiceWithSurveys(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
|
||||
$allSurveys = new Collection([
|
||||
(new Survey())->setValues([
|
||||
'sid' => 1,
|
||||
'surveyls_title' => 'Test',
|
||||
]),
|
||||
(new Survey())->setValues([
|
||||
'sid' => 2,
|
||||
'surveyls_title' => 'Another Test',
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->serviceWithSurveys = new SurveyService($client, $allSurveys);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTypeTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownMethodException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\SystemMethodType;
|
||||
|
||||
/**
|
||||
* Test case of the type of method used while talking with LimeSurvey's API
|
||||
@@ -21,6 +22,11 @@ use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
*/
|
||||
class MethodTypeTest extends BaseTypeTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(MethodType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $incorrectMethod Type of method to verify
|
||||
* @dataProvider provideIncorrectMethod
|
||||
@@ -83,6 +89,14 @@ class MethodTypeTest extends BaseTypeTestCase
|
||||
yield[
|
||||
MethodType::LIST_SURVEYS,
|
||||
];
|
||||
|
||||
yield[
|
||||
SystemMethodType::GET_SESSION_KEY,
|
||||
];
|
||||
|
||||
yield[
|
||||
SystemMethodType::RELEASE_SESSION_KEY,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,6 +171,7 @@ class MethodTypeTest extends BaseTypeTestCase
|
||||
protected function getAllExpectedTypes()
|
||||
{
|
||||
return [
|
||||
'ADD_PARTICIPANTS' => MethodType::ADD_PARTICIPANTS,
|
||||
'ADD_RESPONSE' => MethodType::ADD_RESPONSE,
|
||||
'EXPORT_STATISTICS' => MethodType::EXPORT_STATISTICS,
|
||||
'GET_PARTICIPANT_PROPERTIES' => MethodType::GET_PARTICIPANT_PROPERTIES,
|
||||
|
||||
@@ -19,6 +19,11 @@ use Meritoo\LimeSurvey\ApiClient\Type\SystemMethodType;
|
||||
*/
|
||||
class SystemMethodTypeTest extends BaseTypeTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(SystemMethodType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user