Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Updated test class for Zepto\Router
Browse files Browse the repository at this point in the history
  • Loading branch information
hassankhan committed Jan 31, 2014
1 parent 3109cc6 commit 21014fb
Showing 1 changed file with 68 additions and 17 deletions.
85 changes: 68 additions & 17 deletions tests/Zepto/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected function tearDown()

/**
* @covers Zepto\Router::get
* @covers Zepto\Router::route()
*/
public function testGet()
{
Expand All @@ -76,6 +77,7 @@ public function testGet()

/**
* @covers Zepto\Router::post
* @covers Zepto\Router::route()
*/
public function testPost()
{
Expand All @@ -92,6 +94,7 @@ public function testPost()

/**
* @covers Zepto\Router::get
* @covers Zepto\Router::route()
* @expectedException Exception
*/
public function testAddingSameRouteTwice()
Expand All @@ -105,20 +108,64 @@ public function testAddingSameRouteTwice()
});
}

/**
* @covers Zepto\Router::route()
*/
public function testRouteWithValidHttpMethod()
{
$this->router->route(new \Zepto\Route('/test', function() {
return 'New test route';
}), Router::METHOD_GET);

$routes = $this->router->routes();

$this->assertArrayHasKey('GET', $routes);
$this->assertArrayHasKey('#^/test/$#', $routes['GET']);
$this->assertInstanceOf('Zepto\Route', $routes['GET']['#^/test/$#']);
}

/**
* @covers Zepto\Router::route()
* @expectedException Exception
*/
public function testRouteWithInvalidHttpMethod()
{
$this->router->route(new \Zepto\Route('/test', function() {
return 'New test route';
}), 'NO_SUCH_METHOD');

$routes = $this->router->routes();

$this->assertArrayNotHasKey('NO_SUCH_METHOD', $routes);
}

/**
* @covers Zepto\Router::match
* @todo Implement testMatch().
*/
public function testMatch()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$this->router->get('/get', function() {
return 'This is a get route';
});

$this->assertInstanceOf('Zepto\Route', $this->router->match('/get/', Router::METHOD_GET));
}

/**
* @covers Zepto\Router::match
*/
public function testMatchFail()
{
$this->router->get('/notget', function() {
return 'This is not a get route';
});

$this->assertNull($this->router->match('/get/', Router::METHOD_GET));
}

/**
* @covers Zepto\Router::run
* @covers Zepto\Router::match
* @covers Zepto\Router::parse_parameters
* @covers Zepto\Router::current_route
* @covers Zepto\Router::current_http_status
Expand All @@ -145,6 +192,7 @@ public function testRun()

/**
* @covers Zepto\Router::run
* @covers Zepto\Router::match
* @covers Zepto\Router::parse_parameters
* @covers Zepto\Router::current_route
* @covers Zepto\Router::current_http_status
Expand Down Expand Up @@ -179,6 +227,7 @@ public function testRunBeforeAddingRoutes()

/**
* @covers Zepto\Router::run
* @covers Zepto\Router::match
* @covers Zepto\Router::not_found
*/
public function testRunWithNotFoundError()
Expand All @@ -201,6 +250,7 @@ public function testRunWithNotFoundError()

/**
* @covers Zepto\Router::run
* @covers Zepto\Router::match
* @covers Zepto\Router::error
*/
public function testRunWithError()
Expand Down Expand Up @@ -247,27 +297,28 @@ public function testRoutes()

/**
* @covers Zepto\Router::error
* @todo Implement testError().
*/
public function testError()
{
// Try adding custom callback
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$this->router->error(function() {
echo '!!!';
});
$this->router->error();

$this->expectOutputString('!!!');

}

/**
* @covers Zepto\Router::not_found
* @todo Implement testNot_found().
*/
public function testNotFound()
{
// Try adding custom callback
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$this->router->not_found(function() {
echo '???';
});
$this->router->not_found();

$this->expectOutputString('???');
}
}

0 comments on commit 21014fb

Please sign in to comment.