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

AbstractRestfulController uses wrong action for id=0 #4175

Closed
fisharebest opened this issue Apr 3, 2013 · 2 comments
Closed

AbstractRestfulController uses wrong action for id=0 #4175

fisharebest opened this issue Apr 3, 2013 · 2 comments
Milestone

Comments

@fisharebest
Copy link

Zend\Mvc\ControllerAbstractRestfulController::getIdentifier() has two instances of

if ($id)

These should both be

if ($id!==false)

Otherwise the route /xxx?id=0 gets routed to the getList() action instead of the get() action

The unit test for this is probably this. I say probably, as can't run it; the ZF2 unit tests require phpunit-3.5 and I can't manage to downgrade my phpunit-3.6.10

public function testDispatchInvokesGetMethodWhenNoActionPresentAndZeroIdentifierPresentOnGet()
    {
    $entity = new stdClass;
    $this->controller->entity = $entity;
    $this->routeMatch->setParam('id', 0);
    $result = $this->controller->dispatch($this->request, $this->response);
    $this->assertArrayHasKey('entity', $result);
    $this->assertEquals($entity, $result['entity']);
    $this->assertEquals('get', $this->routeMatch->getParam('action'));
}
@weierophinney
Copy link
Member

Why are you using an id of 0 in the first place? (Also, BTW, ZF2 unit tests require PHPUnit 3.7, not 3.5.)

@fisharebest
Copy link
Author

<< Why are you using an id of 0 >>

GET /widget

returns either a JSON list of widgets or an HTML list of widgets

GET /widget?id=123

returns either a JSON representation of widget 123, or an HTML page to edit widget 123.

GET /widget?id=0

returns an HTML page to create a new widget (not a list of widgets)

In any case, being a programmer, I might want to number my widgets from zero, rather than one ;-)

<< Also, BTW, ZF2 unit tests require PHPUnit 3.7, not 3.5 >>

My mistake. I got an error about 3.6.10 not being valid, and the first google result for the error message was a comment saying that ZF2 hoped to upgrade from 3.5 to 3.6 shortly. I guess I didn't check the date of the article (or look at the code...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants