* @copyright Meritoo.pl */ class ClientTest extends BaseTestCase { /** * Configuration used while connecting to LimeSurvey's API * * @var ConnectionConfiguration */ private $configuration; public function testConstructorVisibilityAndArguments() { static::assertConstructorVisibilityAndArguments(Client::class, OopVisibilityType::IS_PUBLIC, 3, 1); } /** * @param string $incorrectMethod Incorrect name of method to call * @dataProvider provideIncorrectMethod */ public function testRunWithIncorrectMethod($incorrectMethod) { $this->setExpectedException(UnknownMethodException::class); $client = new Client($this->configuration); $client->run($incorrectMethod); } /** * @param string $method Name of method to call * @param array $arguments Arguments of the method to call * @param bool $debugMode If is set to true, the "debug" mode is turned on. Otherwise - turned off. * @param mixed $expectedRawData Expected raw data returned by JsonRpcClient * * @dataProvider provideMethod */ public function testRun($method, $arguments, $debugMode, $expectedRawData) { $sessionManager = $this->getMock(SessionManager::class, [], [], '', false); $rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false); $rpcClientManager ->expects(static::any()) ->method('runMethod') ->willReturn($expectedRawData); $configuration = new ConnectionConfiguration( $this->configuration->getBaseUrl(), $this->configuration->getUsername(), $this->configuration->getPassword(), $debugMode, $this->configuration->isVerifySslCertificateOn() ); $client = new Client($configuration, $rpcClientManager, $sessionManager); static::assertInstanceOf(Result::class, $client->run($method, $arguments)); } public function testGetConfiguration() { $client = new Client($this->configuration); static::assertEquals($this->configuration, $client->getConfiguration()); } public function testGetRpcClientManagerVisibilityAndArguments() { static::assertMethodVisibilityAndArguments(Client::class, 'getRpcClientManager', OopVisibilityType::IS_PRIVATE); } public function testGetSessionManagerVisibilityAndArguments() { static::assertMethodVisibilityAndArguments(Client::class, 'getRpcClientManager', OopVisibilityType::IS_PRIVATE); } /** * Provides incorrect name of method * * @return Generator */ public function provideIncorrectMethod() { yield[ 'lorem', ]; yield[ 'ipsum', ]; yield[ '', ]; } /** * Provides correct name of method * * @return Generator */ public function provideMethod() { yield[ MethodType::GET_PARTICIPANT_PROPERTIES, [], true, [], ]; yield[ MethodType::LIST_SURVEYS, [], false, [], ]; yield[ MethodType::LIST_PARTICIPANTS, [], false, null, ]; /* * todo: Use/Verify other types of methods */ } /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->configuration = new ConnectionConfiguration('http://test.com', 'test', 'test'); } }