Skip to content

Commit

Permalink
adds coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
henderjon committed Dec 12, 2014
1 parent 2f33a12 commit b80b68b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/PHPUnit/Controllers/FrontControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ function index($method, $args = []){
}
}

class MockNoMethodController extends \Chevron\Kernel\Dispatcher\AbstractDispatchableController {
function init(){} /* noop */
}

class TestLog extends \Psr\Log\AbstractLogger {
protected $container;
function log($level, $message, array $context = []){
$this->container = "{$level}|{$message}|" . count($context);
}
function getLog(){
return $this->container;
}
}

class FrontControllerTest extends PHPUnit_Framework_TestCase {

function getDiMock(){
Expand Down Expand Up @@ -166,4 +180,31 @@ function test_Exception(){

}

function test_AbstractDispatchableController_logging(){

$di = $this->getDiMock();
$dispatcher = $this->getDispatcherMock();
$router = $this->getRouterMock();
$route = $this->getRouteMock();

$mock = new MockNoMethodController($di, $route);
$logger = new TestLog;
$mock->setLogger($logger);

$dispatcher->method('dispatch')
->willReturn($mock);

$app = new Chevron\Kernel\Controllers\FrontController($di, $dispatcher, $router);
$app->setIndexController("MockIndexController");
$app->setErrorController("MockErrorController");

try{
$result = $app("/bar.html");
}catch(\Exception $e){
$expected = "error|Chevron\\Kernel\\Dispatcher\\ActionNotFoundException|10";
$this->assertEquals($expected, $logger->getLog());
}

}

}

0 comments on commit b80b68b

Please sign in to comment.