mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 10:11:49 +01:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5de59f50b | ||
|
|
6e54d39972 | ||
|
|
b3b0e66fb3 | ||
|
|
0fbfc9780d | ||
|
|
92315bd853 | ||
|
|
c3e6935dd8 | ||
|
|
07bc4ab4af | ||
|
|
fd1ec32e1a | ||
|
|
72480ecc27 | ||
|
|
20d7d2f50d | ||
|
|
f5bafdc969 | ||
|
|
0eb6cc85a2 |
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.2",
|
||||
"version": "0.0.7",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Meritoo",
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -59,21 +59,33 @@ 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)
|
||||
->setUsername($username)
|
||||
->setPassword($password)
|
||||
->setDebugMode($debugMode);
|
||||
->setDebugMode($debugMode)
|
||||
->setVerifySslCertificate($verifySslCertificate);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,6 +213,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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,23 @@ use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
*/
|
||||
class ConnectionConfigurationTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Configuration with default values of optional constructor's arguments
|
||||
*
|
||||
* @var ConnectionConfiguration
|
||||
*/
|
||||
private $configurationWithDefaults;
|
||||
|
||||
/**
|
||||
* Configuration without default values of optional constructor's arguments
|
||||
*
|
||||
* @var ConnectionConfiguration
|
||||
*/
|
||||
private $configurationAnother;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 4, 3);
|
||||
static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 5, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,69 +63,92 @@ class ConnectionConfigurationTest extends BaseTestCase
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
static::assertEquals('http://test.com', $this->configurationWithDefaults->getBaseUrl());
|
||||
static::assertEquals('test1', $this->configurationWithDefaults->getUsername());
|
||||
static::assertEquals('test2', $this->configurationWithDefaults->getPassword());
|
||||
static::assertFalse($this->configurationWithDefaults->isDebugModeOn());
|
||||
static::assertTrue($this->configurationWithDefaults->isVerifySslCertificateOn());
|
||||
|
||||
static::assertEquals('http://test.com', $configuration->getBaseUrl());
|
||||
static::assertEquals('test1', $configuration->getUsername());
|
||||
static::assertEquals('test2', $configuration->getPassword());
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
static::assertEquals('http://lets-test.com', $this->configurationAnother->getBaseUrl());
|
||||
static::assertEquals('test11', $this->configurationAnother->getUsername());
|
||||
static::assertEquals('test22', $this->configurationAnother->getPassword());
|
||||
static::assertTrue($this->configurationAnother->isDebugModeOn());
|
||||
static::assertFalse($this->configurationAnother->isVerifySslCertificateOn());
|
||||
}
|
||||
|
||||
public function testSetBaseUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$this->configurationWithDefaults->setBaseUrl('http://lorem.ipsum');
|
||||
static::assertEquals('http://lorem.ipsum', $this->configurationWithDefaults->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->configurationWithDefaults->setBaseUrl('http://lorem.ipsum/');
|
||||
static::assertEquals('http://lorem.ipsum', $this->configurationWithDefaults->getBaseUrl());
|
||||
}
|
||||
|
||||
public function testSetRemoteControlUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setRemoteControlUrl('/lorem/ipsum');
|
||||
|
||||
static::assertEquals('/lorem/ipsum', $configuration->getRemoteControlUrl());
|
||||
$this->configurationWithDefaults->setRemoteControlUrl('/lorem/ipsum');
|
||||
static::assertEquals('/lorem/ipsum', $this->configurationWithDefaults->getRemoteControlUrl());
|
||||
}
|
||||
|
||||
public function testSetUsername()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setUsername('lorem');
|
||||
|
||||
static::assertEquals('lorem', $configuration->getUsername());
|
||||
$this->configurationWithDefaults->setUsername('lorem');
|
||||
static::assertEquals('lorem', $this->configurationWithDefaults->getUsername());
|
||||
}
|
||||
|
||||
public function testSetPassword()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setPassword('ipsum');
|
||||
|
||||
static::assertEquals('ipsum', $configuration->getPassword());
|
||||
$this->configurationWithDefaults->setPassword('ipsum');
|
||||
static::assertEquals('ipsum', $this->configurationWithDefaults->getPassword());
|
||||
}
|
||||
|
||||
public function testSetDebugMode()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$this->configurationWithDefaults->setDebugMode();
|
||||
$this->configurationAnother->setDebugMode();
|
||||
|
||||
$configuration->setDebugMode();
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
static::assertFalse($this->configurationWithDefaults->isDebugModeOn());
|
||||
static::assertFalse($this->configurationAnother->isDebugModeOn());
|
||||
|
||||
$configuration->setDebugMode(false);
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
$this->configurationWithDefaults->setDebugMode(false);
|
||||
$this->configurationAnother->setDebugMode(false);
|
||||
|
||||
$configuration->setDebugMode(true);
|
||||
static::assertTrue($configuration->isDebugModeOn());
|
||||
static::assertFalse($this->configurationWithDefaults->isDebugModeOn());
|
||||
static::assertFalse($this->configurationAnother->isDebugModeOn());
|
||||
|
||||
$this->configurationWithDefaults->setDebugMode(true);
|
||||
$this->configurationAnother->setDebugMode(true);
|
||||
|
||||
static::assertTrue($this->configurationWithDefaults->isDebugModeOn());
|
||||
static::assertTrue($this->configurationAnother->isDebugModeOn());
|
||||
}
|
||||
|
||||
public function testSetVerifySslCertificate()
|
||||
{
|
||||
$this->configurationWithDefaults->setVerifySslCertificate();
|
||||
$this->configurationAnother->setVerifySslCertificate();
|
||||
|
||||
static::assertTrue($this->configurationWithDefaults->isVerifySslCertificateOn());
|
||||
static::assertTrue($this->configurationAnother->isVerifySslCertificateOn());
|
||||
|
||||
$this->configurationWithDefaults->setVerifySslCertificate(false);
|
||||
$this->configurationAnother->setVerifySslCertificate(false);
|
||||
|
||||
static::assertFalse($this->configurationWithDefaults->isVerifySslCertificateOn());
|
||||
static::assertFalse($this->configurationAnother->isVerifySslCertificateOn());
|
||||
|
||||
$this->configurationWithDefaults->setVerifySslCertificate(true);
|
||||
$this->configurationAnother->setVerifySslCertificate(true);
|
||||
|
||||
static::assertTrue($this->configurationWithDefaults->isVerifySslCertificateOn());
|
||||
static::assertTrue($this->configurationAnother->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->configurationWithDefaults->setRemoteControlUrl('lorem/ipsum');
|
||||
static::assertEquals('http://test.com/lorem/ipsum', $this->configurationWithDefaults->getFullUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,4 +186,15 @@ class ConnectionConfigurationTest extends BaseTestCase
|
||||
'htp:/dolor.com',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->configurationWithDefaults = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$this->configurationAnother = new ConnectionConfiguration('http://lets-test.com', 'test11', 'test22', true, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -36,7 +38,7 @@ class JsonRpcClientManagerTest extends BaseTestCase
|
||||
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,6 +85,27 @@ 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()
|
||||
{
|
||||
static::assertMethodVisibilityAndArguments(JsonRpcClientManager::class, 'getRpcClient', OopVisibilityType::IS_PROTECTED);
|
||||
|
||||
@@ -12,6 +12,7 @@ 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;
|
||||
@@ -39,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()
|
||||
|
||||
@@ -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,28 +47,43 @@ 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()
|
||||
{
|
||||
@@ -76,15 +92,15 @@ class ResultTest extends BaseTestCase
|
||||
|
||||
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,6 +126,12 @@ class ResultTest extends BaseTestCase
|
||||
static::assertEquals($this->iterableData, $iterableData);
|
||||
}
|
||||
|
||||
public function testGetDataUsingProcessedDataWhoCannotBeProcessed()
|
||||
{
|
||||
$this->expectException(CannotProcessDataException::class);
|
||||
$this->statusInsteadDataResult->getData();
|
||||
}
|
||||
|
||||
public function testGetProcessedDataVisibilityAndArguments()
|
||||
{
|
||||
static::assertMethodVisibilityAndArguments(Result::class, 'getProcessedData', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
@@ -120,6 +142,20 @@ class ResultTest extends BaseTestCase
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc{
|
||||
*/
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
@@ -88,6 +89,14 @@ class MethodTypeTest extends BaseTypeTestCase
|
||||
yield[
|
||||
MethodType::LIST_SURVEYS,
|
||||
];
|
||||
|
||||
yield[
|
||||
SystemMethodType::GET_SESSION_KEY,
|
||||
];
|
||||
|
||||
yield[
|
||||
SystemMethodType::RELEASE_SESSION_KEY,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user