Skip to content

Commit

Permalink
Almost there!
Browse files Browse the repository at this point in the history
  • Loading branch information
Rican7 committed Sep 28, 2013
1 parent 669e939 commit 033cdfa
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
69 changes: 64 additions & 5 deletions tests/Klein/Tests/KleinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Klein\Tests;

use Exception;
use Klein\App;
use Klein\DataCollection\RouteCollection;
use Klein\Exceptions\DispatchHaltedException;
Expand Down Expand Up @@ -178,7 +179,7 @@ public function testGetPathFor()
// Make sure it fails if not prepared
try {
$this->klein_app->getPathFor($test_name);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertTrue($e instanceof OutOfBoundsException);
}

Expand All @@ -190,11 +191,69 @@ public function testGetPathFor()
$this->assertSame($test_path, $returned_path);
}

public function testOnErrorWithStringCallables()
{
$this->klein_app->onError('test_num_args_wrapper');

$this->klein_app->respond(
function ($request, $response, $service) {
throw new Exception('testing');
}
);

$this->assertSame(
'4',
$this->dispatchAndReturnOutput()
);
}

public function testOnErrorWithBadCallables()
{
$this->klein_app->onError('this_function_doesnt_exist');

$this->klein_app->respond(
function ($request, $response, $service) {
throw new Exception('testing');
}
);

$this->assertEmpty($this->klein_app->service()->flashes());

$this->assertSame(
null,
$this->dispatchAndReturnOutput()
);

$this->assertNotEmpty($this->klein_app->service()->flashes());

// Clean up
session_destroy();
}

/**
* @expectedException Klein\Exceptions\UnhandledException
*/
public function testErrorsWithNoCallbacks()
{
$this->klein_app->respond(
function ($request, $response, $service) {
throw new Exception('testing');
}
);

$this->klein_app->dispatch();

$this->assertSame(
500,
$this->klein_app->response()->code()
);
}

public function testSkipThis()
{
try {
$this->klein_app->skipThis();
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertTrue($e instanceof DispatchHaltedException);
$this->assertSame(DispatchHaltedException::SKIP_THIS, $e->getCode());
$this->assertSame(1, $e->getNumberOfSkips());
Expand All @@ -207,7 +266,7 @@ public function testSkipNext()

try {
$this->klein_app->skipNext($number_of_skips);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertTrue($e instanceof DispatchHaltedException);
$this->assertSame(DispatchHaltedException::SKIP_NEXT, $e->getCode());
$this->assertSame($number_of_skips, $e->getNumberOfSkips());
Expand All @@ -218,7 +277,7 @@ public function testSkipRemaining()
{
try {
$this->klein_app->skipRemaining();
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertTrue($e instanceof DispatchHaltedException);
$this->assertSame(DispatchHaltedException::SKIP_REMAINING, $e->getCode());
}
Expand All @@ -236,7 +295,7 @@ function ($a, $b, $c, $d, $klein_app) use ($test_code) {

try {
$this->klein_app->dispatch();
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertTrue($e instanceof DispatchHaltedException);
$this->assertSame(DispatchHaltedException::SKIP_REMAINING, $e->getCode());
}
Expand Down
5 changes: 5 additions & 0 deletions tests/functions-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ function apc_store($key, $value) {
}
}
}

function test_num_args_wrapper($args)
{
echo func_num_args();
}

0 comments on commit 033cdfa

Please sign in to comment.