diff --git a/src/PhlyRestfully/ResourceController.php b/src/PhlyRestfully/ResourceController.php index bc8498ce..4eeb77d6 100644 --- a/src/PhlyRestfully/ResourceController.php +++ b/src/PhlyRestfully/ResourceController.php @@ -681,12 +681,12 @@ protected function getIdentifier($routeMatch, $request) { $identifier = $this->getIdentifierName(); $id = $routeMatch->getParam($identifier, false); - if ($id) { + if ($id !== false) { return $id; } $id = $request->getQuery()->get($identifier, false); - if ($id) { + if ($id !== false) { return $id; } diff --git a/test/PhlyRestfullyTest/ResourceControllerTest.php b/test/PhlyRestfullyTest/ResourceControllerTest.php index 7999a0ac..91c62e6d 100644 --- a/test/PhlyRestfullyTest/ResourceControllerTest.php +++ b/test/PhlyRestfullyTest/ResourceControllerTest.php @@ -1022,6 +1022,20 @@ public function testUsesConfiguredIdentifierNameToGetIdentifier() $result = $getIdentifier->invoke($this->controller, $routeMatch, $request); $this->assertEquals('bar', $result); } + + public function testIdentifierMatchedAgainstParameter() + { + $r = new ReflectionObject($this->controller); + $getIdentifier = $r->getMethod('getIdentifier'); + $getIdentifier->setAccessible(true); + + $routeMatch = $this->event->getRouteMatch(); + $request = $this->controller->getRequest(); + + $routeMatch->setParam('id', '0'); + $result = $getIdentifier->invoke($this->controller, $routeMatch, $request); + $this->assertEquals('0', $result); + } /** * @group 44