Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix - Property naming inconsistency #261

Merged
merged 3 commits into from
Nov 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/Klein/Klein.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,22 @@ class Klein
*
* @type SplStack
*/
protected $errorCallbacks;
protected $error_callbacks;

/**
* A stack of HTTP error callback callables
*
* @type SplStack
*/
protected $httpErrorCallbacks;
protected $http_error_callbacks;

/**
* A queue of callbacks to call after processing the dispatch loop
* and before the response is sent
*
* @type SplQueue
*/
protected $afterFilterCallbacks;
protected $after_filter_callbacks;


/**
Expand Down Expand Up @@ -219,9 +219,9 @@ public function __construct(
$this->routes = $routes ?: new RouteCollection();
$this->route_factory = $route_factory ?: new RouteFactory();

$this->errorCallbacks = new SplStack();
$this->httpErrorCallbacks = new SplStack();
$this->afterFilterCallbacks = new SplQueue();
$this->error_callbacks = new SplStack();
$this->http_error_callbacks = new SplStack();
$this->after_filter_callbacks = new SplQueue();
}

/**
Expand Down Expand Up @@ -892,7 +892,7 @@ protected function handleRouteCallback(Route $route, RouteCollection $matched, a
*/
public function onError($callback)
{
$this->errorCallbacks->push($callback);
$this->error_callbacks->push($callback);
}

/**
Expand All @@ -907,8 +907,8 @@ protected function error(Exception $err)
$type = get_class($err);
$msg = $err->getMessage();

if (!$this->errorCallbacks->isEmpty()) {
foreach ($this->errorCallbacks as $callback) {
if (!$this->error_callbacks->isEmpty()) {
foreach ($this->error_callbacks as $callback) {
if (is_callable($callback)) {
if (is_string($callback)) {
$callback($this, $msg, $type, $err);
Expand Down Expand Up @@ -944,7 +944,7 @@ protected function error(Exception $err)
*/
public function onHttpError($callback)
{
$this->httpErrorCallbacks->push($callback);
$this->http_error_callbacks->push($callback);
}

/**
Expand All @@ -961,8 +961,8 @@ protected function httpError(HttpExceptionInterface $http_exception, RouteCollec
$this->response->code($http_exception->getCode());
}

if (!$this->httpErrorCallbacks->isEmpty()) {
foreach ($this->httpErrorCallbacks as $callback) {
if (!$this->http_error_callbacks->isEmpty()) {
foreach ($this->http_error_callbacks as $callback) {
if ($callback instanceof Route) {
$this->handleRouteCallback($callback, $matched, $methods_matched);
} elseif (is_callable($callback)) {
Expand Down Expand Up @@ -1003,7 +1003,7 @@ protected function httpError(HttpExceptionInterface $http_exception, RouteCollec
*/
public function afterDispatch($callback)
{
$this->afterFilterCallbacks->enqueue($callback);
$this->after_filter_callbacks->enqueue($callback);
}

/**
Expand All @@ -1014,7 +1014,7 @@ public function afterDispatch($callback)
protected function callAfterDispatchCallbacks()
{
try {
foreach ($this->afterFilterCallbacks as $callback) {
foreach ($this->after_filter_callbacks as $callback) {
if (is_callable($callback)) {
if (is_string($callback)) {
$callback($this);
Expand Down
8 changes: 4 additions & 4 deletions src/Klein/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Klein\Exceptions\ValidationException;

/**
* Validator
* Validator
*/
class Validator
{
Expand Down Expand Up @@ -50,7 +50,7 @@ class Validator
*
* @type boolean
*/
protected static $defaultAdded = false;
protected static $default_added = false;


/**
Expand All @@ -68,7 +68,7 @@ public function __construct($str, $err = null)
$this->str = $str;
$this->err = $err;

if (!static::$defaultAdded) {
if (!static::$default_added) {
static::addDefault();
}
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public static function addDefault()
return preg_match("/^[$chars]++$/i", $str);
};

static::$defaultAdded = true;
static::$default_added = true;
}

/**
Expand Down
96 changes: 48 additions & 48 deletions tests/Klein/Tests/RoutingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,32 +137,32 @@ function ($r, $r, $s, $a) {

public function testDispatchOutput()
{
$expectedOutput = array(
$expected_output = array(
'returned1' => 'alright!',
'returned2' => 'woot!',
);

$this->klein_app->respond(
function () use ($expectedOutput) {
return $expectedOutput['returned1'];
function () use ($expected_output) {
return $expected_output['returned1'];
}
);
$this->klein_app->respond(
function () use ($expectedOutput) {
return $expectedOutput['returned2'];
function () use ($expected_output) {
return $expected_output['returned2'];
}
);

$this->klein_app->dispatch();

// Expect our output to match our ECHO'd output
$this->expectOutputString(
$expectedOutput['returned1'] . $expectedOutput['returned2']
$expected_output['returned1'] . $expected_output['returned2']
);

// Make sure our response body matches the concatenation of what we returned in each callback
$this->assertSame(
$expectedOutput['returned1'] . $expectedOutput['returned2'],
$expected_output['returned1'] . $expected_output['returned2'],
$this->klein_app->response()->body()
);
}
Expand All @@ -187,19 +187,19 @@ function () {

public function testDispatchOutputCaptured()
{
$expectedOutput = array(
$expected_output = array(
'echoed' => 'yup',
'returned' => 'nope',
);

$this->klein_app->respond(
function () use ($expectedOutput) {
echo $expectedOutput['echoed'];
function () use ($expected_output) {
echo $expected_output['echoed'];
}
);
$this->klein_app->respond(
function () use ($expectedOutput) {
return $expectedOutput['returned'];
function () use ($expected_output) {
return $expected_output['returned'];
}
);

Expand All @@ -209,27 +209,27 @@ function () use ($expectedOutput) {
$this->expectOutputString('');

// Make sure our returned output matches what we ECHO'd
$this->assertSame($expectedOutput['echoed'], $output);
$this->assertSame($expected_output['echoed'], $output);

// Make sure our response body matches what we returned
$this->assertSame($expectedOutput['returned'], $this->klein_app->response()->body());
$this->assertSame($expected_output['returned'], $this->klein_app->response()->body());
}

public function testDispatchOutputReplaced()
{
$expectedOutput = array(
$expected_output = array(
'echoed' => 'yup',
'returned' => 'nope',
);

$this->klein_app->respond(
function () use ($expectedOutput) {
echo $expectedOutput['echoed'];
function () use ($expected_output) {
echo $expected_output['echoed'];
}
);
$this->klein_app->respond(
function () use ($expectedOutput) {
return $expectedOutput['returned'];
function () use ($expected_output) {
return $expected_output['returned'];
}
);

Expand All @@ -239,30 +239,30 @@ function () use ($expectedOutput) {
$this->expectOutputString('');

// Make sure our response body matches what we echoed
$this->assertSame($expectedOutput['echoed'], $this->klein_app->response()->body());
$this->assertSame($expected_output['echoed'], $this->klein_app->response()->body());
}

public function testDispatchOutputPrepended()
{
$expectedOutput = array(
$expected_output = array(
'echoed' => 'yup',
'returned' => 'nope',
'echoed2' => 'sure',
);

$this->klein_app->respond(
function () use ($expectedOutput) {
echo $expectedOutput['echoed'];
function () use ($expected_output) {
echo $expected_output['echoed'];
}
);
$this->klein_app->respond(
function () use ($expectedOutput) {
return $expectedOutput['returned'];
function () use ($expected_output) {
return $expected_output['returned'];
}
);
$this->klein_app->respond(
function () use ($expectedOutput) {
echo $expectedOutput['echoed2'];
function () use ($expected_output) {
echo $expected_output['echoed2'];
}
);

Expand All @@ -273,32 +273,32 @@ function () use ($expectedOutput) {

// Make sure our response body matches what we echoed
$this->assertSame(
$expectedOutput['echoed'] . $expectedOutput['echoed2'] . $expectedOutput['returned'],
$expected_output['echoed'] . $expected_output['echoed2'] . $expected_output['returned'],
$this->klein_app->response()->body()
);
}

public function testDispatchOutputAppended()
{
$expectedOutput = array(
$expected_output = array(
'echoed' => 'yup',
'returned' => 'nope',
'echoed2' => 'sure',
);

$this->klein_app->respond(
function () use ($expectedOutput) {
echo $expectedOutput['echoed'];
function () use ($expected_output) {
echo $expected_output['echoed'];
}
);
$this->klein_app->respond(
function () use ($expectedOutput) {
return $expectedOutput['returned'];
function () use ($expected_output) {
return $expected_output['returned'];
}
);
$this->klein_app->respond(
function () use ($expectedOutput) {
echo $expectedOutput['echoed2'];
function () use ($expected_output) {
echo $expected_output['echoed2'];
}
);

Expand All @@ -309,7 +309,7 @@ function () use ($expectedOutput) {

// Make sure our response body matches what we echoed
$this->assertSame(
$expectedOutput['returned'] . $expectedOutput['echoed'] . $expectedOutput['echoed2'],
$expected_output['returned'] . $expected_output['echoed'] . $expected_output['echoed2'],
$this->klein_app->response()->body()
);
}
Expand Down Expand Up @@ -1267,7 +1267,7 @@ function () {

public function test405Routes()
{
$resultArray = array();
$result_array = array();

$this->expectOutputString('_');

Expand All @@ -1292,8 +1292,8 @@ function () {
);
$this->klein_app->respond(
405,
function ($a, $b, $c, $d, $e, $f, $methods) use (&$resultArray) {
$resultArray = $methods;
function ($a, $b, $c, $d, $e, $f, $methods) use (&$result_array) {
$result_array = $methods;
}
);

Expand All @@ -1307,15 +1307,15 @@ function ($a, $b, $c, $d, $e, $f, $methods) use (&$resultArray) {

error_reporting($old_error_val);

$this->assertCount(2, $resultArray);
$this->assertContains('GET', $resultArray);
$this->assertContains('POST', $resultArray);
$this->assertCount(2, $result_array);
$this->assertContains('GET', $result_array);
$this->assertContains('POST', $result_array);
$this->assertSame(405, $this->klein_app->response()->code());
}

public function test405ErrorHandler()
{
$resultArray = array();
$result_array = array();

$this->expectOutputString('_');

Expand All @@ -1339,18 +1339,18 @@ function () {
}
);
$this->klein_app->onHttpError(
function ($code, $klein, $matched, $methods, $exception) use (&$resultArray) {
$resultArray = $methods;
function ($code, $klein, $matched, $methods, $exception) use (&$result_array) {
$result_array = $methods;
}
);

$this->klein_app->dispatch(
MockRequestFactory::create('/sure', 'DELETE')
);

$this->assertCount(2, $resultArray);
$this->assertContains('GET', $resultArray);
$this->assertContains('POST', $resultArray);
$this->assertCount(2, $result_array);
$this->assertContains('GET', $result_array);
$this->assertContains('POST', $result_array);
$this->assertSame(405, $this->klein_app->response()->code());
}

Expand Down