* @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->getMock(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->getMock(RpcClient::class); $manager = $this->getMock(JsonRpcClientManager::class, ['getRpcClient'], [], '', false); $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->setExpectedException(InvalidResultOfMethodRunException::class); $manager = $this->getMock(JsonRpcClientManager::class, ['getRpcClient'], [], '', false); $rpcClient = $this->getMock(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'); } }