From 37af085ec541c31b76d00778cf6382a80df0bbd0 Mon Sep 17 00:00:00 2001 From: PJ Dietz Date: Sun, 10 May 2015 11:46:51 -0400 Subject: [PATCH] Pass DispatcherInterface to RouteFactory on construction --- src/Routing/Route/RouteFactory.php | 16 ++++++++++++---- .../unit/Routing/Route/PrefixRouteTest.php | 2 ++ .../tests/unit/Routing/Route/RegexRouteTest.php | 2 ++ .../unit/Routing/Route/RouteFactoryTest.php | 17 +++++++++++++---- test/tests/unit/Routing/Route/RouteTest.php | 1 + .../unit/Routing/Route/StaticRouteTest.php | 2 ++ .../unit/Routing/Route/TemplateRouteTest.php | 2 ++ 7 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/Routing/Route/RouteFactory.php b/src/Routing/Route/RouteFactory.php index bb31b66..1448fe8 100644 --- a/src/Routing/Route/RouteFactory.php +++ b/src/Routing/Route/RouteFactory.php @@ -2,6 +2,7 @@ namespace WellRESTed\Routing\Route; +use WellRESTed\Dispatching\DispatcherInterface; use WellRESTed\Routing\MethodMap; /** @@ -9,6 +10,13 @@ use WellRESTed\Routing\MethodMap; */ class RouteFactory implements RouteFactoryInterface { + private $dispatcher; + + public function __construct(DispatcherInterface $dispatcher) + { + $this->dispatcher = $dispatcher; + } + /** * Creates a route for the given target. * @@ -28,19 +36,19 @@ class RouteFactory implements RouteFactoryInterface // PrefixRoutes end with * if (substr($target, -1) === "*") { - return new PrefixRoute($target, new MethodMap()); + return new PrefixRoute($target, new MethodMap($this->dispatcher)); } // TempalateRoutes contain {variable} if (preg_match(TemplateRoute::URI_TEMPLATE_EXPRESSION_RE, $target)) { - return new TemplateRoute($target, new MethodMap()); + return new TemplateRoute($target, new MethodMap($this->dispatcher)); } // StaticRoute - return new StaticRoute($target, new MethodMap()); + return new StaticRoute($target, new MethodMap($this->dispatcher)); } // Regex - return new RegexRoute($target, new MethodMap()); + return new RegexRoute($target, new MethodMap($this->dispatcher)); } } diff --git a/test/tests/unit/Routing/Route/PrefixRouteTest.php b/test/tests/unit/Routing/Route/PrefixRouteTest.php index e4be49a..6721103 100644 --- a/test/tests/unit/Routing/Route/PrefixRouteTest.php +++ b/test/tests/unit/Routing/Route/PrefixRouteTest.php @@ -10,6 +10,8 @@ use WellRESTed\Routing\Route\RouteInterface; * @coversDefaultClass WellRESTed\Routing\Route\PrefixRoute * @uses WellRESTed\Routing\Route\PrefixRoute * @uses WellRESTed\Routing\Route\Route + * @group route + * @group routing */ class PrefixRouteTest extends \PHPUnit_Framework_TestCase { diff --git a/test/tests/unit/Routing/Route/RegexRouteTest.php b/test/tests/unit/Routing/Route/RegexRouteTest.php index 9576ad3..b8b48b4 100644 --- a/test/tests/unit/Routing/Route/RegexRouteTest.php +++ b/test/tests/unit/Routing/Route/RegexRouteTest.php @@ -10,6 +10,8 @@ use WellRESTed\Routing\Route\RouteInterface; * @coversDefaultClass WellRESTed\Routing\Route\RegexRoute * @uses WellRESTed\Routing\Route\RegexRoute * @uses WellRESTed\Routing\Route\Route + * @group route + * @group routing */ class RegexRouteTest extends \PHPUnit_Framework_TestCase { diff --git a/test/tests/unit/Routing/Route/RouteFactoryTest.php b/test/tests/unit/Routing/Route/RouteFactoryTest.php index 57859bc..40b2fe2 100644 --- a/test/tests/unit/Routing/Route/RouteFactoryTest.php +++ b/test/tests/unit/Routing/Route/RouteFactoryTest.php @@ -14,33 +14,42 @@ use WellRESTed\Routing\Route\RouteInterface; * @uses WellRESTed\Routing\Route\StaticRoute * @uses WellRESTed\Routing\Route\Route * @uses WellRESTed\Routing\MethodMap + * @group route + * @group routing */ class RouteFactoryTest extends \PHPUnit_Framework_TestCase { + private $dispatcher; + + public function setUp() + { + $this->dispatcher = $this->prophesize('WellRESTed\Dispatching\DispatcherInterface'); + } + public function testCreatesStaticRoute() { - $factory = new RouteFactory(); + $factory = new RouteFactory($this->dispatcher->reveal()); $route = $factory->create("/cats/"); $this->assertSame(RouteInterface::TYPE_STATIC, $route->getType()); } public function testCreatesPrefixRoute() { - $factory = new RouteFactory(); + $factory = new RouteFactory($this->dispatcher->reveal()); $route = $factory->create("/cats/*"); $this->assertSame(RouteInterface::TYPE_PREFIX, $route->getType()); } public function testCreatesRegexRoute() { - $factory = new RouteFactory(); + $factory = new RouteFactory($this->dispatcher->reveal()); $route = $factory->create("~/cat/[0-9]+~"); $this->assertSame(RouteInterface::TYPE_PATTERN, $route->getType()); } public function testCreatesTemplateRoute() { - $factory = new RouteFactory(); + $factory = new RouteFactory($this->dispatcher->reveal()); $route = $factory->create("/cat/{id}"); $this->assertSame(RouteInterface::TYPE_PATTERN, $route->getType()); } diff --git a/test/tests/unit/Routing/Route/RouteTest.php b/test/tests/unit/Routing/Route/RouteTest.php index fd988fd..6163b8d 100644 --- a/test/tests/unit/Routing/Route/RouteTest.php +++ b/test/tests/unit/Routing/Route/RouteTest.php @@ -8,6 +8,7 @@ use Prophecy\Argument; * @coversDefaultClass WellRESTed\Routing\Route\Route * @uses WellRESTed\Routing\Route\Route * @group route + * @group routing */ class RouteTest extends \PHPUnit_Framework_TestCase { diff --git a/test/tests/unit/Routing/Route/StaticRouteTest.php b/test/tests/unit/Routing/Route/StaticRouteTest.php index b53533b..bcc647f 100644 --- a/test/tests/unit/Routing/Route/StaticRouteTest.php +++ b/test/tests/unit/Routing/Route/StaticRouteTest.php @@ -10,6 +10,8 @@ use WellRESTed\Routing\Route\StaticRoute; * @coversDefaultClass WellRESTed\Routing\Route\StaticRoute * @uses WellRESTed\Routing\Route\StaticRoute * @uses WellRESTed\Routing\Route\Route + * @group route + * @group routing */ class StaticRouteTest extends \PHPUnit_Framework_TestCase { diff --git a/test/tests/unit/Routing/Route/TemplateRouteTest.php b/test/tests/unit/Routing/Route/TemplateRouteTest.php index 703fcbd..a55f906 100644 --- a/test/tests/unit/Routing/Route/TemplateRouteTest.php +++ b/test/tests/unit/Routing/Route/TemplateRouteTest.php @@ -10,6 +10,8 @@ use WellRESTed\Routing\Route\TemplateRoute; * @covers WellRESTed\Routing\Route\TemplateRoute * @uses WellRESTed\Routing\Route\RegexRoute * @uses WellRESTed\Routing\Route\Route + * @group route + * @group routing */ class TemplateRouteTest extends \PHPUnit_Framework_TestCase {