mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 02:11:45 +01:00
composer.json - move tests-related classes to "autoload-dev" section (used for development purposes only and avoid polluting the autoloader in production)
This commit is contained in:
122
tests/Manager/JsonRpcClientManagerTest.php
Normal file
122
tests/Manager/JsonRpcClientManagerTest.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?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\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;
|
||||
|
||||
/**
|
||||
* Test case of the manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class JsonRpcClientManagerTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @var ConnectionConfiguration
|
||||
*/
|
||||
private $configuration;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(JsonRpcClientManager::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
public function testRunMethodWithEmptyArrayReturned()
|
||||
{
|
||||
$rpcClient = $this->createMock(RpcClient::class);
|
||||
|
||||
$manager = $this
|
||||
->getMockBuilder(JsonRpcClientManager::class)
|
||||
->setConstructorArgs([
|
||||
$this->configuration,
|
||||
])
|
||||
->setMethods([
|
||||
'getRpcClient',
|
||||
])
|
||||
->getMock();
|
||||
|
||||
$rpcClient
|
||||
->expects(static::once())
|
||||
->method('execute')
|
||||
->willReturn([]);
|
||||
|
||||
$manager
|
||||
->expects(static::once())
|
||||
->method('getRpcClient')
|
||||
->willReturn($rpcClient);
|
||||
|
||||
/* @var JsonRpcClientManager $manager */
|
||||
static::assertEquals([], $manager->runMethod(MethodType::LIST_SURVEYS));
|
||||
}
|
||||
|
||||
public function testRunMethodWithRawDataReturned()
|
||||
{
|
||||
$rpcClient = $this->createMock(RpcClient::class);
|
||||
$manager = $this->createPartialMock(JsonRpcClientManager::class, ['getRpcClient']);
|
||||
|
||||
$rpcClient
|
||||
->expects(static::once())
|
||||
->method('execute')
|
||||
->willReturn(SurveyTest::getSurveysRawData());
|
||||
|
||||
$manager
|
||||
->expects(static::once())
|
||||
->method('getRpcClient')
|
||||
->willReturn($rpcClient);
|
||||
|
||||
/* @var JsonRpcClientManager $manager */
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->configuration = new ConnectionConfiguration('http://test.com', 'test', 'test');
|
||||
}
|
||||
}
|
||||
89
tests/Manager/SessionManagerTest.php
Normal file
89
tests/Manager/SessionManagerTest.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?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\Manager;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CreateSessionKeyFailedException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\SessionManager;
|
||||
|
||||
/**
|
||||
* Test case of the manager of session started while connecting to LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SessionManagerTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(SessionManager::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
public function testGetSessionKeyWhenFailedWithoutReason()
|
||||
{
|
||||
$this->expectException(CreateSessionKeyFailedException::class);
|
||||
$this->expectExceptionMessage('Create of the session key has failed');
|
||||
|
||||
$clientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$clientManager
|
||||
->expects(static::any())
|
||||
->method('runMethod')
|
||||
->willReturn([]);
|
||||
|
||||
(new SessionManager($clientManager))->getSessionKey('lorem', 'ipsum');
|
||||
}
|
||||
|
||||
public function testGetSessionKeyWhenFailedWithReason()
|
||||
{
|
||||
$reason = 'Invalid credentials';
|
||||
|
||||
$this->expectException(CreateSessionKeyFailedException::class);
|
||||
$this->expectExceptionMessage(sprintf('Create of the session key has failed. Reason: \'%s\'.', $reason));
|
||||
|
||||
$clientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$clientManager
|
||||
->expects(static::any())
|
||||
->method('runMethod')
|
||||
->willReturn([
|
||||
'status' => $reason,
|
||||
]);
|
||||
|
||||
(new SessionManager($clientManager))->getSessionKey('lorem', 'ipsum');
|
||||
}
|
||||
|
||||
public function testGetSessionKey()
|
||||
{
|
||||
$clientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$clientManager
|
||||
->expects(static::any())
|
||||
->method('runMethod')
|
||||
->willReturn('12345');
|
||||
|
||||
$sessionManager = new SessionManager($clientManager);
|
||||
static::assertEquals('12345', $sessionManager->getSessionKey('lorem', 'ipsum'));
|
||||
}
|
||||
|
||||
public function testReleaseSessionKey()
|
||||
{
|
||||
$clientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$clientManager
|
||||
->expects(static::any())
|
||||
->method('runMethod')
|
||||
->willReturn([]);
|
||||
|
||||
$sessionManager = new SessionManager($clientManager);
|
||||
static::assertInstanceOf(SessionManager::class, $sessionManager->releaseSessionKey());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user