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

Commit

Permalink
Merge branch 'feature/expressive-routecollector' into develop
Browse files Browse the repository at this point in the history
Close #584
  • Loading branch information
weierophinney committed Mar 14, 2018
2 parents 889eadd + 5520ab8 commit 35344a4
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 124 deletions.
18 changes: 7 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ All notable changes to this project will be documented in this file, in reverse
`Zend\HttpHandlerRunner\RequestHandlerRunner` instance, using the services
`Zend\Expressive\Application`, `Zend\HttpHandlerRunner\Emitter\EmitterInterface`,
`Zend\Expressive\ServerRequestFactory`, and `Zend\Expressive\ServerRequestErrorResponseGenerator`.
- `RouteMiddlewareFactory`: creates and returns a `Zend\Expressive\Router\PathBasedRoutingMiddleware` instance.
- `ServerRequestFactoryFactory`: creates and returns a `callable` factory for
generating a PSR-7 `ServerRequestInterface` instance; this returned factory is a
dependency for the `Zend\HttpHandlerRunner\RequestHandlerRunner` service.
Expand Down Expand Up @@ -146,7 +145,7 @@ All notable changes to this project will be documented in this file, in reverse

- `Zend\Expressive\MiddlewareFactory`
- `Zend\Stratigility\MiddlewarePipe`; this is the pipeline representing the application.
- `Zend\Expressive\Router\PathBasedRoutingMiddleware`
- `Zend\Expressive\Router\RouteCollector`
- `Zend\HttpHandlerRunner\RequestHandlerRunner`

It removes all "getter" methods (as detailed in the "Removed" section of this
Expand All @@ -169,8 +168,8 @@ All notable changes to this project will be documented in this file, in reverse

- `route(string $path, $middleware, array $methods = null, string $name) : Route`
passes its `$middleware` argument to the `MiddlewareFactory::prepare()`
method, and then all arguments to the composed `PathBasedRoutingMiddleware`
instance's `route()` method.
method, and then all arguments to the composed `RouteCollector` instance's
`route()` method.

As a result of switching to use the `MiddlewareFactory` to prepare
middleware, you may now route to `RequestHandlerInterface` instances as
Expand All @@ -179,8 +178,7 @@ All notable changes to this project will be documented in this file, in reverse
- Each of `get`, `post`, `patch`, `put`, `delete`, and `any` now proxy to
`route()` after marshaling the correct `$methods`.

- `getRoutes() : Route[]` proxies to the composed `PathBasedRoutingMiddleware`
instance.
- `getRoutes() : Route[]` proxies to the composed `RouteCollector` instance.

- `handle(ServerRequestInterface $request) : ResponseInterface` proxies to the
composed `MiddlewarePipe` instance's `handle()` method.
Expand All @@ -200,7 +198,7 @@ All notable changes to this project will be documented in this file, in reverse
- `Zend\Stratigility\ApplicationPipeline`, which should resolve to a
`MiddlewarePipe` instance; use the
`Zend\Expressive\Container\ApplicationPipelineFactory`.
- `Zend\Expressive\Router\PathBasedRoutingMiddleware`
- `Zend\Expressive\Router\RouteCollector`
- `Zend\HttpHandlerRunner\RequestHandlerRunner`

- [#581](https://github.com/zendframework/zend-expressive/pull/581)
Expand Down Expand Up @@ -274,9 +272,7 @@ All notable changes to this project will be documented in this file, in reverse

- [#543](https://github.com/zendframework/zend-expressive/pull/543) removes the
class `Zend\Expressive\Middleware\RouteMiddleware`. Use the
`PathBasedRoutingMiddleware` or `RouteMiddleware` from zend-expressive-router
instead; the factory `Zend\Expressive\Container\RouteMiddlewareFactory` will
return a `PathBasedRoutingMiddleware` instance for you.
`RouteMiddleware` from zend-expressive-router instead.

- [#543](https://github.com/zendframework/zend-expressive/pull/543) removes the
class `Zend\Expressive\Middleware\DispatchMiddleware`. Use the
Expand All @@ -291,7 +287,7 @@ All notable changes to this project will be documented in this file, in reverse
- [#543](https://github.com/zendframework/zend-expressive/pull/543) removes the
following methods from `Zend\Expressive\Application`:

- `pipeRoutingMiddleware()`: use `pipe(\Zend\Expressive\Router\PathBasedRoutingMiddleware::class)` instead.
- `pipeRoutingMiddleware()`: use `pipe(\Zend\Expressive\Router\RouteMiddleware::class)` instead.
- `pipeDispatchMiddleware()`: use `pipe(\Zend\Expressive\Router\DispatchMiddleware::class)` instead.
- `getContainer()`
- `getDefaultDelegate()`: ensure you pipe middleware or a request handler
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"psr/container": "^1.0",
"psr/http-message": "^1.0.1",
"psr/http-server-middleware": "^1.0",
"zendframework/zend-expressive-router": "^3.0.0rc4",
"zendframework/zend-expressive-router": "^3.0.0rc5",
"zendframework/zend-expressive-template": "^2.0.0alpha1",
"zendframework/zend-httphandlerrunner": "^1.0.1",
"zendframework/zend-stratigility": "^3.0.0rc1"
Expand Down
21 changes: 10 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware;
use Zend\Expressive\Router\RouteCollector;
use Zend\HttpHandlerRunner\RequestHandlerRunner;
use Zend\Stratigility\MiddlewarePipeInterface;

Expand All @@ -32,7 +32,7 @@ class Application implements MiddlewareInterface, RequestHandlerInterface
private $pipeline;

/**
* @var PathBasedRoutingMiddleware
* @var RouteCollector
*/
private $routes;

Expand All @@ -44,7 +44,7 @@ class Application implements MiddlewareInterface, RequestHandlerInterface
public function __construct(
MiddlewareFactory $factory,
MiddlewarePipeInterface $pipeline,
PathBasedRoutingMiddleware $routes,
RouteCollector $routes,
RequestHandlerRunner $runner
) {
$this->factory = $factory;
Expand Down
2 changes: 1 addition & 1 deletion src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getDependencies() : array
IMPLICIT_HEAD_MIDDLEWARE => Router\Middleware\ImplicitHeadMiddleware::class,
IMPLICIT_OPTIONS_MIDDLEWARE => Router\Middleware\ImplicitOptionsMiddleware::class,
NOT_FOUND_MIDDLEWARE => Handler\NotFoundHandler::class,
ROUTE_MIDDLEWARE => Router\Middleware\PathBasedRoutingMiddleware::class,
ROUTE_MIDDLEWARE => Router\Middleware\RouteMiddleware::class,
],
'factories' => [
Application::class => Container\ApplicationFactory::class,
Expand Down
6 changes: 3 additions & 3 deletions src/Container/ApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Zend\Expressive\Application;
use Zend\Expressive\ApplicationPipeline;
use Zend\Expressive\MiddlewareFactory;
use Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware;
use Zend\Expressive\Router\RouteCollector;
use Zend\HttpHandlerRunner\RequestHandlerRunner;

/**
Expand All @@ -25,7 +25,7 @@
* - Zend\Expressive\MiddlewareFactory.
* - Zend\Expressive\ApplicationPipeline, which should resolve to a
* Zend\Stratigility\MiddlewarePipeInterface instance.
* - Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware.
* - Zend\Expressive\Router\RouteCollector.
* - Zend\HttpHandler\RequestHandlerRunner.
*/
class ApplicationFactory
Expand All @@ -35,7 +35,7 @@ public function __invoke(ContainerInterface $container) : Application
return new Application(
$container->get(MiddlewareFactory::class),
$container->get(ApplicationPipeline::class),
$container->get(PathBasedRoutingMiddleware::class),
$container->get(RouteCollector::class),
$container->get(RequestHandlerRunner::class)
);
}
Expand Down
6 changes: 3 additions & 3 deletions test/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use TypeError;
use Zend\Expressive\Application;
use Zend\Expressive\MiddlewareFactory;
use Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware as RouteMiddleware;
use Zend\Expressive\Router\Route;
use Zend\Expressive\Router\RouteCollector;
use Zend\HttpHandlerRunner\RequestHandlerRunner;
use Zend\Stratigility\Middleware\PathMiddlewareDecorator;
use Zend\Stratigility\MiddlewarePipe;
Expand All @@ -32,7 +32,7 @@ public function setUp()
{
$this->factory = $this->prophesize(MiddlewareFactory::class);
$this->pipeline = $this->prophesize(MiddlewarePipeInterface::class);
$this->routes = $this->prophesize(RouteMiddleware::class);
$this->routes = $this->prophesize(RouteCollector::class);
$this->runner = $this->prophesize(RequestHandlerRunner::class);

$this->app = new Application(
Expand Down Expand Up @@ -333,7 +333,7 @@ public function testAnyMethodPassesNullForMethodWhenAllArgumentsPresent($middlew
$this->assertSame($route, $this->app->any('/foo', $middleware, 'foo'));
}

public function testGetRoutesProxiesToRouteMiddleware()
public function testGetRoutesProxiesToRouteCollector()
{
$route = $this->prophesize(Route::class)->reveal();
$this->routes->getRoutes()->willReturn([$route]);
Expand Down
93 changes: 9 additions & 84 deletions test/Container/ApplicationConfigInjectionDelegatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
use Zend\Expressive\MiddlewareFactory;
use Zend\Expressive\Router\Middleware\DispatchMiddleware;
use Zend\Expressive\Router\Middleware\MethodNotAllowedMiddleware;
use Zend\Expressive\Router\Middleware\PathBasedRoutingMiddleware;
use Zend\Expressive\Router\Middleware\RouteMiddleware;
use Zend\Expressive\Router\Route;
use Zend\Expressive\Router\RouteCollector;
use Zend\Expressive\Router\RouterInterface;
use Zend\HttpHandlerRunner\RequestHandlerRunner;
use Zend\Stratigility\MiddlewarePipe;
Expand All @@ -46,7 +47,10 @@ class ApplicationConfigInjectionDelegatorTest extends TestCase
/** @var MethodNotAllowedMiddleware|ObjectProphecy */
private $methodNotAllowedMiddleware;

/** @var PathBasedRoutingMiddleware */
/** @var RouteCollector */
private $routeCollector;

/** @var RouteMiddleware */
private $routeMiddleware;

/** @var RouterInterface|ObjectProphecy */
Expand All @@ -56,10 +60,8 @@ public function setUp()
{
$this->container = $this->mockContainerInterface();
$this->router = $this->prophesize(RouterInterface::class);
$this->routeMiddleware = new PathBasedRoutingMiddleware(
$this->router->reveal(),
new Response()
);
$this->routeCollector = new RouteCollector($this->router->reveal());
$this->routeMiddleware = new RouteMiddleware($this->router->reveal());
$this->dispatchMiddleware = $this->prophesize(DispatchMiddleware::class)->reveal();
$this->methodNotAllowedMiddleware = $this->prophesize(MethodNotAllowedMiddleware::class)->reveal();
}
Expand All @@ -73,7 +75,7 @@ public function createApplication()
return new Application(
$factory,
$pipeline,
$this->routeMiddleware,
$this->routeCollector,
$runner
);
}
Expand Down Expand Up @@ -139,63 +141,6 @@ public static function assertPipelineContainsInstanceOf($class, $pipeline, $mess
Assert::assertThat($found, Assert::isTrue(), $message);
}

public static function assertRouteMiddleware(MiddlewareInterface $middleware)
{
if ($middleware instanceof PathBasedRoutingMiddleware) {
Assert::assertInstanceOf(PathBasedRoutingMiddleware::class, $middleware);
return;
}

if (! $middleware instanceof Middleware\LazyLoadingMiddleware) {
Assert::fail('Middleware is not an instance of PathBasedRoutingMiddleware');
}

Assert::assertAttributeSame(
PathBasedRoutingMiddleware::class,
'middlewareName',
$middleware,
'Middleware is not an instance of PathBasedRoutingMiddleware'
);
}

public static function assertDispatchMiddleware(MiddlewareInterface $middleware)
{
if ($middleware instanceof DispatchMiddleware) {
Assert::assertInstanceOf(DispatchMiddleware::class, $middleware);
return;
}

if (! $middleware instanceof Middleware\LazyLoadingMiddleware) {
Assert::fail('Middleware is not an instance of DispatchMiddleware');
}

Assert::assertAttributeSame(
DispatchMiddleware::class,
'middlewareName',
$middleware,
'Middleware is not an instance of DispatchMiddleware'
);
}

public static function assertMethodNotAllowedMiddleware(MiddlewareInterface $middleware)
{
if ($middleware instanceof MethodNotAllowedMiddleware) {
Assert::assertInstanceOf(MethodNotAllowedMiddleware::class, $middleware);
return;
}

if (! $middleware instanceof Middleware\LazyLoadingMiddleware) {
Assert::fail('Middleware is not an instance of MethodNotAllowedMiddleware');
}

Assert::assertAttributeSame(
MethodNotAllowedMiddleware::class,
'middlewareName',
$middleware,
'Middleware is not an instance of MethodNotAllowedMiddleware'
);
}

public function callableMiddlewares()
{
return [
Expand Down Expand Up @@ -416,16 +361,6 @@ public function testInjectRoutesFromConfigWillSkipSpecsThatOmitPath()
],
];
$this->container->has('config')->willReturn(false);
$this->injectServiceInContainer(
$this->container,
PathBasedRoutingMiddleware::class,
$this->routeMiddleware
);
$this->injectServiceInContainer(
$this->container,
DispatchMiddleware::class,
$this->dispatchMiddleware
);

$app = $this->createApplication();

Expand All @@ -447,16 +382,6 @@ public function testInjectRoutesFromConfigWillSkipSpecsThatOmitMiddleware()
],
];
$this->container->has('config')->willReturn(false);
$this->injectServiceInContainer(
$this->container,
PathBasedRoutingMiddleware::class,
$this->routeMiddleware
);
$this->injectServiceInContainer(
$this->container,
DispatchMiddleware::class,
$this->dispatchMiddleware
);

$app = $this->createApplication();

Expand Down
Loading

0 comments on commit 35344a4

Please sign in to comment.