Skip to content

Commit 60cbcef

Browse files
lucasabajderusse
authored andcommitted
Adds LDAP Adapter test in integration group
Adds ext-ldap on github-actions
1 parent 5ccf663 commit 60cbcef

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

Tests/Adapter/ExtLdap/AdapterTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@
2525
*/
2626
class AdapterTest extends LdapTestCase
2727
{
28-
private const PAGINATION_REQUIRED_CONFIG = [
29-
'options' => [
30-
'protocol_version' => 3,
31-
],
32-
];
33-
3428
public function testLdapEscape()
3529
{
3630
$ldap = new Adapter();
@@ -122,7 +116,7 @@ public function testLdapQueryScopeOneLevel()
122116

123117
public function testLdapPagination()
124118
{
125-
$ldap = new Adapter(array_merge($this->getLdapConfig(), static::PAGINATION_REQUIRED_CONFIG));
119+
$ldap = new Adapter(array_merge($this->getLdapConfig()));
126120
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
127121
$entries = $this->setupTestUsers($ldap);
128122

@@ -205,7 +199,7 @@ private function destroyEntries($ldap, $entries)
205199

206200
public function testLdapPaginationLimits()
207201
{
208-
$ldap = new Adapter(array_merge($this->getLdapConfig(), static::PAGINATION_REQUIRED_CONFIG));
202+
$ldap = new Adapter(array_merge($this->getLdapConfig()));
209203
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
210204

211205
$entries = $this->setupTestUsers($ldap);

Tests/Adapter/ExtLdap/LdapManagerTest.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
use Symfony\Component\Ldap\Adapter\ExtLdap\Collection;
1616
use Symfony\Component\Ldap\Adapter\ExtLdap\UpdateOperation;
1717
use Symfony\Component\Ldap\Entry;
18-
use Symfony\Component\Ldap\Exception\AlreadyExistsException;
1918
use Symfony\Component\Ldap\Exception\LdapException;
2019
use Symfony\Component\Ldap\Exception\NotBoundException;
2120
use Symfony\Component\Ldap\Exception\UpdateOperationException;
2221
use Symfony\Component\Ldap\Tests\LdapTestCase;
2322

2423
/**
2524
* @requires extension ldap
25+
* @group integration
2626
*/
2727
class LdapManagerTest extends LdapTestCase
2828
{
@@ -82,7 +82,7 @@ public function testLdapAddInvalidEntry()
8282
*/
8383
public function testLdapAddDouble()
8484
{
85-
$this->expectException(AlreadyExistsException::class);
85+
$this->expectException(LdapException::class);
8686
$this->executeSearchQuery(1);
8787

8888
$entry = new Entry('cn=Elsa Amrouche,dc=symfony,dc=com', [
@@ -94,7 +94,12 @@ public function testLdapAddDouble()
9494

9595
$em = $this->adapter->getEntryManager();
9696
$em->add($entry);
97-
$em->add($entry);
97+
try {
98+
$em->add($entry);
99+
} catch (LdapException $e) {
100+
$em->remove($entry);
101+
throw $e;
102+
}
98103
}
99104

100105
/**
@@ -210,7 +215,8 @@ public function testLdapRenameWithoutRemovingOldRdn()
210215
$newEntry = $result[0];
211216
$originalCN = $entry->getAttribute('cn')[0];
212217

213-
$this->assertStringContainsString($originalCN, $newEntry->getAttribute('cn'));
218+
$this->assertContains($originalCN, $newEntry->getAttribute('cn'));
219+
$this->assertContains('Kevin', $newEntry->getAttribute('cn'));
214220

215221
$entryManager->rename($newEntry, 'cn='.$originalCN);
216222

@@ -372,13 +378,16 @@ public function testLdapMove()
372378
$result = $this->executeSearchQuery(1);
373379

374380
$entry = $result[0];
375-
$this->assertNotContains('ou=Ldap', $entry->getDn());
381+
$this->assertStringNotContainsString('ou=Ldap', $entry->getDn());
376382

377383
$entryManager = $this->adapter->getEntryManager();
378384
$entryManager->move($entry, 'ou=Ldap,ou=Components,dc=symfony,dc=com');
379385

380386
$result = $this->executeSearchQuery(1);
381387
$movedEntry = $result[0];
382388
$this->assertStringContainsString('ou=Ldap', $movedEntry->getDn());
389+
390+
// Move back entry
391+
$entryManager->move($movedEntry, 'dc=symfony,dc=com');
383392
}
384393
}

Tests/LdapTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class LdapTestCase extends TestCase
99
protected function getLdapConfig()
1010
{
1111
$h = @ldap_connect(getenv('LDAP_HOST'), getenv('LDAP_PORT'));
12+
ldap_set_option($h, LDAP_OPT_PROTOCOL_VERSION, 3);
1213

1314
if (!$h || !@ldap_bind($h)) {
1415
$this->markTestSkipped('No server is listening on LDAP_HOST:LDAP_PORT');

0 commit comments

Comments
 (0)