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

View File

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

View File

@ -8,12 +8,6 @@ use WellRESTed\Routing\Route\RouteInterface;
/**
* @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 routing
*/

View File

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

View File

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

View File

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