Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
chg: add a switch parameterset event
Browse files Browse the repository at this point in the history
phpunit tests added
  • Loading branch information
athanasius-kircher committed Oct 2, 2018
1 parent a73d93e commit a6d879e
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Event/SwitchParameterSetEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Created by PhpStorm.
* User: boellmann
* Date: 02.10.18
* Time: 14:38
*/

namespace DoL\LdapBundle\Event;


use Symfony\Component\EventDispatcher\Event;

class SwitchParameterSetEvent extends Event
{
const PARAMETERSET = 'dol_ldap.manager.switch_parameter_set';

private $parameterSet = [];

/**
* SwitchParameterSet constructor.
* @param array $parameterSet
*/
public function __construct(array $parameterSet)
{
$this->parameterSet = $parameterSet;
}

/**
* @return array
*/
public function getParameterSet(): array
{
return $this->parameterSet;
}

}
2 changes: 2 additions & 0 deletions Ldap/LdapManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -167,5 +168,6 @@ private function switchParameterSet(array $parameter)
$this->params = [];
}
$this->setLdapAttr();
$this->eventDispatcher->dispatch(SwitchParameterSetEvent::PARAMETERSET, new SwitchParameterSetEvent($parameter));
}
}
50 changes: 50 additions & 0 deletions Tests/Event/SwitchParameterSetEventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Created by PhpStorm.
* User: boellmann
* Date: 02.10.18
* Time: 14:44
*/

namespace DoL\LdapBundle\Event;


class SwitchParameterSetEventTest extends \PHPUnit_Framework_TestCase
{
/**
* @var SwitchParameterSetEvent
*/
private $event;
/**
* @var array
*/
private $parameter;

protected function setUp()
{
$this->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());
}

}
10 changes: 10 additions & 0 deletions Tests/Ldap/LdapManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit a6d879e

Please sign in to comment.