Refactor route tests

This commit is contained in:
PJ Dietz 2016-05-21 08:45:55 -04:00
parent 929f8ffd97
commit 36bb00dc1a
6 changed files with 23 additions and 182 deletions

View File

@ -7,17 +7,12 @@ use WellRESTed\Routing\Route\PrefixRoute;
use WellRESTed\Routing\Route\RouteInterface; use WellRESTed\Routing\Route\RouteInterface;
/** /**
* @coversDefaultClass WellRESTed\Routing\Route\PrefixRoute * @covers WellRESTed\Routing\Route\PrefixRoute
* @uses WellRESTed\Routing\Route\PrefixRoute
* @uses WellRESTed\Routing\Route\Route
* @group route * @group route
* @group routing * @group routing
*/ */
class PrefixRouteTest extends \PHPUnit_Framework_TestCase class PrefixRouteTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @covers ::__construct
*/
public function testTrimsAsteriskFromEndOfTarget() public function testTrimsAsteriskFromEndOfTarget()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
@ -25,9 +20,6 @@ class PrefixRouteTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("/cats/", $route->getTarget()); $this->assertEquals("/cats/", $route->getTarget());
} }
/**
* @covers ::getType
*/
public function testReturnsPrefixType() public function testReturnsPrefixType()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
@ -35,9 +27,6 @@ class PrefixRouteTest extends \PHPUnit_Framework_TestCase
$this->assertSame(RouteInterface::TYPE_PREFIX, $route->getType()); $this->assertSame(RouteInterface::TYPE_PREFIX, $route->getType());
} }
/**
* @covers ::getPathVariables
*/
public function testReturnsEmptyArrayForPathVariables() public function testReturnsEmptyArrayForPathVariables()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
@ -45,9 +34,6 @@ class PrefixRouteTest extends \PHPUnit_Framework_TestCase
$this->assertSame([], $route->getPathVariables()); $this->assertSame([], $route->getPathVariables());
} }
/**
* @covers ::matchesRequestTarget
*/
public function testMatchesExactRequestTarget() public function testMatchesExactRequestTarget()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
@ -55,9 +41,6 @@ class PrefixRouteTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($route->matchesRequestTarget("/")); $this->assertTrue($route->matchesRequestTarget("/"));
} }
/**
* @covers ::matchesRequestTarget
*/
public function testMatchesRequestTargetWithSamePrefix() public function testMatchesRequestTargetWithSamePrefix()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
@ -65,9 +48,6 @@ class PrefixRouteTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($route->matchesRequestTarget("/cats/")); $this->assertTrue($route->matchesRequestTarget("/cats/"));
} }
/**
* @covers ::matchesRequestTarget
*/
public function testDoesNotMatchNonmatchingRequestTarget() public function testDoesNotMatchNonmatchingRequestTarget()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');

View File

@ -7,9 +7,7 @@ use WellRESTed\Routing\Route\RegexRoute;
use WellRESTed\Routing\Route\RouteInterface; use WellRESTed\Routing\Route\RouteInterface;
/** /**
* @coversDefaultClass WellRESTed\Routing\Route\RegexRoute * @covers WellRESTed\Routing\Route\RegexRoute
* @uses WellRESTed\Routing\Route\RegexRoute
* @uses WellRESTed\Routing\Route\Route
* @group route * @group route
* @group routing * @group routing
*/ */
@ -22,39 +20,27 @@ class RegexRouteTest extends \PHPUnit_Framework_TestCase
$this->methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $this->methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
} }
/**
* @covers ::getType
*/
public function testReturnsPatternType() public function testReturnsPatternType()
{ {
$route = new RegexRoute("/", $this->methodMap->reveal()); $route = new RegexRoute("/", $this->methodMap->reveal());
$this->assertSame(RouteInterface::TYPE_PATTERN, $route->getType()); $this->assertSame(RouteInterface::TYPE_PATTERN, $route->getType());
} }
/** /** @dataProvider matchingRouteProvider */
* @covers ::matchesRequestTarget
* @dataProvider matchingRouteProvider
*/
public function testMatchesTarget($pattern, $path) public function testMatchesTarget($pattern, $path)
{ {
$route = new RegexRoute($pattern, $this->methodMap->reveal()); $route = new RegexRoute($pattern, $this->methodMap->reveal());
$this->assertTrue($route->matchesRequestTarget($path)); $this->assertTrue($route->matchesRequestTarget($path));
} }
/** /** @dataProvider matchingRouteProvider */
* @covers ::matchesRequestTarget
* @dataProvider matchingRouteProvider
*/
public function testMatchesTargetByRegex($pattern, $target) public function testMatchesTargetByRegex($pattern, $target)
{ {
$route = new RegexRoute($pattern, $this->methodMap->reveal()); $route = new RegexRoute($pattern, $this->methodMap->reveal());
$this->assertTrue($route->matchesRequestTarget($target)); $this->assertTrue($route->matchesRequestTarget($target));
} }
/** /** @dataProvider matchingRouteProvider */
* @covers ::getPathVariables
* @dataProvider matchingRouteProvider
*/
public function testExtractsPathVariablesByRegex($pattern, $target, $expectedCaptures) public function testExtractsPathVariablesByRegex($pattern, $target, $expectedCaptures)
{ {
$route = new RegexRoute($pattern, $this->methodMap->reveal()); $route = new RegexRoute($pattern, $this->methodMap->reveal());
@ -79,10 +65,7 @@ class RegexRouteTest extends \PHPUnit_Framework_TestCase
]; ];
} }
/** /** @dataProvider mismatchingRouteProvider */
* @covers ::matchesRequestTarget
* @dataProvider mismatchingRouteProvider
*/
public function testDoesNotMatchNonmatchingTarget($pattern, $path) public function testDoesNotMatchNonmatchingTarget($pattern, $path)
{ {
$route = new RegexRoute($pattern, $this->methodMap->reveal()); $route = new RegexRoute($pattern, $this->methodMap->reveal());
@ -99,9 +82,8 @@ class RegexRouteTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers ::matchesRequestTarget
* @dataProvider invalidRouteProvider * @dataProvider invalidRouteProvider
* @expectedException \RuntimeException * @expectedException \RuntimeException
*/ */
public function testThrowsExceptionOnInvalidPattern($pattern) public function testThrowsExceptionOnInvalidPattern($pattern)
{ {

View File

@ -8,12 +8,6 @@ use WellRESTed\Routing\Route\RouteInterface;
/** /**
* @covers WellRESTed\Routing\Route\RouteFactory * @covers WellRESTed\Routing\Route\RouteFactory
* @uses WellRESTed\Routing\Route\TemplateRoute
* @uses WellRESTed\Routing\Route\RegexRoute
* @uses WellRESTed\Routing\Route\PrefixRoute
* @uses WellRESTed\Routing\Route\StaticRoute
* @uses WellRESTed\Routing\Route\Route
* @uses WellRESTed\Routing\MethodMap
* @group route * @group route
* @group routing * @group routing
*/ */

View File

@ -5,16 +5,12 @@ namespace WellRESTed\Test\Unit\Routing\Route;
use Prophecy\Argument; use Prophecy\Argument;
/** /**
* @coversDefaultClass WellRESTed\Routing\Route\Route * @covers WellRESTed\Routing\Route\Route
* @uses WellRESTed\Routing\Route\Route
* @group route * @group route
* @group routing * @group routing
*/ */
class RouteTest extends \PHPUnit_Framework_TestCase class RouteTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @covers ::__construct
*/
public function testCreatesInstance() public function testCreatesInstance()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
@ -24,9 +20,6 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->assertNotNull($route); $this->assertNotNull($route);
} }
/**
* @covers ::getTarget
*/
public function testReturnsTarget() public function testReturnsTarget()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
@ -36,9 +29,6 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->assertSame("/target", $route->getTarget()); $this->assertSame("/target", $route->getTarget());
} }
/**
* @covers ::getMethodMap
*/
public function testReturnsMethodMap() public function testReturnsMethodMap()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
@ -48,9 +38,6 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->assertSame($methodMap->reveal(), $route->getMethodMap()); $this->assertSame($methodMap->reveal(), $route->getMethodMap());
} }
/**
* @covers ::__invoke
*/
public function testDispatchesMethodMap() public function testDispatchesMethodMap()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');

View File

@ -7,17 +7,12 @@ use WellRESTed\Routing\Route\RouteInterface;
use WellRESTed\Routing\Route\StaticRoute; use WellRESTed\Routing\Route\StaticRoute;
/** /**
* @coversDefaultClass WellRESTed\Routing\Route\StaticRoute * @covers WellRESTed\Routing\Route\StaticRoute
* @uses WellRESTed\Routing\Route\StaticRoute
* @uses WellRESTed\Routing\Route\Route
* @group route * @group route
* @group routing * @group routing
*/ */
class StaticRouteTest extends \PHPUnit_Framework_TestCase class StaticRouteTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @covers ::getType
*/
public function testReturnsStaticType() public function testReturnsStaticType()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
@ -25,9 +20,6 @@ class StaticRouteTest extends \PHPUnit_Framework_TestCase
$this->assertSame(RouteInterface::TYPE_STATIC, $route->getType()); $this->assertSame(RouteInterface::TYPE_STATIC, $route->getType());
} }
/**
* @covers ::matchesRequestTarget
*/
public function testMatchesExactRequestTarget() public function testMatchesExactRequestTarget()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
@ -35,9 +27,6 @@ class StaticRouteTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($route->matchesRequestTarget("/")); $this->assertTrue($route->matchesRequestTarget("/"));
} }
/**
* @covers ::getPathVariables
*/
public function testReturnsEmptyArrayForPathVariables() public function testReturnsEmptyArrayForPathVariables()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
@ -45,9 +34,6 @@ class StaticRouteTest extends \PHPUnit_Framework_TestCase
$this->assertSame([], $route->getPathVariables()); $this->assertSame([], $route->getPathVariables());
} }
/**
* @covers ::matchesRequestTarget
*/
public function testDoesNotMatchNonmatchingRequestTarget() public function testDoesNotMatchNonmatchingRequestTarget()
{ {
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');

View File

@ -7,10 +7,7 @@ use WellRESTed\Routing\Route\RouteInterface;
use WellRESTed\Routing\Route\TemplateRoute; use WellRESTed\Routing\Route\TemplateRoute;
/** /**
* @coversDefaultClass WellRESTed\Routing\Route\TemplateRoute * @covers WellRESTed\Routing\Route\TemplateRoute
* @uses WellRESTed\Routing\Route\TemplateRoute
* @uses WellRESTed\Routing\Route\RegexRoute
* @uses WellRESTed\Routing\Route\Route
* @group route * @group route
* @group routing * @group routing
*/ */
@ -49,9 +46,6 @@ class TemplateRouteTest extends \PHPUnit_Framework_TestCase
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/**
* @covers ::getType
*/
public function testReturnsPatternType() public function testReturnsPatternType()
{ {
$route = new TemplateRoute("/", $this->methodMap->reveal()); $route = new TemplateRoute("/", $this->methodMap->reveal());
@ -61,14 +55,7 @@ class TemplateRouteTest extends \PHPUnit_Framework_TestCase
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Matching // Matching
/** /** @dataProvider nonMatchingTargetProvider */
* @covers ::matchesRequestTarget
* @covers ::matchesStartOfRequestTarget
* @covers ::getMatchingPattern
* @dataProvider nonMatchingTargetProvider
* @param string $template
* @param string $target
*/
public function testFailsToMatchNonMatchingTarget($template, $target) public function testFailsToMatchNonMatchingTarget($template, $target)
{ {
$route = new TemplateRoute($template, $this->methodMap); $route = new TemplateRoute($template, $this->methodMap);
@ -88,29 +75,14 @@ class TemplateRouteTest extends \PHPUnit_Framework_TestCase
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Matching :: Simple Strings // Matching :: Simple Strings
/** /** @dataProvider simpleStringProvider */
* @covers ::matchesRequestTarget
* @covers ::getMatchingPattern
* @covers ::uriVariableReplacementCallback
* @dataProvider simpleStringProvider
* @param string $template
* @param string $target
*/
public function testMatchesSimpleStrings($template, $target) public function testMatchesSimpleStrings($template, $target)
{ {
$route = new TemplateRoute($template, $this->methodMap); $route = new TemplateRoute($template, $this->methodMap);
$this->assertTrue($route->matchesRequestTarget($target)); $this->assertTrue($route->matchesRequestTarget($target));
} }
/** /** @dataProvider simpleStringProvider */
* @covers ::getPathVariables
* @covers ::processMatches
* @covers ::uriVariableReplacementCallback
* @dataProvider simpleStringProvider
* @param string $template
* @param string $target
* @param string[] List of variables that should be extracted
*/
public function testCapturesFromSimpleStrings($template, $target, $variables) public function testCapturesFromSimpleStrings($template, $target, $variables)
{ {
$route = new TemplateRoute($template, $this->methodMap); $route = new TemplateRoute($template, $this->methodMap);
@ -130,31 +102,16 @@ class TemplateRouteTest extends \PHPUnit_Framework_TestCase
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Matching :: Reservered // Matching :: Reserved
/** /** @dataProvider reservedStringProvider */
* @covers ::matchesRequestTarget public function testMatchesReservedStrings($template, $target)
* @covers ::getMatchingPattern
* @covers ::uriVariableReplacementCallback
* @dataProvider reservedStringProvider
* @param string $template
* @param string $target
*/
public function testMatchesReserveredStrings($template, $target)
{ {
$route = new TemplateRoute($template, $this->methodMap); $route = new TemplateRoute($template, $this->methodMap);
$this->assertTrue($route->matchesRequestTarget($target)); $this->assertTrue($route->matchesRequestTarget($target));
} }
/** /** @dataProvider reservedStringProvider */
* @covers ::getPathVariables
* @covers ::processMatches
* @covers ::uriVariableReplacementCallback
* @dataProvider reservedStringProvider
* @param string $template
* @param string $target
* @param string[] List of variables that should be extracted
*/
public function testCapturesFromReservedStrings($template, $target, $variables) public function testCapturesFromReservedStrings($template, $target, $variables)
{ {
$route = new TemplateRoute($template, $this->methodMap); $route = new TemplateRoute($template, $this->methodMap);
@ -174,29 +131,14 @@ class TemplateRouteTest extends \PHPUnit_Framework_TestCase
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Matching :: Label Expansion // Matching :: Label Expansion
/** /** @dataProvider labelWithDotPrefixProvider */
* @covers ::matchesRequestTarget
* @covers ::getMatchingPattern
* @covers ::uriVariableReplacementCallback
* @dataProvider labelWithDotPrefixProvider
* @param string $template
* @param string $target
*/
public function testMatchesLabelWithDotPrefix($template, $target) public function testMatchesLabelWithDotPrefix($template, $target)
{ {
$route = new TemplateRoute($template, $this->methodMap); $route = new TemplateRoute($template, $this->methodMap);
$this->assertTrue($route->matchesRequestTarget($target)); $this->assertTrue($route->matchesRequestTarget($target));
} }
/** /** @dataProvider labelWithDotPrefixProvider */
* @covers ::getPathVariables
* @covers ::processMatches
* @covers ::uriVariableReplacementCallback
* @dataProvider labelWithDotPrefixProvider
* @param string $template
* @param string $target
* @param string[] List of variables that should be extracted
*/
public function testCapturesFromLabelWithDotPrefix($template, $target, $variables) public function testCapturesFromLabelWithDotPrefix($template, $target, $variables)
{ {
$route = new TemplateRoute($template, $this->methodMap); $route = new TemplateRoute($template, $this->methodMap);
@ -216,29 +158,14 @@ class TemplateRouteTest extends \PHPUnit_Framework_TestCase
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Matching :: Path Segments // Matching :: Path Segments
/** /** @dataProvider pathSegmentProvider */
* @covers ::matchesRequestTarget
* @covers ::getMatchingPattern
* @covers ::uriVariableReplacementCallback
* @dataProvider pathSegmentProvider
* @param string $template
* @param string $target
*/
public function testMatchesPathSegments($template, $target) public function testMatchesPathSegments($template, $target)
{ {
$route = new TemplateRoute($template, $this->methodMap); $route = new TemplateRoute($template, $this->methodMap);
$this->assertTrue($route->matchesRequestTarget($target)); $this->assertTrue($route->matchesRequestTarget($target));
} }
/** /** @dataProvider pathSegmentProvider */
* @covers ::getPathVariables
* @covers ::processMatches
* @covers ::uriVariableReplacementCallback
* @dataProvider pathSegmentProvider
* @param string $template
* @param string $target
* @param string[] List of variables that should be extracted
*/
public function testCapturesFromPathSegments($template, $target, $variables) public function testCapturesFromPathSegments($template, $target, $variables)
{ {
$route = new TemplateRoute($template, $this->methodMap); $route = new TemplateRoute($template, $this->methodMap);
@ -258,29 +185,14 @@ class TemplateRouteTest extends \PHPUnit_Framework_TestCase
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Matching :: Explosion // Matching :: Explosion
/** /** @dataProvider pathExplosionProvider */
* @covers ::matchesRequestTarget
* @covers ::getMatchingPattern
* @covers ::uriVariableReplacementCallback
* @dataProvider pathExplosionProvider
* @param string $template
* @param string $target
*/
public function testMatchesExplosion($template, $target) public function testMatchesExplosion($template, $target)
{ {
$route = new TemplateRoute($template, $this->methodMap); $route = new TemplateRoute($template, $this->methodMap);
$this->assertTrue($route->matchesRequestTarget($target)); $this->assertTrue($route->matchesRequestTarget($target));
} }
/** /** @dataProvider pathExplosionProvider */
* @covers ::getPathVariables
* @covers ::processMatches
* @covers ::uriVariableReplacementCallback
* @dataProvider pathExplosionProvider
* @param string $template
* @param string $target
* @param string[] List of variables that should be extracted
*/
public function testCapturesFromExplosion($template, $target, $variables) public function testCapturesFromExplosion($template, $target, $variables)
{ {
$route = new TemplateRoute($template, $this->methodMap); $route = new TemplateRoute($template, $this->methodMap);