Working on tests for the Resource class.

Got a bunch more validation rules to port over.
This commit is contained in:
Josh Sherman 2014-09-28 09:47:54 -04:00
parent 3b8eddc7b5
commit 6c173cdc89
4 changed files with 188 additions and 171 deletions

View file

@ -2,7 +2,7 @@
namespace Resources\v1
{
class resource extends \Pickles\Resource
class router extends \Pickles\Resource
{
}
@ -14,7 +14,14 @@ namespace
{
public function testServerError()
{
$this->expectOutputRegex('/{"status":500,"message":"Undefined index: request"}/');
$response = json_encode([
'meta' => [
'status' => 500,
'message' => 'Undefined index: request',
],
]);
$this->expectOutputString($response);
$_SERVER['REQUEST_METHOD'] = 'GET';
@ -23,22 +30,36 @@ namespace
public function testNotFound()
{
$this->expectOutputRegex('/{"status":404,"message":"Not Found."}/');
$response = json_encode([
'meta' => [
'status' => 404,
'message' => 'Not Found.',
],
]);
$this->expectOutputString($response);
$_SERVER['REQUEST_METHOD'] = 'GET';
$_REQUEST['request'] = 'v1/test';
$_REQUEST['request'] = 'v1/doesnotexist';
new Pickles\Router();
}
// We're just testing that the class can be loaded, not that it will
// work. That logic is off in ResourceTest
public function testFound()
public function testFoundWithUID()
{
$this->expectOutputRegex('/{"status":405,"message":"Method not allowed."}/');
$response = json_encode([
'meta' => [
'status' => 405,
'message' => 'Method not allowed.',
],
]);
$this->expectOutputString($response);
$_SERVER['REQUEST_METHOD'] = 'GET';
$_REQUEST['request'] = 'v1/resource/1';
$_REQUEST['request'] = 'v1/router/1';
new Pickles\Router();
}