created mocks for testing
This commit is contained in:
@@ -2,12 +2,131 @@
|
||||
namespace BSR\Webservice;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use BSR\Utils\Logger\Logger;
|
||||
use BSR\Utils\Configuration\Configuration;
|
||||
|
||||
class WebserviceTest extends TestCase
|
||||
{
|
||||
private $webservice;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->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 test
|
||||
public function testRunThrowsAUsageExceptionWhenMissingRequiredParamsInRequest()
|
||||
{
|
||||
}
|
||||
|
||||
public function testRunThrowsAUsageExceptionWhenTooManyParamsInRequest()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user