ZF-Commons / zfc-rbac

Role-based access control module to provide additional features on top of Zend\Permissions\Rbac
BSD 3-Clause "New" or "Revised" License
181 stars 111 forks source link

Add support for setter injection of IdentityProviderInterface and RoleeProviderInterface instances #298

Closed sebastianbergmann closed 9 years ago

sebastianbergmann commented 9 years ago

This solves problems such as the one described at http://stackoverflow.com/questions/29340127/zend-framework-2-abstractcontrollertestcase-and-zfcuser-zfcrbac

bakura10 commented 9 years ago

Why is this needed? This is not supposed to be changed, why can't you simply mock and inject them on constructor?

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-0.61%) to 93.02% when pulling 334c4ae94e38eecf515f39c5b6ad41b57b4da26f on sebastianbergmann:master into dd462590ec2a72964850a62258120a28a43ffdd2 on ZF-Commons:master.

sebastianbergmann commented 9 years ago

@bakura10 Thank you for your time to look at this. This is required because in the context of a test that uses Zend Framework 2's AbstractHttpControllerTestCase the guards are already registered by the time we can inject mocks into the service locator. Using the setter injection added by this patch we can replace the original instance with out mock which we cannot register otherwise.

bakura10 commented 9 years ago

Okay, I definitely think that mocking of controller should be done easier in ZF2, but given the current limitation, change sounds sane. I'll merge and tag.

bakura10 commented 9 years ago

Done. ZfcRbac has been tagged to 2.5.2

sebastianbergmann commented 9 years ago

Thanks!

clemf commented 8 years ago

@sebastianbergmann Is it possible to give an example of how to use this patch? I am struggling with this exact issue but I don't understand how these setters help.

sebastianbergmann commented 8 years ago

@clemf Sorry, I don't remember the details.