webservice = new MockWebserviceSubclass('1.2.3'); } private function removeLogs() { $logsDir = realpath(dirname(Configuration::get('log.file'))); $files = glob("$logsDir/*"); foreach($files as $file){ if(is_file($file)) unlink($file); } } /** * @see config/configuration.local.php for the mock renderer used * @runInSeparateProcess */ public function testRunSavesTheRequestIntoALogFile() { $this->removeLogs(); $log = Logger::getLastLogs(); $this->assertEquals(Logger::NO_LOG_YET_MSG, $log); $this->webservice->run(false); $response = ob_get_clean(); $log = Logger::getLastLogs(); $this->assertNotEquals(Logger::NO_LOG_YET_MSG, $log); } /** * @see config/configuration.local.php for the mock renderer used * @runInSeparateProcess */ public function testReturnsErrorNoArgumentsWhenNoParamtersInGetPostRequest() { $this->removeLogs(); $log = Logger::getLastLogs(); $this->assertEquals(Logger::NO_LOG_YET_MSG, $log); $_GET = array(); $_POST = array(); $this->webservice->run(false); $response = ob_get_clean(); $responseArray = json_decode($response, true); $this->assertEquals(100, $responseArray['error']['code']); $this->assertEquals('NoArguments', $responseArray['error']['name']); } public function testDoesNotReturnErrorNoArgumentsWhenParamtersInGetRequest() { $this->removeLogs(); $log = Logger::getLastLogs(); $this->assertEquals(Logger::NO_LOG_YET_MSG, $log); $_GET = array('a' => 'a1'); $this->webservice->run(false); $response = ob_get_clean(); $responseArray = json_decode($response, true); $this->assertNotEquals(100, $responseArray['error']['code']); $this->assertNotEquals('NoArguments', $responseArray['error']['name']); } 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); $response = ob_get_clean(); $responseArray = json_decode($response, true); $this->assertEquals(101, $responseArray['error']['code']); $this->assertEquals('MissingMethod', $responseArray['error']['name']); } public function testDoesNotReturnErrorMissingMethodWhenFuncParamInRequest() { $this->removeLogs(); $log = Logger::getLastLogs(); $this->assertEquals(Logger::NO_LOG_YET_MSG, $log); $_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']); } public function testRunThrowsAUsageExceptionWhenFuncParamIsNotCallableOnSubclass() { } public function testRunThrowsAUsageExceptionWhenMissingRequiredParamsInRequest() { } public function testRunThrowsAUsageExceptionWhenTooManyParamsInRequest() { } }