Tweaked unit tests

This commit is contained in:
Josh Sherman 2014-10-13 21:46:34 -04:00
parent 1cc1595e30
commit ec14621e7c
4 changed files with 4 additions and 162 deletions

View file

@ -92,23 +92,14 @@ class Resource extends Object
} }
// Check auth if flag is explicitly true or is true for the method // Check auth if flag is explicitly true or is true for the method
/*
if ($this->auth === true if ($this->auth === true
|| (isset($this->auth[$method]) && $this->auth[$method])) || (isset($this->auth[$method]) && $this->auth[$method]))
{ {
if (!$this->config['auth'][$_SERVER['__version']]) if (!isset($this->config['oauth2'][$_SERVER['__version']]))
{ {
throw new \Exception('Authentication is not configured properly.', 401); throw new \Exception('Authentication is not configured properly.', 401);
} }
switch ($this->config['auth'][$_SERVER['__version']]['strategy'])
{
default:
throw new \Exception('Invalid authentication strategy.', 401);
break;
} }
}
*/
// Hack together some new globals // Hack together some new globals
if (in_array($method, ['PUT', 'DELETE'])) if (in_array($method, ['PUT', 'DELETE']))

View file

@ -1,38 +0,0 @@
<?php
class AuthTest extends PHPUnit_Framework_TestCase
{
private $auth;
public function setUp()
{
Pickles\Object::$instances = [];
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SERVER_NAME'] = '127.0.0.1';
file_put_contents('/tmp/pickles.php', '<?php
$config = [
"environments" => [
"local" => "127.0.0.1",
"production" => "123.456.789.0",
],
];
');
Pickles\Config::getInstance('/tmp/pickles.php');
$this->auth = new Pickles\Auth();
}
public function testBasic()
{
$this->assertFalse($this->auth->basic());
}
public function testOAuth2()
{
$this->assertFalse($this->auth->oauth2());
}
}

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Resources\v1 namespace Pickles\App\Resources\v1
{ {
class resource extends \Pickles\Resource class resource extends \Pickles\Resource
{ {
@ -63,28 +63,6 @@ namespace Resources\v1
} }
} }
namespace Classes
{
class Auth extends \Pickles\Auth
{
private static $count = 0;
public function basic()
{
self::$count++;
if (self::$count % 2)
{
return false;
}
else
{
return true;
}
}
}
}
namespace namespace
{ {
class ResourceTest extends PHPUnit_Framework_TestCase class ResourceTest extends PHPUnit_Framework_TestCase
@ -235,92 +213,6 @@ namespace
new Pickles\Router(); new Pickles\Router();
} }
public function testBasicAuthBadCredentials()
{
Pickles\Object::$instances = [];
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SERVER_NAME'] = '127.0.0.1';
file_put_contents('/tmp/pickles.php', '<?php
$config = [
"environments" => [
"local" => "127.0.0.1",
"production" => "123.456.789.0",
],
"pickles" => [
"namespace" => "",
"datasource" => "mysql",
"auth" => "basic",
],
"datasources" => [
"mysql" => [
"driver" => "pdo_mysql",
],
],
];
');
Pickles\Config::getInstance('/tmp/pickles.php');
$response = json_encode([
'meta' => [
'status' => 401,
'message' => 'Invalid authentication credentials.',
],
]);
$this->expectOutputString($response);
$_SERVER['REQUEST_METHOD'] = 'DELETE';
$_REQUEST['request'] = 'v1/resource/1';
new Pickles\Router();
}
public function testBasicAuth()
{
Pickles\Object::$instances = [];
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SERVER_NAME'] = '127.0.0.1';
file_put_contents('/tmp/pickles.php', '<?php
$config = [
"environments" => [
"local" => "127.0.0.1",
"production" => "123.456.789.0",
],
"pickles" => [
"namespace" => "",
"datasource" => "mysql",
"auth" => "basic",
],
"datasources" => [
"mysql" => [
"driver" => "pdo_mysql",
],
],
];
');
Pickles\Config::getInstance('/tmp/pickles.php');
$response = json_encode([
'meta' => [
'status' => 405,
'message' => 'Method not allowed.',
],
]);
$this->expectOutputString($response);
$_SERVER['REQUEST_METHOD'] = 'DELETE';
$_REQUEST['request'] = 'v1/resource/1';
new Pickles\Router();
}
public function testMethodNotAllowed() public function testMethodNotAllowed()
{ {
$response = json_encode([ $response = json_encode([

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Resources\v1 namespace Pickles\App\Resources\v1
{ {
class router extends \Pickles\Resource class router extends \Pickles\Resource
{ {
@ -76,9 +76,6 @@ namespace
"local" => "127.0.0.1", "local" => "127.0.0.1",
"production" => "123.456.789.0", "production" => "123.456.789.0",
], ],
"pickles" => [
"namespace" => "",
],
"datasources" => [], "datasources" => [],
]; ];
'); ');