diff --git a/Event/SwitchParameterSetEvent.php b/Event/SwitchParameterSetEvent.php new file mode 100644 index 0000000..16275b5 --- /dev/null +++ b/Event/SwitchParameterSetEvent.php @@ -0,0 +1,37 @@ +parameterSet = $parameterSet; + } + + /** + * @return array + */ + public function getParameterSet(): array + { + return $this->parameterSet; + } + +} diff --git a/Ldap/LdapManager.php b/Ldap/LdapManager.php index 9c4a55c..d368a53 100644 --- a/Ldap/LdapManager.php +++ b/Ldap/LdapManager.php @@ -3,6 +3,7 @@ namespace DoL\LdapBundle\Ldap; use DoL\LdapBundle\Driver\LdapDriverInterface; +use DoL\LdapBundle\Event\SwitchParameterSetEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Security\Core\User\UserInterface; use DoL\LdapBundle\Hydrator\HydratorInterface; @@ -167,5 +168,6 @@ private function switchParameterSet(array $parameter) $this->params = []; } $this->setLdapAttr(); + $this->eventDispatcher->dispatch(SwitchParameterSetEvent::PARAMETERSET, new SwitchParameterSetEvent($parameter)); } } diff --git a/Tests/Event/SwitchParameterSetEventTest.php b/Tests/Event/SwitchParameterSetEventTest.php new file mode 100644 index 0000000..5feeb62 --- /dev/null +++ b/Tests/Event/SwitchParameterSetEventTest.php @@ -0,0 +1,50 @@ +parameter = [ + 'driver' => [ + // SOME ATTRIBUTES + ], + 'user' => [ + 'baseDn' => 'ou=Groups,dc=example,dc=com', + 'filter' => '(attr0=value0)', + 'attributes' => [ + [ + 'ldap_attr' => 'uid', + 'user_method' => 'setUsername', + ], + ], + ], + ]; + $this->event = new SwitchParameterSetEvent($this->parameter); + } + + + public function testGetter() + { + $this->assertTrue(is_array($this->event->getParameterSet())); + $this->assertArraySubset($this->parameter,$this->event->getParameterSet()); + } + +} diff --git a/Tests/Ldap/LdapManagerTest.php b/Tests/Ldap/LdapManagerTest.php index dbc3b8a..4fec33f 100644 --- a/Tests/Ldap/LdapManagerTest.php +++ b/Tests/Ldap/LdapManagerTest.php @@ -2,6 +2,7 @@ namespace DoL\LdapBundle\Tests\Ldap; +use DoL\LdapBundle\Event\SwitchParameterSetEvent; use DoL\LdapBundle\Hydrator\HydratorInterface; use DoL\LdapBundle\Ldap\LdapManager; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -150,6 +151,15 @@ public function testBind() ->method('bind') ->with($user, $this->equalTo($password)) ->will($this->returnValue(true)); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch') + ->with( + $this->equalTo('dol_ldap.manager.switch_parameter_set'), + $this->callback(function(SwitchParameterSetEvent $event){ + $parameterSet = $event->getParameterSet(); + return (is_array($parameterSet) AND isset($parameterSet['driver'])); + }) + ); self::assertTrue($this->ldapManager->bind($user, $password)); }