AbstractRestfulController uses wrong action for id=0 #4175

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

Comments

Projects
None yet
2 participants
@fisharebest

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

This comment has been minimized.

Show comment Hide comment
@weierophinney

weierophinney Apr 3, 2013

Owner

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

Owner

weierophinney commented Apr 3, 2013

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

This comment has been minimized.

Show comment Hide comment
@fisharebest

fisharebest Apr 3, 2013

<< 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...

<< 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 join this conversation on GitHub. Already have an account? Sign in to comment