Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge branch 'route-test-coverage' into develop
Browse files Browse the repository at this point in the history
Forward port #19
  • Loading branch information
michaelmoussa committed Oct 24, 2016
2 parents a13c223 + fac8f6b commit 908e910
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
namespace ZendTest\Expressive\Router;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\Expressive\Router\Exception\InvalidArgumentException;
use Zend\Expressive\Router\Route;

/**
* @covers Zend\Expressive\Router\Route
*/
class RouteTest extends TestCase
{
/**
* @var callable
*/
private $noopMiddleware;

public function setUp()
{
$this->noopMiddleware = function ($req, $res, $next) {
Expand Down Expand Up @@ -113,4 +119,61 @@ public function testRouteNameWithGetAndPost()
$route = new Route('/test', $this->noopMiddleware, [ 'GET', 'POST' ]);
$this->assertSame('/test^GET' . Route::HTTP_METHOD_SEPARATOR . 'POST', $route->getName());
}

public function testThrowsExceptionDuringConstructionIfPathIsNotString()
{
$this->setExpectedException(InvalidArgumentException::class, 'Invalid path; must be a string');

new Route(12345, $this->noopMiddleware);
}

public function testThrowsExceptionDuringConstructionOnInvalidMiddleware()
{
$this->setExpectedException(
InvalidArgumentException::class,
'Invalid middleware; must be callable or a service name'
);

new Route('/foo', 12345);
}

public function testThrowsExceptionDuringConstructionOnInvalidHttpMethod()
{
$this->setExpectedException(
InvalidArgumentException::class,
'Invalid HTTP methods; must be an array or ' . Route::class . '::HTTP_METHOD_ANY'
);

new Route('/foo', $this->noopMiddleware, 'FOO');
}

public function testRouteNameIsMutable()
{
$route = new Route('/foo', $this->noopMiddleware, ['GET'], 'foo');
$route->setName('bar');

$this->assertSame('bar', $route->getName());
}

public function invalidHttpMethodsProvider()
{
return [
[[123]],
[[123, 456]],
[['@@@']],
[['@@@', '@@@']],
];
}

/**
* @dataProvider invalidHttpMethodsProvider
*/
public function testThrowsExceptionIfInvalidHttpMethodsAreProvided(array $invalidHttpMethods)
{
$this->setExpectedException(InvalidArgumentException::class, 'One or more HTTP methods were invalid');

$route = new Route('/test', $this->noopMiddleware, $invalidHttpMethods);

$this->assertFalse($route->getAllowedMethods());
}
}

0 comments on commit 908e910

Please sign in to comment.