|
|
|
|
@ -45,10 +45,6 @@ class WebserviceTest extends TestCase
|
|
|
|
|
*/
|
|
|
|
|
public function testReturnsErrorNoArgumentsWhenNoParamtersInGetPostRequest()
|
|
|
|
|
{
|
|
|
|
|
$this->removeLogs();
|
|
|
|
|
$log = Logger::getLastLogs();
|
|
|
|
|
$this->assertEquals(Logger::NO_LOG_YET_MSG, $log);
|
|
|
|
|
|
|
|
|
|
$_GET = array(); $_POST = array();
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
@ -60,10 +56,6 @@ class WebserviceTest extends TestCase
|
|
|
|
|
|
|
|
|
|
public function testDoesNotReturnErrorNoArgumentsWhenParamtersInGetRequest()
|
|
|
|
|
{
|
|
|
|
|
$this->removeLogs();
|
|
|
|
|
$log = Logger::getLastLogs();
|
|
|
|
|
$this->assertEquals(Logger::NO_LOG_YET_MSG, $log);
|
|
|
|
|
|
|
|
|
|
$_GET = array('a' => 'a1');
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
@ -75,26 +67,17 @@ class WebserviceTest extends TestCase
|
|
|
|
|
|
|
|
|
|
public function testDoesNotReturnErrorNoArgumentsWhenParamtersInPostRequest()
|
|
|
|
|
{
|
|
|
|
|
$this->removeLogs();
|
|
|
|
|
$log = Logger::getLastLogs();
|
|
|
|
|
$this->assertEquals(Logger::NO_LOG_YET_MSG, $log);
|
|
|
|
|
|
|
|
|
|
$_POST = array('a' => 'a1');
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
$response = ob_get_clean();
|
|
|
|
|
$responseArray = json_decode($response, true);
|
|
|
|
|
var_dump($responseArray);
|
|
|
|
|
$this->assertNotEquals(100, $responseArray['error']['code']);
|
|
|
|
|
$this->assertNotEquals('NoArguments', $responseArray['error']['name']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testReturnsErrorMissingMethodWhenNoFuncParamInRequest()
|
|
|
|
|
{
|
|
|
|
|
$this->removeLogs();
|
|
|
|
|
$log = Logger::getLastLogs();
|
|
|
|
|
$this->assertEquals(Logger::NO_LOG_YET_MSG, $log);
|
|
|
|
|
|
|
|
|
|
$_POST = array('a' => 'a1');
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
@ -106,27 +89,153 @@ class WebserviceTest extends TestCase
|
|
|
|
|
|
|
|
|
|
public function testDoesNotReturnErrorMissingMethodWhenFuncParamInRequest()
|
|
|
|
|
{
|
|
|
|
|
$this->removeLogs();
|
|
|
|
|
$log = Logger::getLastLogs();
|
|
|
|
|
$this->assertEquals(Logger::NO_LOG_YET_MSG, $log);
|
|
|
|
|
$_GET = array('func' => 'someNonExistentMockFunction'); $_POST = array();
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
$response = ob_get_clean();
|
|
|
|
|
$responseArray = json_decode($response, true);
|
|
|
|
|
$this->assertNotEquals(101, $responseArray['error']['code']);
|
|
|
|
|
$this->assertNotEquals('MissingMethod', $responseArray['error']['name']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testReturnsErrorBadMethodWhenMethodNotExistsFuncParamInRequest()
|
|
|
|
|
{
|
|
|
|
|
$_GET = array('func' => 'someNonExistentMockFunction'); $_POST = array();
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
$response = ob_get_clean();
|
|
|
|
|
$responseArray = json_decode($response, true);
|
|
|
|
|
$this->assertEquals(102, $responseArray['error']['code']);
|
|
|
|
|
$this->assertEquals('BadMethod', $responseArray['error']['name']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testReturnsErrorTooFewArgsWhenMethodNeedsMoreParamsInRequest()
|
|
|
|
|
{
|
|
|
|
|
$_GET = array('func' => 'someMockFunction'); $_POST = array();
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
$response = ob_get_clean();
|
|
|
|
|
$responseArray = json_decode($response, true);
|
|
|
|
|
$this->assertEquals(100, $responseArray['error']['code']);
|
|
|
|
|
$this->assertEquals(103, $responseArray['error']['code']);
|
|
|
|
|
$this->assertEquals('TooFewArgs', $responseArray['error']['name']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRunThrowsAUsageExceptionWhenFuncParamIsNotCallableOnSubclass()
|
|
|
|
|
public function testReturnsErrorTooFewArgsWhenMethodNeedsEvenMoreParamsInRequest()
|
|
|
|
|
{
|
|
|
|
|
$_GET = array(
|
|
|
|
|
'func' => 'someMockFunction',
|
|
|
|
|
'wrongParamName' => 'val',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
$response = ob_get_clean();
|
|
|
|
|
$responseArray = json_decode($response, true);
|
|
|
|
|
$this->assertEquals(103, $responseArray['error']['code']);
|
|
|
|
|
$this->assertEquals('TooFewArgs', $responseArray['error']['name']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRunThrowsAUsageExceptionWhenMissingRequiredParamsInRequest()
|
|
|
|
|
public function testReturnsErrorTooManyArgsWhenMethodHasLessParamsThanInRequest()
|
|
|
|
|
{
|
|
|
|
|
$_GET = array(
|
|
|
|
|
'param1' => 'val',
|
|
|
|
|
'param2' => 'val',
|
|
|
|
|
'param3' => 'val',
|
|
|
|
|
'func' => 'someMockFunction',
|
|
|
|
|
'param4' => 'val',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
$response = ob_get_clean();
|
|
|
|
|
$responseArray = json_decode($response, true);
|
|
|
|
|
$this->assertEquals(104, $responseArray['error']['code']);
|
|
|
|
|
$this->assertEquals('TooManyArgs', $responseArray['error']['name']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testWebserviceSubclassMethodParamNamesDontMatterAsLongThatThereIsTheRightCount()
|
|
|
|
|
{
|
|
|
|
|
$_GET = array(
|
|
|
|
|
'func' => 'someMockFunction',
|
|
|
|
|
'wrongParamName' => 'val',
|
|
|
|
|
'wrongParamName2' => 'val',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
$response = ob_get_clean();
|
|
|
|
|
$responseArray = json_decode($response, true);
|
|
|
|
|
$this->assertEquals(true, isset($responseArray['result']));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testReturnsResultIfProvidedAllParameters()
|
|
|
|
|
{
|
|
|
|
|
$_GET = array(
|
|
|
|
|
'func' => 'someMockFunction',
|
|
|
|
|
'anyParamName1' => 'val',
|
|
|
|
|
'anyParamName2' => 'val',
|
|
|
|
|
'anyParamName3' => 'val',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
$response = ob_get_clean();
|
|
|
|
|
$responseArray = json_decode($response, true);
|
|
|
|
|
$this->assertEquals(true, isset($responseArray['result']));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRunThrowsAUsageExceptionWhenTooManyParamsInRequest()
|
|
|
|
|
public function testReturnsResultFormattedAsMethodNameAndReturnValue()
|
|
|
|
|
{
|
|
|
|
|
$_GET = array(
|
|
|
|
|
'func' => 'someMockFunction',
|
|
|
|
|
'anyParamName1' => 'val',
|
|
|
|
|
'anyParamName2' => 'val',
|
|
|
|
|
'anyParamName3' => 'val',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
$response = ob_get_clean();
|
|
|
|
|
$responseArray = json_decode($response, true);
|
|
|
|
|
$this->assertEquals(array(
|
|
|
|
|
'someMockFunction' => 'Some Mock Function Return'
|
|
|
|
|
), $responseArray['result']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testOrderOfParamatersMatchesArrayOrder()
|
|
|
|
|
{
|
|
|
|
|
$_GET = array(
|
|
|
|
|
'func' => 'someOtherMockFunction',
|
|
|
|
|
'anyParamName1' => 'one',
|
|
|
|
|
'anyParamName2' => 'two',
|
|
|
|
|
'anyParamName3' => 'threeOpt',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
$response = ob_get_clean();
|
|
|
|
|
$responseArray = json_decode($response, true);
|
|
|
|
|
$this->assertEquals(array(
|
|
|
|
|
'someOtherMockFunction' => array(
|
|
|
|
|
'one' => 'one',
|
|
|
|
|
'two' => 'two',
|
|
|
|
|
'threeOpt' => 'threeOpt',
|
|
|
|
|
)
|
|
|
|
|
), $responseArray['result']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testOrderOfParamatersMatchesArrayMixedOrder()
|
|
|
|
|
{
|
|
|
|
|
$_GET = array(
|
|
|
|
|
'func' => 'someOtherMockFunction',
|
|
|
|
|
'anyParamName2' => 'two',
|
|
|
|
|
'anyParamName3' => 'threeOpt',
|
|
|
|
|
'anyParamName1' => 'one',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->webservice->run(false);
|
|
|
|
|
$response = ob_get_clean();
|
|
|
|
|
$responseArray = json_decode($response, true);
|
|
|
|
|
$this->assertEquals(array(
|
|
|
|
|
'someOtherMockFunction' => array(
|
|
|
|
|
'one' => 'two',
|
|
|
|
|
'two' => 'threeOpt',
|
|
|
|
|
'threeOpt' => 'one',
|
|
|
|
|
)
|
|
|
|
|
), $responseArray['result']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|