function it_should_call_the_event_dispatcher_modify_events_when_persisting_an_object(EventDispatcherInterface $dispatcher, $connection)
{
$dn = 'cn=foo,dc=foo,dc=bar';
$batch = new BatchCollection($dn);
$batch->add(new Batch(Batch::TYPE['REPLACE'], 'givenName', 'Chad'));
$batch->add(new Batch(Batch::TYPE['ADD'], 'sn', 'Sikorra'));
$batch->add(new Batch(Batch::TYPE['REMOVE'], 'sAMAccountName', 'csikorra'));
$batch->add(new Batch(Batch::TYPE['REMOVE_ALL'], 'mail'));
$connection->execute(new BatchModifyOperation($dn, $batch))->willReturn(null);
$this->beConstructedWith($connection, $this->objectSchemaFactory, $dispatcher);
$ldapObject = new LdapObject(['dn' => $dn], 'user');
$ldapObject->set('firstName', 'Chad');
$ldapObject->add('lastName', 'Sikorra');
$ldapObject->remove('username', 'csikorra');
$ldapObject->reset('emailAddress');
$beforeEvent = new LdapObjectEvent(Event::LDAP_OBJECT_BEFORE_MODIFY, $ldapObject);
$afterEvent = new LdapObjectEvent(Event::LDAP_OBJECT_AFTER_MODIFY, $ldapObject);
$dispatcher->dispatch($beforeEvent)->shouldBeCalled();
$dispatcher->dispatch($afterEvent)->shouldBeCalled();
$this->persist($ldapObject);
}