-
Notifications
You must be signed in to change notification settings - Fork 111
Conversation
Mhmm seems like it is time to drop PHP 5.4 support? |
Even time to drop 5.5 I would say :-) |
ok, I'm just affraid that our build does not run tests with both ZF2 and ZF3. I think you should bump dev dependency to latest version. Or should we drop ZF2 as well? :D |
Oh, no problem, let me do this... wait... |
so, that should do the trick. |
damn. some tests are failing with minimum requirements already. I'll try to fix that tomorrow. |
Any ideas why latest zend-servicemanager installed is 2.7.6 instead of 3.1? Is there any other dependency requiring the older version perhaps? |
Damn, currently DoctrineModule and zend-developer-tools do not allow Zend-Servicemanager v3 for DoctrineModule, there is a PR here: doctrine/DoctrineModule#558 |
So you can prepare against that PR... I did that when I wanted to zf3 proof SlmQueue. Whenever doctrine orm is updated I'm fairly sure it will work...
|
Please review carefully. I needed to change a lot of code. |
the test should be failing with current implementation and pass with your Sascha-Oliver Prolic 2016-07-20 22:04 GMT+08:00 Atanas Vasilev notifications@github.com:
|
I could really use some help here. In my situation, if I change this: public function onResult(MvcEvent $event)
{
if ($this->isGranted($event)) {
return;
}
$event->setError(self::GUARD_UNAUTHORIZED);
$event->setParam('exception', new Exception\UnauthorizedException(
'You are not authorized to access this resource',
403
));
$event->stopPropagation(true);
$application = $event->getApplication();
$eventManager = $application->getEventManager();
$eventManager->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event);
} ... to this: public function onResult(MvcEvent $event)
{
if ($this->isGranted($event)) {
return;
}
$event->setError(self::GUARD_UNAUTHORIZED);
$event->setParam('exception', new Exception\UnauthorizedException(
'You are not authorized to access this resource',
403
));
$event->stopPropagation(true);
$event->setName(MvcEvent::EVENT_DISPATCH_ERROR);
$target = $event->getTarget();
$target->getEventManager()->triggerEvent($event);
} The fatal error is not emitted and the redirect strategy does its job properly. What I don't know is, how I could represent this with unit tests. This is the test I'm looking at:
public function testProperlySetUnauthorizedAndTriggerEventOnUnauthorization()
{
$event = new MvcEvent();
$routeMatch = new RouteMatch([]);
$application = $this->getMock('Zend\Mvc\Application', [], [], '', false);
$eventManager = $this->getMock('Zend\EventManager\EventManagerInterface');
$application->expects($this->once())
->method('getEventManager')
->will($this->returnValue($eventManager));
$eventManager->expects($this->once())
->method('trigger')
->with(MvcEvent::EVENT_DISPATCH_ERROR);
$routeMatch->setParam('controller', 'MyController');
$routeMatch->setParam('action', 'delete');
$event->setRouteMatch($routeMatch);
$event->setApplication($application);
$identityProvider = $this->getMock('ZfcRbac\Identity\IdentityProviderInterface');
$identityProvider->expects($this->any())
->method('getIdentityRoles')
->will($this->returnValue('member'));
$roleProvider = new InMemoryRoleProvider([
'member'
]);
$roleService = new RoleService($identityProvider, $roleProvider, new RecursiveRoleIteratorStrategy());
$routeGuard = new ControllerGuard($roleService, [[
'controller' => 'MyController',
'actions' => 'edit',
'roles' => 'member'
]]);
$routeGuard->onResult($event);
$this->assertTrue($event->propagationIsStopped());
$this->assertEquals(ControllerGuard::GUARD_UNAUTHORIZED, $event->getError());
$this->assertInstanceOf('ZfcRbac\Exception\UnauthorizedException', $event->getParam('exception'));
} You see, the event propagation, error and exception param are set okay, but when namespace Zend\EventManager;
class EventManager implements EventManagerInterface
{
public function trigger($eventName, $target = null, $argv = [])
{
// Zend\EventManager\Event and not Zend\Mvc\MvcEvent
// which all listeners expect
$event = clone $this->eventPrototype;
$event->setName($eventName);
$event->setTarget($target);
$event->setParams($argv);
return $this->triggerListeners($event);
}
} I don't know how to test this in isolation as in my opinion it's an integration issue. Could someone advise as to how this could be handled? |
When planned merges these changes? |
@prolic, How should I implement the tests to pass both with zf2 and zf3, with respect to changed namespaces? For example in ZF3 the Router is in its own namespace |
@webimpress Thank you! The example is valid, but the same approach is not used with the current tests in the The tests fail with my environment even without modifying the code. |
…ce of the wrong type to be passed to registered listeners
Okay, I'm not creating a PR, because of said differences regarding imports, but here's my commit that basically fixes the problem for me: nasko@9e97ce3. I'd be grateful for any feedback. |
@nasko you can skip the test if class_exists returns false. |
I'm going do merge it tonight, @bakura10 can you review it as well? |
This is beyond me - I guess I'll have to resort to using my fork to address #340 |
updated, thanks to @nasko for helping to fix this. |
|
||
/* @var \ZfcRbac\Service\AuthorizationService $authorizationService */ | ||
$authorizationService = $parentLocator->get('ZfcRbac\Service\AuthorizationService'); | ||
$authorizationService = $container->get('ZfcRbac\Service\AuthorizationService'); | ||
|
||
$routeGuard = new RoutePermissionsGuard($authorizationService, $this->options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$options
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
some further notes:
DoctrineORMModule does not support Zend-MVC 3.0, but this module still can support it, as the tests are showing. If you want to run this module with DoctrineORMModule, then you have to use Zend-MVC 2.7 for now.
There are some BC breaks in the factories. They are working the with Zend-Servicemanager v2 and v3 but do not implement the MutableCreationOptionsInterface, f.e. Also the plugin managers get the main service locator injected into the constructor, instead of calling $pluginmanager->setServiceLocator($sm);
This has to be noted in the changelog. You don't need to care about this, when you simply use this module as is. If you extended or aggregated the provided factories, you need to update your code accordingly.