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

Commit 56ab39d

Browse files
committed
Merge branch 'hotfix/118'
Close #118
2 parents 48191f7 + d5e5f9e commit 56ab39d

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
@@ -16,6 +16,7 @@
1616
use Zend\Expressive\Emitter\EmitterStack;
1717
use Zend\Expressive\Exception;
1818
use Zend\Expressive\Router\Aura as AuraRouter;
19+
use Zend\Expressive\Router\Route;
1920
use Zend\Expressive\Router\RouterInterface;
2021

2122
/**
@@ -167,11 +168,14 @@ private function injectRoutes(Application $app, ContainerInterface $container)
167168
? $spec['allowed_methods']
168169
: null;
169170
$name = isset($spec['name']) ? $spec['name'] : null;
170-
$route = $app->route($spec['path'], $spec['middleware'], $methods, $name);
171+
$methods = (null === $methods) ? Route::HTTP_METHOD_ANY : $methods;
172+
$route = new Route($spec['path'], $spec['middleware'], $methods, $name);
171173

172174
if (isset($spec['options']) && is_array($spec['options'])) {
173175
$route->setOptions($spec['options']);
174176
}
177+
178+
$app->route($route);
175179
}
176180
}
177181

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)