diff --git a/CHANGELOG.md b/CHANGELOG.md index 276254d6..4b4303b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -105,6 +105,12 @@ All notable changes to this project will be documented in this file, in reverse ### Changes +- [#440](https://github.com/zendframework/zend-expressive/pull/440) changes the + `Zend\Expressive\Application::__call($method, array $args)` signature; in + previous versions, `$args` did not have a typehint. If you are extending the + class and overriding this method, you will need to update your signature + accordingly. + - [#428](https://github.com/zendframework/zend-expressive/pull/428) updates `Zend\Expressive\Container\ApplicationFactory` to ignore the `zend-expressive.raise_throwables` configuration setting; Stratigility 2.X no diff --git a/doc/book/reference/migration/to-v2.md b/doc/book/reference/migration/to-v2.md index a81fef62..43e0ca7a 100644 --- a/doc/book/reference/migration/to-v2.md +++ b/doc/book/reference/migration/to-v2.md @@ -4,6 +4,7 @@ Expressive 2.0 should not result in many upgrade problems for users. However, starting in this version, we offer a few changes affecting the following that you should be aware of, and potentially update your application to adopt: +- [Signature changes](#signature-changes) - [Removed functionality](#removed-functionality) - [Deprecated functionality](#deprecated-functionality) - [Usage of http-interop middleware](#http-interop) @@ -13,6 +14,15 @@ you should be aware of, and potentially update your application to adopt: - [Programmatic middleware pipelines](#programmatic-middleware-pipelines) - [Implicit handling of `HEAD` and `OPTIONS` requests](#handling-head-and-options-requests) +## Signature changes + +The following signature changes were made that could affect _class extensions_: + +- `Zend\Expressive\Application::__call($method, array $args)`: previously, the + `$args` argument was not typehinted; it now is. If you are extending this + class and overriding that method, you will need to update your method + signature accordingly. + ## Removed functionality The following classes and/or methods were removed for the Expressive 2.0 diff --git a/src/Application.php b/src/Application.php index c9f1b736..e41a50aa 100644 --- a/src/Application.php +++ b/src/Application.php @@ -123,7 +123,7 @@ public function __construct( * @throws Exception\BadMethodCallException if the $method is not in $httpRouteMethods. * @throws Exception\BadMethodCallException if receiving more or less than 2 arguments. */ - public function __call($method, $args) + public function __call($method, array $args) { if (! in_array(strtoupper($method), $this->httpRouteMethods, true)) { throw new Exception\BadMethodCallException('Unsupported method'); diff --git a/src/IsCallableInteropMiddlewareTrait.php b/src/IsCallableInteropMiddlewareTrait.php index 89fb1cad..1d0c4bca 100644 --- a/src/IsCallableInteropMiddlewareTrait.php +++ b/src/IsCallableInteropMiddlewareTrait.php @@ -16,7 +16,7 @@ trait IsCallableInteropMiddlewareTrait /** * Is callable middleware interop middleware? * - * @param callable $middleware + * @param mixed $middleware * @return bool */ private function isCallableInteropMiddleware($middleware) diff --git a/test/Application/ConfigInjectionTest.php b/test/Application/ConfigInjectionTest.php index 9a0fd896..f522b365 100644 --- a/test/Application/ConfigInjectionTest.php +++ b/test/Application/ConfigInjectionTest.php @@ -99,19 +99,19 @@ public static function assertPipelineContainsInstanceOf($class, $pipeline, $mess public function callableMiddlewares() { return [ - ['HelloWorld'], - [ + ['HelloWorld'], + [ function () { }, - ], - [[InvokableMiddleware::class, 'staticallyCallableMiddleware']], + ], + [[InvokableMiddleware::class, 'staticallyCallableMiddleware']], ]; } /** * @dataProvider callableMiddlewares * - * @param callable $middleware + * @param callable|array|string $middleware */ public function testInjectRoutesFromConfigSetsUpRoutesFromConfig($middleware) { @@ -519,7 +519,7 @@ public function testInjectPipelineFromConfigRaisesExceptionForSpecsOmittingMiddl 'middleware_pipeline' => [ [ 'this' => 'will not work', - ] + ], ], ]; $app = $this->createApplication(); diff --git a/test/Container/ApplicationFactoryTest.php b/test/Container/ApplicationFactoryTest.php index 801c974f..008cb5b3 100644 --- a/test/Container/ApplicationFactoryTest.php +++ b/test/Container/ApplicationFactoryTest.php @@ -124,19 +124,19 @@ public function testFactoryWillPullAllReplaceableDependenciesFromContainerWhenPr public function callableMiddlewares() { return [ - ['HelloWorld'], - [ + ['HelloWorld'], + [ function () { - } - ], - [[InvokableMiddleware::class, 'staticallyCallableMiddleware']], + }, + ], + [[InvokableMiddleware::class, 'staticallyCallableMiddleware']], ]; } /** * @dataProvider callableMiddlewares * - * @param callable $middleware + * @param callable|array|string $middleware */ public function testFactorySetsUpRoutesFromConfig($middleware) { @@ -227,11 +227,11 @@ public function testCanSpecifyRouteOptionsViaConfiguration() { $expected = [ 'values' => [ - 'foo' => 'bar' + 'foo' => 'bar', ], 'tokens' => [ - 'bar' => 'foo' - ] + 'bar' => 'foo', + ], ]; $config = [ 'routes' => [ @@ -240,7 +240,7 @@ public function testCanSpecifyRouteOptionsViaConfiguration() 'middleware' => 'HelloWorld', 'name' => 'home', 'allowed_methods' => ['GET'], - 'options' => $expected + 'options' => $expected, ], ], ]; @@ -314,11 +314,13 @@ public function testWillCreatePipelineBasedOnMiddlewareConfiguration() ['path' => '/dynamic-path', 'middleware' => 'DynamicPath'], ['middleware' => $noPath], ['middleware' => 'Goodbye'], - ['middleware' => [ - $pipelineFirst, - 'Hello', - $pipelineLast, - ]], + [ + 'middleware' => [ + $pipelineFirst, + 'Hello', + $pipelineLast, + ], + ], ]; $config = ['middleware_pipeline' => $pipeline]; @@ -453,11 +455,13 @@ public function testWillNotInjectConfiguredRoutesOrPipelineIfProgrammaticPipelin ['path' => '/dynamic-path', 'middleware' => 'DynamicPath'], ['middleware' => $noPath], ['middleware' => 'Goodbye'], - ['middleware' => [ - $pipelineFirst, - 'Hello', - $pipelineLast, - ]], + [ + 'middleware' => [ + $pipelineFirst, + 'Hello', + $pipelineLast, + ], + ], ], 'routes' => [ [ diff --git a/test/Container/ErrorResponseGeneratorFactoryTest.php b/test/Container/ErrorResponseGeneratorFactoryTest.php index 3009ae42..d1b291f1 100644 --- a/test/Container/ErrorResponseGeneratorFactoryTest.php +++ b/test/Container/ErrorResponseGeneratorFactoryTest.php @@ -73,11 +73,13 @@ public function testUsesConfiguredTemplateRenderToSetGeneratorRenderer() public function testUsesTemplateConfigurationToSetTemplate() { $this->container->has('config')->willReturn(true); - $this->container->get('config')->willReturn(['zend-expressive' => [ - 'error_handler' => [ - 'template_error' => 'error::custom', + $this->container->get('config')->willReturn([ + 'zend-expressive' => [ + 'error_handler' => [ + 'template_error' => 'error::custom', + ], ], - ]]); + ]); $this->container->has(TemplateRendererInterface::class)->willReturn(false); $factory = new ErrorResponseGeneratorFactory(); diff --git a/test/Router/IntegrationTest.php b/test/Router/IntegrationTest.php index 54c5e15e..2ecd2ae1 100644 --- a/test/Router/IntegrationTest.php +++ b/test/Router/IntegrationTest.php @@ -59,9 +59,9 @@ public function getApplication() public function routerAdapters() { return [ - 'aura' => [AuraRouter::class], - 'fast-route' => [FastRouteRouter::class], - 'zf2' => [ZendRouter::class], + 'aura' => [AuraRouter::class], + 'fast-route' => [FastRouteRouter::class], + 'zf2' => [ZendRouter::class], ]; } @@ -76,7 +76,7 @@ public function routerAdapters() */ private function createApplicationWithGetPost($adapter, $getName = null, $postName = null) { - $app = new Application(new $adapter); + $app = new Application(new $adapter()); $app->pipeRoutingMiddleware(); $app->get('/foo', function ($req, $res, $next) { @@ -104,7 +104,7 @@ private function createApplicationWithGetPost($adapter, $getName = null, $postNa */ private function createApplicationWithRouteGetPost($adapter, $getName = null, $postName = null) { - $app = new Application(new $adapter); + $app = new Application(new $adapter()); $app->pipeRoutingMiddleware(); $app->route('/foo', function ($req, $res, $next) { @@ -262,7 +262,7 @@ public function testRoutingWithSamePathWithRouteWithName($adapter) */ public function testRoutingWithSamePathWithRouteWithMultipleMethods($adapter) { - $app = new Application(new $adapter); + $app = new Application(new $adapter()); $app->pipeRoutingMiddleware(); $app->pipeDispatchMiddleware(); @@ -322,7 +322,7 @@ public function routerAdaptersForHttpMethods() */ public function testMatchWithAllHttpMethods($adapter, $method) { - $app = new Application(new $adapter); + $app = new Application(new $adapter()); $app->pipeRoutingMiddleware(); $app->pipeDispatchMiddleware(); @@ -382,7 +382,7 @@ public function notAllowedMethod() */ public function testAllowedMethodsWhenOnlyPutMethodSet($adapter, $method) { - $app = new Application(new $adapter); + $app = new Application(new $adapter()); $app->pipeRoutingMiddleware(); $app->pipe(new Middleware\ImplicitHeadMiddleware()); $app->pipe(new Middleware\ImplicitOptionsMiddleware()); @@ -414,7 +414,7 @@ public function testAllowedMethodsWhenOnlyPutMethodSet($adapter, $method) */ public function testAllowedMethodsWhenNoHttpMethodsSet($adapter, $method) { - $app = new Application(new $adapter); + $app = new Application(new $adapter()); $app->pipeRoutingMiddleware(); $app->pipe(new Middleware\ImplicitHeadMiddleware()); $app->pipe(new Middleware\ImplicitOptionsMiddleware()); @@ -446,7 +446,7 @@ public function testAllowedMethodsWhenNoHttpMethodsSet($adapter, $method) */ public function testNotAllowedMethodWhenNoHttpMethodsSet($adapter, $method) { - $app = new Application(new $adapter); + $app = new Application(new $adapter()); $app->pipeRoutingMiddleware(); $app->pipeDispatchMiddleware(); @@ -476,7 +476,7 @@ public function testNotAllowedMethodWhenNoHttpMethodsSet($adapter, $method) */ public function testWithOnlyRootPathRouteDefinedRoutingToSubPathsShouldDelegate($adapter) { - $app = new Application(new $adapter); + $app = new Application(new $adapter()); $app->pipeRoutingMiddleware(); $app->route('/', function ($req, $res, $next) {