You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
4.0 KiB
PHP
133 lines
4.0 KiB
PHP
<?php
|
|
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 testRunThrowsAUsageExceptionWhenMissingRequiredParamsInRequest()
|
|
{
|
|
}
|
|
|
|
public function testRunThrowsAUsageExceptionWhenTooManyParamsInRequest()
|
|
{
|
|
}
|
|
}
|