From 9c928cfa54b2dddc1575acc244823ff3abd99426 Mon Sep 17 00:00:00 2001 From: Guillermo Dev Date: Sat, 13 Oct 2018 18:37:30 +0200 Subject: [PATCH] webservice tests pass --- log/log.txt | 15 ++ src/Webservice/.WebService.php.swp | Bin 12288 -> 12288 bytes .../.MockWebserviceSubclass.php.swp | Bin 12288 -> 12288 bytes tests/Webservice/.WebserviceTest.php.swp | Bin 16384 -> 24576 bytes tests/Webservice/MockWebserviceSubclass.php | 9 + tests/Webservice/WebserviceTest.php | 157 +++++++++++++++--- 6 files changed, 157 insertions(+), 24 deletions(-) create mode 100644 log/log.txt diff --git a/log/log.txt b/log/log.txt new file mode 100644 index 0000000..f603907 --- /dev/null +++ b/log/log.txt @@ -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) diff --git a/src/Webservice/.WebService.php.swp b/src/Webservice/.WebService.php.swp index 4a0509c2086f1b3ef336ab5293ac6d5390f478a3..c6db1db6d5bdd953d7e7c06d15b7e88f3cde5415 100644 GIT binary patch delta 52 zcmZojXh@JvG6?hZRj|-AU;qLE28QDjhoZYHmNG={WMD|2xKVwh%M?YX4~!EP#W#Oc HwY@IllGPZm_rRx{*hV0Z}>c?`s7fp`-TPY2>+AkF~dBp^=U+pH+?k9V?xzCgXE zHG={YP%p_SN=@}IC{b6iwNp@m@zB(i=R>8-^L0?A^7B$5Qa}bmswlOjv?xy@v8X7q tQUk1^8cY_HiYMh{CM%?s<|UV8=I1FC=jW#Smt>?CO>WZHo@}Up9sqsZL)-uW delta 86 zcmZojXh@JvG6?hZRj|-AU;qLE1_oZCL($#EOBo_}GBBi1JgC0W8 diff --git a/tests/Webservice/.WebserviceTest.php.swp b/tests/Webservice/.WebserviceTest.php.swp index 5a8eca6474a04bfbd9280e273a267019f3964305..f8519d60950aa7daf44250292443651164ca5122 100644 GIT binary patch literal 24576 zcmeI23yd9A8OI0YVX0UHX#rDlY>RWZw%u+YK)STJw7aFT`$%`&O1pJCd+*tMFTFc+ zJ2Q8;1X?N*0i&QMJk_8?Owk0?D37$oNMo=V1Qj$i8VZ695+B5bC;{s4%;V17xevDO z7P>H#{C0NcoO@>G|DD(OoijLp-KtLY;(7BGj*ltI;2* zoy!|yUcpT3g$DU|WSdu-X0{;auCVeWqItR5+%~9ZMf0c_w1qX2Pm5+p*pA)2KD-hB z+egy8Vy@WW2}x3-K%ziR1xn7)+>6gt7A|OUoBGTdpHk00Yi-S}$<0K8M1e$sM1e$s zM1e$sM1e$sM1l9G0#5N1GXU+ACvW9g^F?*Al~eyV?cx__SG zKOlIHe>*uP3M2|73M2|73M2|73M2|73M2|73M2|73M2{~2L<$uqTGdZKTSI5tp5l8 z{~J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5%|bxh+1`rwBb%kji5G6f6waSVrX0C7~|Cl!ADtz=y?3NE#>X- $one, + 'two' => $two, + 'threeOpt' => $threeOpt + ); + } } diff --git a/tests/Webservice/WebserviceTest.php b/tests/Webservice/WebserviceTest.php index 464334e..31cc2fc 100644 --- a/tests/Webservice/WebserviceTest.php +++ b/tests/Webservice/WebserviceTest.php @@ -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']); } }