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

Commit c3e2fda

Browse files
committed
Merge branch 'hotfix/118' into develop
Forward port #118
2 parents ff194a1 + d5e5f9e commit c3e2fda

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

src/Container/ApplicationFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Zend\Expressive\Application;
1515
use Zend\Expressive\Exception;
1616
use Zend\Expressive\Router\AuraRouter;
17+
use Zend\Expressive\Router\Route;
1718
use Zend\Expressive\Router\RouterInterface;
1819

1920
/**
@@ -165,11 +166,14 @@ private function injectRoutes(Application $app, ContainerInterface $container)
165166
? $spec['allowed_methods']
166167
: null;
167168
$name = isset($spec['name']) ? $spec['name'] : null;
168-
$route = $app->route($spec['path'], $spec['middleware'], $methods, $name);
169+
$methods = (null === $methods) ? Route::HTTP_METHOD_ANY : $methods;
170+
$route = new Route($spec['path'], $spec['middleware'], $methods, $name);
169171

170172
if (isset($spec['options']) && is_array($spec['options'])) {
171173
$route->setOptions($spec['options']);
172174
}
175+
176+
$app->route($route);
173177
}
174178
}
175179

test/Container/ApplicationFactoryTest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,4 +997,75 @@ public function testCanSpecifyRouteNamesViaConfiguration()
997997
$this->assertInstanceOf(Route::class, $route);
998998
$this->assertEquals('home', $route->getName());
999999
}
1000+
1001+
public function testCanSpecifyRouteOptionsViaConfiguration()
1002+
{
1003+
$router = $this->prophesize('Zend\Expressive\Router\RouterInterface');
1004+
$emitter = $this->prophesize('Zend\Diactoros\Response\EmitterInterface');
1005+
$finalHandler = function ($req, $res, $err = null) {
1006+
};
1007+
1008+
$expected = [
1009+
'values' => [
1010+
'foo' => 'bar'
1011+
],
1012+
'tokens' => [
1013+
'bar' => 'foo'
1014+
]
1015+
];
1016+
$config = [
1017+
'routes' => [
1018+
[
1019+
'path' => '/',
1020+
'middleware' => 'HelloWorld',
1021+
'name' => 'home',
1022+
'allowed_methods' => ['GET'],
1023+
'options' => $expected
1024+
],
1025+
],
1026+
];
1027+
1028+
$this->container
1029+
->has('Zend\Expressive\Router\RouterInterface')
1030+
->willReturn(true);
1031+
$this->container
1032+
->get('Zend\Expressive\Router\RouterInterface')
1033+
->will(function () use ($router) {
1034+
return $router->reveal();
1035+
});
1036+
1037+
$this->container
1038+
->has('Zend\Diactoros\Response\EmitterInterface')
1039+
->willReturn(true);
1040+
$this->container
1041+
->get('Zend\Diactoros\Response\EmitterInterface')
1042+
->will(function () use ($emitter) {
1043+
return $emitter->reveal();
1044+
});
1045+
1046+
$this->container
1047+
->has('Zend\Expressive\FinalHandler')
1048+
->willReturn(true);
1049+
$this->container
1050+
->get('Zend\Expressive\FinalHandler')
1051+
->willReturn($finalHandler);
1052+
1053+
$this->container
1054+
->has('config')
1055+
->willReturn(true);
1056+
1057+
$this->container
1058+
->get('config')
1059+
->willReturn($config);
1060+
1061+
$app = $this->factory->__invoke($this->container->reveal());
1062+
1063+
$r = new ReflectionProperty($app, 'routes');
1064+
$r->setAccessible(true);
1065+
$routes = $r->getValue($app);
1066+
$route = array_shift($routes);
1067+
1068+
$this->assertInstanceOf(Route::class, $route);
1069+
$this->assertEquals($expected, $route->getOptions());
1070+
}
10001071
}

0 commit comments

Comments
 (0)