[WEB-19] Add timeouts

This commit is contained in:
Piotr Marynczak committed 2026-08-14 14:52:17 +02:00
1 parent 7d1cc5384e
commit 33d5581383
25 files changed
+283 -147

No files matched your search

+1
View File
@@ -134,3 +134,4 @@ Icon
Network Trash Folder
Temporary Items
.apdisk
.phpunit.result.cache
+20
View File
@@ -133,6 +133,26 @@ If you want to verify if if the "debug" mode is turned on simply call the `\Meri
$debugMode = $configuration->isDebugModeOn();
```
## Timeouts
By default, this client relies on the underlying `fguillot/json-rpc` HTTP client, which only sets a 5 seconds
connect timeout (`CURLOPT_CONNECTTIMEOUT`) and applies **no limit at all** on the total duration of a request
(there's no `CURLOPT_TIMEOUT`). This means a slow or unresponsive LimeSurvey instance can make a request hang for
a very long time.
You can pass your own connect timeout and request timeout (both in seconds) as the 6th and 7th argument of the
`ConnectionConfiguration` constructor:
```php
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
// connect timeout: 2s, request timeout (including reading the response): 5s
$configuration = new ConnectionConfiguration('http://test.com', 'test', 'test', false, true, 2, 5);
```
If not provided (`null`, the default), the underlying HTTP client's defaults are used - i.e. the behaviour
described above.
## Getting data from result
#### Verify if the result is empty
+7 -8
View File
@@ -1,6 +1,7 @@
{
"name": "wiosna-dev/limesurvey-api-client",
"description": "Client of LimeSurvey API",
"version": "0.2.0",
"type": "library",
"license": "MIT",
"authors": [
@@ -10,18 +11,16 @@
}
],
"require": {
"php": ">=5.6",
"php": ">=8.0",
"fguillot/json-rpc": "^1.2",
"wiosna-dev/common-library": "^0.2.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.6",
"pdepend/pdepend": "^2.5",
"phploc/phploc": "^4.0",
"phpmd/phpmd": "^2.6",
"phpunit/phpunit": "^5.7",
"sebastian/phpcpd": "^3.0",
"squizlabs/php_codesniffer": "^2.9"
"friendsofphp/php-cs-fixer": "^3.0",
"pdepend/pdepend": "^2.16",
"phpmd/phpmd": "^2.15",
"phpunit/phpunit": "^10.0",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": {
+14 -22
View File
@@ -1,4 +1,4 @@
FROM php:5.6-cli
FROM php:8.2-cli
MAINTAINER Meritoo <github@meritoo.pl>
#
@@ -12,6 +12,8 @@ RUN apt-get update \
unzip \
zlib1g-dev \
libicu-dev \
libzip-dev \
libonig-dev \
&& apt-get clean \
&& rm -rf \
/var/lib/apt/lists/* \
@@ -30,10 +32,8 @@ RUN docker-php-ext-install \
# PHP extensions (PECL):
# - Xdebug
#
RUN pecl install \
xdebug-2.5.5 \
&& docker-php-ext-enable \
xdebug
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
@@ -49,12 +49,6 @@ RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
&& printf '[PHP]\ndate.timezone = "%s"\n' ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini \
&& "date"
#
# Phing
#
RUN pear channel-discover pear.phing.info \
&& pear install [--alldeps] phing/phing
#
# Composer - environment variables:
# - disable warning about running commands as root/super user
@@ -66,24 +60,22 @@ RUN pear channel-discover pear.phing.info \
ENV COMPOSER_ALLOW_SUPERUSER 1
#
# Composer + https://packagist.org/packages/hirak/prestissimo package
# Composer (from official image)
#
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === \
'544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo \
'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& php -r "unlink('composer-setup.php');" \
&& composer global require \
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
#
# Phing (via Composer global)
#
RUN composer global require \
--no-plugins \
--no-scripts \
--no-progress \
--no-suggest \
--no-interaction \
--prefer-dist \
--optimize-autoloader \
--classmap-authoritative \
hirak/prestissimo \
phing/phing:^3.0 \
&& rm -rf ~/.composer/cache/* \
&& composer clear-cache \
&& composer --version
@@ -98,6 +90,6 @@ RUN sed -i 's/^# export/export/g; \
#
# Use project-related binaries globally
#
ENV PATH="/project/vendor/bin:${PATH}"
ENV PATH="/project/vendor/bin:/root/.composer/vendor/bin:${PATH}"
WORKDIR /project
+3 -5
View File
@@ -1,6 +1,4 @@
[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_port=9001
xdebug.remote_host=10.254.254.254
xdebug.mode=debug
xdebug.client_port=9001
xdebug.client_host=10.254.254.254
+12 -15
View File
@@ -1,15 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="true"
bootstrap="./vendor/autoload.php"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Meritoo Package - Main Test Suite">
@@ -17,11 +12,11 @@
</testsuite>
</testsuites>
<filter>
<whitelist>
<source>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</include>
</source>
<groups>
<exclude>
@@ -29,7 +24,9 @@
</exclude>
</groups>
<logging>
<log type="coverage-html" target="./.build/logs/phpunit_coverage/html" />
</logging>
<coverage>
<report>
<html outputDirectory="./.build/logs/phpunit_coverage/html"/>
</report>
</coverage>
</phpunit>
+59 -9
View File
@@ -67,26 +67,56 @@ class ConnectionConfiguration
*/
private $verifySslCertificate = true;
/**
* Maximum number of seconds allowed to establish the TCP connection to LimeSurvey's API.
* If null, the underlying HTTP client's default is used.
*
* @var int|null
*/
private $connectTimeout;
/**
* Maximum number of seconds allowed for the whole request, including reading the response.
* If null, no limit is applied (the underlying HTTP client's default behaviour).
*
* @var int|null
*/
private $requestTimeout;
/**
* 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 bool $verifySslCertificate (optional) If is set to true, the SSL certificate verification 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.
* @param int|null $connectTimeout (optional) Maximum number of seconds allowed to establish the TCP
* connection to LimeSurvey's API. If null (default), the underlying HTTP
* client's default is used.
* @param int|null $requestTimeout (optional) Maximum number of seconds allowed for the whole request,
* including reading the response. If null (default), no limit is applied.
* @throws InvalidUrlException
*/
public function __construct($baseUrl, $username, $password, $debugMode = false, $verifySslCertificate = true)
{
public function __construct(
$baseUrl,
$username,
$password,
$debugMode = false,
$verifySslCertificate = true,
$connectTimeout = null,
$requestTimeout = null
) {
$this->setBaseUrl($baseUrl);
$this->username = $username;
$this->password = $password;
$this->debugMode = $debugMode;
$this->verifySslCertificate = $verifySslCertificate;
$this->connectTimeout = $connectTimeout;
$this->requestTimeout = $requestTimeout;
}
/**
@@ -162,6 +192,26 @@ class ConnectionConfiguration
return $this->verifySslCertificate;
}
/**
* Returns the maximum number of seconds allowed to establish the TCP connection to LimeSurvey's API
*
* @return int|null
*/
public function getConnectTimeout()
{
return $this->connectTimeout;
}
/**
* Returns the maximum number of seconds allowed for the whole request, including reading the response
*
* @return int|null
*/
public function getRequestTimeout()
{
return $this->requestTimeout;
}
/**
* Returns full url of the LimeSurvey's API.
* It's a base url with part related to remote control.
+27
View File
@@ -100,6 +100,33 @@ class JsonRpcClientManager
->getHttpClient()
->withoutSslVerification();
}
/*
* A custom connect timeout was requested?
*
* `JsonRPC\HttpClient::withTimeout()` sets `CURLOPT_CONNECTTIMEOUT` (and the equivalent stream
* context option), it does not limit the whole request.
*/
if (null !== $this->connectionConfiguration->getConnectTimeout()) {
$this
->rpcClient
->getHttpClient()
->withTimeout($this->connectionConfiguration->getConnectTimeout());
}
/*
* A custom request timeout was requested?
*
* `JsonRPC\HttpClient` doesn't set `CURLOPT_TIMEOUT` (limit of the whole request, including reading
* the response) at all by default, so without this a slow/unresponsive LimeSurvey instance could hang
* the request for a very long time.
*/
if (null !== $this->connectionConfiguration->getRequestTimeout()) {
$this
->rpcClient
->getHttpClient()
->addOption(CURLOPT_TIMEOUT, $this->connectionConfiguration->getRequestTimeout());
}
}
return $this->rpcClient;
+4 -4
View File
@@ -45,7 +45,7 @@ class ClientTest extends BaseTestCase
*/
public function testRunWithIncorrectMethod($incorrectMethod)
{
$this->setExpectedException(UnknownMethodException::class);
$this->expectException(UnknownMethodException::class);
$client = new Client($this->configuration);
$client->run($incorrectMethod);
@@ -61,8 +61,8 @@ class ClientTest extends BaseTestCase
*/
public function testRun($method, $arguments, $debugMode, $expectedRawData)
{
$sessionManager = $this->getMock(SessionManager::class, [], [], '', false);
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$sessionManager = $this->getMockBuilder(SessionManager::class)->disableOriginalConstructor()->getMock();
$rpcClientManager = $this->getMockBuilder(JsonRpcClientManager::class)->disableOriginalConstructor()->getMock();
$rpcClientManager
->expects(static::any())
@@ -153,7 +153,7 @@ class ClientTest extends BaseTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->configuration = new ConnectionConfiguration('http://test.com', 'test', 'test');
@@ -38,7 +38,7 @@ class ConnectionConfigurationTest extends BaseTestCase
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 5, 3);
static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 7, 3);
}
/**
@@ -47,7 +47,7 @@ class ConnectionConfigurationTest extends BaseTestCase
*/
public function testConstructorWithEmptyBaseUrl($emptyBaseUrl)
{
$this->setExpectedException(InvalidUrlException::class);
$this->expectException(InvalidUrlException::class);
new ConnectionConfiguration($emptyBaseUrl, '', '');
}
@@ -57,7 +57,7 @@ class ConnectionConfigurationTest extends BaseTestCase
*/
public function testConstructorWithInvalidBaseUrl($invalidBaseUrl)
{
$this->setExpectedException(InvalidUrlException::class);
$this->expectException(InvalidUrlException::class);
new ConnectionConfiguration($invalidBaseUrl, '', '');
}
@@ -68,12 +68,16 @@ class ConnectionConfigurationTest extends BaseTestCase
static::assertEquals('test2', $this->configurationWithDefaults->getPassword());
static::assertFalse($this->configurationWithDefaults->isDebugModeOn());
static::assertTrue($this->configurationWithDefaults->isVerifySslCertificateOn());
static::assertNull($this->configurationWithDefaults->getConnectTimeout());
static::assertNull($this->configurationWithDefaults->getRequestTimeout());
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());
static::assertEquals(1, $this->configurationAnother->getConnectTimeout());
static::assertEquals(5, $this->configurationAnother->getRequestTimeout());
}
public function testGetRemoteControlUrl()
@@ -130,11 +134,11 @@ class ConnectionConfigurationTest extends BaseTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->configurationWithDefaults = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
$this->configurationAnother = new ConnectionConfiguration('http://lets-test.com/', 'test11', 'test22', true, false);
$this->configurationAnother = new ConnectionConfiguration('http://lets-test.com/', 'test11', 'test22', true, false, 1, 5);
}
}
+51 -8
View File
@@ -40,14 +40,14 @@ class JsonRpcClientManagerTest extends BaseTestCase
public function testRunMethodWithEmptyArrayReturned()
{
$rpcClient = $this->getMock(RpcClient::class);
$rpcClient = $this->createMock(RpcClient::class);
$manager = $this
->getMockBuilder(JsonRpcClientManager::class)
->setConstructorArgs([
$this->configuration,
])
->setMethods([
->onlyMethods([
'getRpcClient',
])
->getMock();
@@ -68,8 +68,8 @@ class JsonRpcClientManagerTest extends BaseTestCase
public function testRunMethodWithRawDataReturned()
{
$rpcClient = $this->getMock(RpcClient::class);
$manager = $this->getMock(JsonRpcClientManager::class, ['getRpcClient'], [], '', false);
$rpcClient = $this->createMock(RpcClient::class);
$manager = $this->getMockBuilder(JsonRpcClientManager::class)->disableOriginalConstructor()->onlyMethods(['getRpcClient'])->getMock();
$rpcClient
->expects(static::once())
@@ -87,10 +87,10 @@ class JsonRpcClientManagerTest extends BaseTestCase
public function testRunMethodWithException()
{
$this->setExpectedException(InvalidResultOfMethodRunException::class);
$this->expectException(InvalidResultOfMethodRunException::class);
$manager = $this->getMock(JsonRpcClientManager::class, ['getRpcClient'], [], '', false);
$rpcClient = $this->getMock(RpcClient::class);
$manager = $this->getMockBuilder(JsonRpcClientManager::class)->disableOriginalConstructor()->onlyMethods(['getRpcClient'])->getMock();
$rpcClient = $this->createMock(RpcClient::class);
$rpcClient
->expects(self::once())
@@ -111,10 +111,53 @@ class JsonRpcClientManagerTest extends BaseTestCase
static::assertMethodVisibilityAndArguments(JsonRpcClientManager::class, 'getRpcClient', OopVisibilityType::IS_PROTECTED);
}
public function testGetRpcClientWithoutTimeoutsDoesNotTouchHttpClientDefaults()
{
$configuration = new ConnectionConfiguration('http://test.com', 'test', 'test');
$httpClient = $this->getHttpClientOfManager(new JsonRpcClientManager($configuration));
static::assertEquals(5, $this->getHttpClientProperty($httpClient, 'timeout'));
static::assertArrayNotHasKey(CURLOPT_TIMEOUT, $this->getHttpClientProperty($httpClient, 'options'));
}
public function testGetRpcClientAppliesConnectAndRequestTimeout()
{
$configuration = new ConnectionConfiguration('http://test.com', 'test', 'test', false, true, 2, 7);
$httpClient = $this->getHttpClientOfManager(new JsonRpcClientManager($configuration));
static::assertEquals(2, $this->getHttpClientProperty($httpClient, 'timeout'));
static::assertEquals(7, $this->getHttpClientProperty($httpClient, 'options')[CURLOPT_TIMEOUT]);
}
/**
* @param JsonRpcClientManager $manager
* @return \JsonRPC\HttpClient
*/
private function getHttpClientOfManager(JsonRpcClientManager $manager)
{
$method = new \ReflectionMethod($manager, 'getRpcClient');
$method->setAccessible(true);
return $method->invoke($manager)->getHttpClient();
}
/**
* @param object $httpClient
* @param string $propertyName
* @return mixed
*/
private function getHttpClientProperty($httpClient, $propertyName)
{
$property = new \ReflectionProperty($httpClient, $propertyName);
$property->setAccessible(true);
return $property->getValue($httpClient);
}
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->configuration = new ConnectionConfiguration('http://test.com', 'test', 'test');
+8 -6
View File
@@ -29,9 +29,10 @@ class SessionManagerTest extends BaseTestCase
public function testGetSessionKeyWhenFailedWithoutReason()
{
$this->setExpectedException(CreateSessionKeyFailedException::class, 'Create of the session key has failed');
$this->expectException(CreateSessionKeyFailedException::class);
$this->expectExceptionMessage('Create of the session key has failed');
$clientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$clientManager = $this->getMockBuilder(JsonRpcClientManager::class)->disableOriginalConstructor()->getMock();
$clientManager
->expects(static::any())
@@ -46,9 +47,10 @@ class SessionManagerTest extends BaseTestCase
$reason = 'Invalid credentials';
$message = sprintf('Create of the session key has failed. Reason: \'%s\'.', $reason);
$this->setExpectedException(CreateSessionKeyFailedException::class, $message);
$this->expectException(CreateSessionKeyFailedException::class);
$this->expectExceptionMessage($message);
$clientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$clientManager = $this->getMockBuilder(JsonRpcClientManager::class)->disableOriginalConstructor()->getMock();
$clientManager
->expects(static::any())
@@ -62,7 +64,7 @@ class SessionManagerTest extends BaseTestCase
public function testGetSessionKey()
{
$clientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$clientManager = $this->getMockBuilder(JsonRpcClientManager::class)->disableOriginalConstructor()->getMock();
$clientManager
->expects(static::any())
@@ -75,7 +77,7 @@ class SessionManagerTest extends BaseTestCase
public function testReleaseSessionKey()
{
$clientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$clientManager = $this->getMockBuilder(JsonRpcClientManager::class)->disableOriginalConstructor()->getMock();
$clientManager
->expects(static::any())
+4 -4
View File
@@ -52,19 +52,19 @@ class ParticipantsTest extends BaseTestCase
public function testAdd()
{
$this->setExpectedException(DisabledMethodException::class);
$this->expectException(DisabledMethodException::class);
(new Participants())->add('');
}
public function testAddMultiple()
{
$this->setExpectedException(DisabledMethodException::class);
$this->expectException(DisabledMethodException::class);
(new Participants())->addMultiple([]);
}
public function testHas()
{
$this->setExpectedException(DisabledMethodException::class);
$this->expectException(DisabledMethodException::class);
(new Participants())->has(new Participant());
}
@@ -174,7 +174,7 @@ class ParticipantsTest extends BaseTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
@@ -44,19 +44,19 @@ class SurveysSummariesTest extends BaseTestCase
public function testAdd()
{
$this->setExpectedException(DisabledMethodException::class);
$this->expectException(DisabledMethodException::class);
(new SurveysSummaries())->add('');
}
public function testAddMultiple()
{
$this->setExpectedException(DisabledMethodException::class);
$this->expectException(DisabledMethodException::class);
(new SurveysSummaries())->addMultiple([]);
}
public function testHas()
{
$this->setExpectedException(DisabledMethodException::class);
$this->expectException(DisabledMethodException::class);
(new SurveysSummaries())->has(new SurveySummary());
}
@@ -143,7 +143,7 @@ class SurveysSummariesTest extends BaseTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->emptySurveysSummaries = new SurveysSummaries();
+1 -1
View File
@@ -81,7 +81,7 @@ class SurveysTest extends BaseTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
+1 -1
View File
@@ -130,7 +130,7 @@ class ParticipantShortTest extends BaseTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->rawData = static::getParticipantsRawData();
+1 -1
View File
@@ -163,7 +163,7 @@ class ParticipantTest extends BaseTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->rawData = static::getParticipantsRawData();
+1 -1
View File
@@ -161,7 +161,7 @@ class QuestionShortTest extends BaseTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->rawData = static::getQuestionsRawData();
+1 -1
View File
@@ -197,7 +197,7 @@ class QuestionTest extends BaseTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->rawData = static::getQuestionsRawData();
+1 -1
View File
@@ -116,7 +116,7 @@ class SurveyTest extends BaseTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->rawData = static::getSurveysRawData();
@@ -82,7 +82,7 @@ class ResultProcessorTest extends BaseTestCase
public function testRunWithUnknownResultClass()
{
$this->setExpectedException(UnknownInstanceOfResultItem::class);
$this->expectException(UnknownInstanceOfResultItem::class);
$rawData = [
'lorem' => 'ipsum',
+6 -6
View File
@@ -15,7 +15,7 @@ use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
use Meritoo\LimeSurvey\ApiClient\Result\Result;
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
/**
* Test case of the result with data fetched while talking to the LimeSurvey's API
@@ -58,7 +58,7 @@ class ResultTest extends BaseTestCase
* Result with empty data returned by the LimeSurvey's API.
* Mock of the tested class.
*
* @var PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
private $emptyDataResult;
@@ -66,7 +66,7 @@ class ResultTest extends BaseTestCase
* Result with iterable, not empty data.
* Mock of the tested class.
*
* @var PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
private $iterableDataResult;
@@ -74,7 +74,7 @@ class ResultTest extends BaseTestCase
* Result with not iterable, not empty data.
* Mock of the tested class.
*
* @var PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
private $notIterableDataResult;
@@ -128,7 +128,7 @@ class ResultTest extends BaseTestCase
public function testGetDataUsingProcessedDataWhoCannotBeProcessed()
{
$this->setExpectedException(CannotProcessDataException::class);
$this->expectException(CannotProcessDataException::class);
$this->statusInsteadDataResult->getData();
}
@@ -159,7 +159,7 @@ class ResultTest extends BaseTestCase
/**
* {@inheritdoc{
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->emptyData = [];
+18 -17
View File
@@ -23,7 +23,7 @@ use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
use Meritoo\LimeSurvey\ApiClient\Service\ParticipantService;
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
/**
* Test case of the service that serves participants
@@ -112,7 +112,8 @@ class ParticipantServiceTest extends BaseTestCase
public function testGetParticipantDetailsWithException()
{
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
$this->setExpectedException(CannotProcessDataException::class, $exception->getMessage());
$this->expectException(CannotProcessDataException::class);
$this->expectExceptionMessage($exception->getMessage());
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
$sessionManager = $this->getSessionManager();
@@ -156,7 +157,7 @@ class ParticipantServiceTest extends BaseTestCase
public function testHasParticipantFilledSurveyWithoutParticipants()
{
$this->setExpectedException(MissingParticipantOfSurveyException::class);
$this->expectException(MissingParticipantOfSurveyException::class);
$rpcClientManager = $this->getJsonRpcClientManager(1);
$sessionManager = $this->getSessionManager();
@@ -176,7 +177,7 @@ class ParticipantServiceTest extends BaseTestCase
public function testHasParticipantFilledSurveyUsingNotExistingParticipant()
{
$this->setExpectedException(MissingParticipantOfSurveyException::class);
$this->expectException(MissingParticipantOfSurveyException::class);
$rpcClientManager = $this->getJsonRpcClientManager(1);
$sessionManager = $this->getSessionManager();
@@ -188,7 +189,7 @@ class ParticipantServiceTest extends BaseTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
@@ -247,11 +248,11 @@ class ParticipantServiceTest extends BaseTestCase
/**
* Returns manager of session started while connecting to LimeSurvey's API
*
* @return PHPUnit_Framework_MockObject_MockObject
* @return MockObject
*/
private function getSessionManager()
{
return $this->getMock(SessionManager::class, [], [], '', false);
return $this->getMockBuilder(SessionManager::class)->disableOriginalConstructor()->getMock();
}
/**
@@ -259,11 +260,11 @@ class ParticipantServiceTest extends BaseTestCase
*
* @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
* @return MockObject
*/
private function getJsonRpcClientManager($runMethodCallCount, array $runMethodCallResults = [])
{
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$rpcClientManager = $this->getMockBuilder(JsonRpcClientManager::class)->disableOriginalConstructor()->getMock();
$mocker = $rpcClientManager
->expects(static::exactly($runMethodCallCount))
@@ -291,11 +292,11 @@ class ParticipantServiceTest extends BaseTestCase
*
* @param int $runMethodCallCount Count of calls of the runMethod() method (who is mocked)
* @param Exception $exception The exception that should be thrown
* @return PHPUnit_Framework_MockObject_MockObject
* @return MockObject
*/
private function getJsonRpcClientManagerWithException($runMethodCallCount, Exception $exception)
{
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$rpcClientManager = $this->getMockBuilder(JsonRpcClientManager::class)->disableOriginalConstructor()->getMock();
$rpcClientManager
->expects(static::exactly($runMethodCallCount))
@@ -308,10 +309,10 @@ class ParticipantServiceTest extends BaseTestCase
/**
* 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
* @param MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
* @param 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)
private function createServiceWithoutParticipants(MockObject $rpcClientManager, MockObject $sessionManager)
{
$configuration = $this->getConnectionConfiguration();
$client = new Client($configuration, $rpcClientManager, $sessionManager);
@@ -321,10 +322,10 @@ class ParticipantServiceTest extends BaseTestCase
/**
* 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
* @param MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
* @param 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)
private function createServiceWithParticipants(MockObject $rpcClientManager, MockObject $sessionManager)
{
$configuration = $this->getConnectionConfiguration();
$client = new Client($configuration, $rpcClientManager, $sessionManager);
+27 -25
View File
@@ -25,7 +25,7 @@ use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
use Meritoo\LimeSurvey\ApiClient\Service\SurveyService;
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
/**
* Test case of the service that serves surveys and participants of surveys
@@ -100,7 +100,7 @@ class SurveyServiceTest extends BaseTestCase
public function testGetAllSurveysWithNoTableException()
{
$this->setExpectedException(CannotProcessDataException::class);
$this->expectException(CannotProcessDataException::class);
$exception = new CannotProcessDataException(ReasonType::NO_TOKEN_TABLE);
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
@@ -224,7 +224,8 @@ class SurveyServiceTest extends BaseTestCase
public function testGetSurveyParticipantsWithNotExistingSurveyException()
{
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
$this->setExpectedException(CannotProcessDataException::class, $exception->getMessage());
$this->expectException(CannotProcessDataException::class);
$this->expectExceptionMessage($exception->getMessage());
$runMethodCallResults = [
[
@@ -312,6 +313,7 @@ class SurveyServiceTest extends BaseTestCase
'incomplete_responses' => '0',
'full_responses' => '0',
],
null,
];
$rpcClientManager = $this->getJsonRpcClientManager(6, $runMethodCallResults);
@@ -330,7 +332,7 @@ class SurveyServiceTest extends BaseTestCase
public function testGetSurveyParticipantsWithNoTableException()
{
$this->setExpectedException(CannotProcessDataException::class);
$this->expectException(CannotProcessDataException::class);
$exception = new CannotProcessDataException(ReasonType::NO_TOKEN_TABLE);
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
@@ -342,7 +344,7 @@ class SurveyServiceTest extends BaseTestCase
public function testGetSurveyParticipantsWithNoParticipantsException()
{
$this->setExpectedException(CannotProcessDataException::class);
$this->expectException(CannotProcessDataException::class);
$exception = new CannotProcessDataException(ReasonType::NO_PARTICIPANTS_FOUND);
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
@@ -354,7 +356,7 @@ class SurveyServiceTest extends BaseTestCase
public function testAddParticipantForNotExistingSurvey()
{
$this->setExpectedException(CannotProcessDataException::class);
$this->expectException(CannotProcessDataException::class);
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
@@ -464,7 +466,7 @@ class SurveyServiceTest extends BaseTestCase
public function testGetSurveyTokenCountWithException()
{
$this->setExpectedException(MissingSurveySummaryException::class);
$this->expectException(MissingSurveySummaryException::class);
$runMethodCallResults = [
null,
@@ -490,11 +492,11 @@ class SurveyServiceTest extends BaseTestCase
/**
* Returns manager of session started while connecting to LimeSurvey's API
*
* @return PHPUnit_Framework_MockObject_MockObject
* @return MockObject
*/
private function getSessionManager()
{
return $this->getMock(SessionManager::class, [], [], '', false);
return $this->getMockBuilder(SessionManager::class)->disableOriginalConstructor()->getMock();
}
/**
@@ -502,11 +504,11 @@ class SurveyServiceTest extends BaseTestCase
*
* @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
* @return MockObject
*/
private function getJsonRpcClientManager($runMethodCallCount, array $runMethodCallResults = [])
{
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$rpcClientManager = $this->getMockBuilder(JsonRpcClientManager::class)->disableOriginalConstructor()->getMock();
$mocker = $rpcClientManager
->expects(static::exactly($runMethodCallCount))
@@ -534,11 +536,11 @@ class SurveyServiceTest extends BaseTestCase
*
* @param int $runMethodCallCount Count of calls of the runMethod() method (who is mocked)
* @param Exception $exception The exception that should be thrown
* @return PHPUnit_Framework_MockObject_MockObject
* @return MockObject
*/
private function getJsonRpcClientManagerWithException($runMethodCallCount, Exception $exception)
{
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$rpcClientManager = $this->getMockBuilder(JsonRpcClientManager::class)->disableOriginalConstructor()->getMock();
$rpcClientManager
->expects(static::exactly($runMethodCallCount))
@@ -551,10 +553,10 @@ class SurveyServiceTest extends BaseTestCase
/**
* 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
* @param MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
* @param 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)
private function createServiceWithoutSurveys(MockObject $rpcClientManager, MockObject $sessionManager)
{
$configuration = $this->getConnectionConfiguration();
$client = new Client($configuration, $rpcClientManager, $sessionManager);
@@ -564,10 +566,10 @@ class SurveyServiceTest extends BaseTestCase
/**
* 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
* @param MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
* @param 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)
private function createServiceWithSurveys(MockObject $rpcClientManager, MockObject $sessionManager)
{
$configuration = $this->getConnectionConfiguration();
$client = new Client($configuration, $rpcClientManager, $sessionManager);
@@ -595,10 +597,10 @@ class SurveyServiceTest extends BaseTestCase
/**
* 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
* @param MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
* @param 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)
private function createServiceWithoutParticipants(MockObject $rpcClientManager, MockObject $sessionManager)
{
$configuration = $this->getConnectionConfiguration();
$client = new Client($configuration, $rpcClientManager, $sessionManager);
@@ -608,10 +610,10 @@ class SurveyServiceTest extends BaseTestCase
/**
* 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
* @param MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
* @param 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)
private function createServiceWithParticipants(MockObject $rpcClientManager, MockObject $sessionManager)
{
$configuration = $this->getConnectionConfiguration();
$client = new Client($configuration, $rpcClientManager, $sessionManager);
+2 -2
View File
@@ -33,7 +33,7 @@ class MethodTypeTest extends BaseTypeTestCase
*/
public function testGetValidatedMethodWithIncorrectMethod($incorrectMethod)
{
$this->setExpectedException(UnknownMethodException::class);
$this->expectException(UnknownMethodException::class);
MethodType::getValidatedMethod($incorrectMethod);
}
@@ -52,7 +52,7 @@ class MethodTypeTest extends BaseTypeTestCase
*/
public function testIsResultIterableWithIncorrectMethod($incorrectMethod)
{
$this->setExpectedException(UnknownMethodException::class);
$this->expectException(UnknownMethodException::class);
MethodType::isResultIterable($incorrectMethod);
}