Skip to content

Commit

Permalink
Added support for PHPUnit 8
Browse files Browse the repository at this point in the history
  • Loading branch information
omoikane committed Feb 13, 2019
1 parent 9e66441 commit 34b7faf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 40 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -15,7 +15,7 @@
"psr/http-message": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"phpunit/phpunit": "^7.0 || ^8.0",
"aura/router": "^3.1",
"php-coveralls/php-coveralls": "^2.1",
"zendframework/zend-diactoros": "^1.7"
Expand Down
32 changes: 16 additions & 16 deletions src/Test/RouterMapAdapterTestCase.php
Expand Up @@ -13,6 +13,11 @@

namespace Lepre\Routing\Test;

use Lepre\Routing\Exception\InvalidParametersException;
use Lepre\Routing\Exception\MethodNotAllowedException;
use Lepre\Routing\Exception\MissingParametersException;
use Lepre\Routing\Exception\ResourceNotFoundException;
use Lepre\Routing\Exception\RouteNotFoundException;
use Lepre\Routing\RouterMap;
use Lepre\Routing\RouterMapAdapterInterface;
use PHPUnit\Framework\TestCase;
Expand All @@ -28,7 +33,7 @@ abstract class RouterMapAdapterTestCase extends TestCase
*/
private $routerMap;

public function setUp()
public function setUp(): void
{
$this->routerMap = new RouterMap($this->createAdapter());
}
Expand All @@ -46,21 +51,19 @@ public function testMatch()
$this->assertEquals(['postId' => 123], $route->getParams());
}

/**
* @expectedException \Lepre\Routing\Exception\ResourceNotFoundException
*/
public function testMatchThrowsResourceNotFoundException()
{
$this->expectException(ResourceNotFoundException::class);

$request = new ServerRequest([], [], '/about', 'GET');

$this->routerMap->match($request);
}

/**
* @expectedException \Lepre\Routing\Exception\MethodNotAllowedException
*/
public function testMatchThrowsMethodNotAllowedException()
{
$this->expectException(MethodNotAllowedException::class);

$this->routerMap->post('/save-post', 'handler');
$request = new ServerRequest([], [], '/save-post', 'GET');

Expand All @@ -76,27 +79,24 @@ public function testGenerateUrl()
$this->assertEquals('/blog/123', $this->routerMap->generateUrl('blog-post', ['postId' => 123]));
}

/**
* @expectedException \Lepre\Routing\Exception\RouteNotFoundException
*/
public function testGenerateUrlThrowsRouteNotFoundException()
{
$this->expectException(RouteNotFoundException::class);

$this->routerMap->generateUrl('undefined');
}

/**
* @expectedException \Lepre\Routing\Exception\MissingParametersException
*/
public function testGenerateUrlThrowsMissingParametersException()
{
$this->expectException(MissingParametersException::class);

$this->markTestIncomplete();
}

/**
* @expectedException \Lepre\Routing\Exception\InvalidParametersException
*/
public function testGenerateUrlThrowsInvalidParametersException()
{
$this->expectException(InvalidParametersException::class);

$this->markTestIncomplete();
}
}
15 changes: 7 additions & 8 deletions tests/RouteTest.php
Expand Up @@ -13,6 +13,7 @@

namespace Lepre\Routing\Tests;

use Lepre\Routing\Exception\UnsupportedMethodException;
use Lepre\Routing\Route;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -71,22 +72,20 @@ public function testAllowedMethodsManipulation()
$this->assertEquals(['POST', 'HEAD'], $route->getAllowedMethods());
}

/**
* @expectedException \Lepre\Routing\Exception\UnsupportedMethodException
* @expectedExceptionMessage The method "UNKNOWN" is not supported.
*/
public function testAllowUnsupportedMethodThrowsException()
{
$this->expectException(UnsupportedMethodException::class);
$this->expectExceptionMessage('The method "UNKNOWN" is not supported.');

$route = new Route('/', 'handler');
$route->allowMethod('UNKNOWN');
}

/**
* @expectedException \Lepre\Routing\Exception\UnsupportedMethodException
* @expectedExceptionMessage The method "UNKNOWN" is not supported.
*/
public function testAllowUnsupportedMethodsThrowsException()
{
$this->expectException(UnsupportedMethodException::class);
$this->expectExceptionMessage('The method "UNKNOWN" is not supported.');

$route = new Route('/', 'handler');
$route->allowMethods(['GET', 'UNKNOWN']);
}
Expand Down
26 changes: 11 additions & 15 deletions tests/RouterCollectionTest.php
Expand Up @@ -34,7 +34,7 @@ final class RouterCollectionTest extends TestCase
*/
private $collection;

public function setUp()
public function setUp(): void
{
$this->collection = new RouterCollection();
}
Expand Down Expand Up @@ -67,12 +67,11 @@ public function testRegisterMultipleRouters()
$this->assertCount(3, $this->collection->getRouters());
}

/**
* @expectedException \Lepre\Routing\Exception\ResourceNotFoundException
* @expectedExceptionMessage The resource was not found
*/
public function testVoidCollectionMatch()
{
$this->expectException(ResourceNotFoundException::class);
$this->expectExceptionMessage('The resource was not found');

/** @var ServerRequestInterface $request */
$request = $this->createMock(ServerRequestInterface::class);

Expand Down Expand Up @@ -179,20 +178,18 @@ public function testRegisterRouterOrder()
$this->assertEquals('/page2.html', $this->collection->generateUrl('route2', ['param1' => 'value1']));
}

/**
* @expectedException \Lepre\Routing\Exception\RouteNotFoundException
* @expectedExceptionMessage Cannot generate URI for route "the route name": route not found
*/
public function testVoidCollectionGenerateUrl()
{
$this->expectException(RouteNotFoundException::class);
$this->expectExceptionMessage('Cannot generate URI for route "the route name": route not found');

$this->collection->generateUrl('the route name');
}

/**
* @expectedException \Lepre\Routing\Exception\MissingParametersException
*/
public function testGenerateUrlHonorMissingParametersException()
{
$this->expectException(MissingParametersException::class);

$router = $this->createMock(RouterInterface::class);
$router->expects($this->once())->method('generateUrl')
->with('routeName')
Expand All @@ -207,11 +204,10 @@ public function testGenerateUrlHonorMissingParametersException()
$this->collection->generateUrl('routeName');
}

/**
* @expectedException \Lepre\Routing\Exception\InvalidParametersException
*/
public function testGenerateUrlHonorInvalidParametersException()
{
$this->expectException(InvalidParametersException::class);

$router = $this->createMock(RouterInterface::class);
$router->expects($this->once())->method('generateUrl')
->with('routeName')
Expand Down

0 comments on commit 34b7faf

Please sign in to comment.