6 Commits
0.0.4 ... 0.0.7

Author SHA1 Message Date
Meritoo
f5de59f50b Minor refactoring 2017-09-27 22:56:38 +02:00
Meritoo
6e54d39972 ConnectionConfiguration - $verifySslCertificate property - fix setting value by constructor 2017-09-27 22:32:20 +02:00
Meritoo
b3b0e66fb3 ConnectionConfiguration - add $verifySslCertificate property - 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.
2017-09-27 21:32:28 +02:00
Meritoo
0fbfc9780d Remove composer.lock 2017-09-27 21:29:51 +02:00
Meritoo
92315bd853 Minor refactoring 2017-09-27 12:28:51 +02:00
Meritoo
c3e6935dd8 ResultProcessor - fix bug when iterable data with multiple items was returned 2017-09-26 22:18:14 +02:00
8 changed files with 157 additions and 3627 deletions

1
.gitignore vendored
View File

@@ -11,6 +11,7 @@
# ----------------------------------------------------------------------------------------------------------------------
### Composer
# ----------------------------------------------------------------------------------------------------------------------
/composer.lock
/composer.phar
# ----------------------------------------------------------------------------------------------------------------------

View File

@@ -3,7 +3,7 @@
"description": "Client of LimeSurvey API",
"type": "library",
"license": "MIT",
"version": "0.0.4",
"version": "0.0.7",
"authors": [
{
"name": "Meritoo",

3581
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -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)

View File

@@ -85,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();
}
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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()