webservice tests pass
This commit is contained in:
15
log/log.txt
Normal file
15
log/log.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
(n-a) - [13.10.2018 16:36:29] - 400 NoArguments - 0.41ms - (none)
|
||||
(n-a) - [13.10.2018 16:36:29] - 400 NoArguments - 0.75ms - (none)
|
||||
(n-a) - [13.10.2018 16:36:29] - 400 MissingMethod - 1.06ms - (none)
|
||||
(n-a) - [13.10.2018 16:36:29] - 400 MissingMethod - 0.04ms - (none)
|
||||
(n-a) - [13.10.2018 16:36:29] - 400 MissingMethod - 0.05ms - (none)
|
||||
(n-a) - [13.10.2018 16:36:29] - 400 BadMethod - 0.06ms - someNonExistentMockFunction()
|
||||
(n-a) - [13.10.2018 16:36:29] - 400 BadMethod - 0.06ms - someNonExistentMockFunction()
|
||||
(n-a) - [13.10.2018 16:36:29] - 400 TooFewArgs - 0.25ms - someMockFunction()
|
||||
(n-a) - [13.10.2018 16:36:29] - 400 TooFewArgs - 0.16ms - someMockFunction(val)
|
||||
(n-a) - [13.10.2018 16:36:29] - 400 TooManyArgs - 0.18ms - someMockFunction(val, val, val, val)
|
||||
(n-a) - [13.10.2018 16:36:29] - 200 - 0.03ms - someMockFunction(val, val)
|
||||
(n-a) - [13.10.2018 16:36:29] - 200 - 0.02ms - someMockFunction(val, val, val)
|
||||
(n-a) - [13.10.2018 16:36:29] - 200 - 0.02ms - someMockFunction(val, val, val)
|
||||
(n-a) - [13.10.2018 16:36:29] - 200 - 0.03ms - someOtherMockFunction(one, two, threeOpt)
|
||||
(n-a) - [13.10.2018 16:36:29] - 200 - 0.02ms - someOtherMockFunction(two, threeOpt, one)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -7,4 +7,13 @@ class MockWebserviceSubclass extends Webservice
|
||||
{
|
||||
return 'Some Mock Function Return';
|
||||
}
|
||||
|
||||
public function someOtherMockFunction($one, $two, $threeOpt = null)
|
||||
{
|
||||
return array(
|
||||
'one' => $one,
|
||||
'two' => $two,
|
||||
'threeOpt' => $threeOpt
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 testRunThrowsAUsageExceptionWhenTooManyParamsInRequest()
|
||||
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 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']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user