Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion phpstan.tests.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
parameters:
level: 3
treatPhpDocTypesAsCertain: false
level: 10
paths:
- %currentWorkingDirectory%/tests
14 changes: 1 addition & 13 deletions src/FreeDSx/Ldap/Entry/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,26 @@
* @author Chad Sikorra <Chad.Sikorra@gmail.com>
*
* @implements IteratorAggregate<Entry>
* @template T of Entry
*/
class Entries implements Countable, IteratorAggregate
{
/**
* @var array<T>
* @var array<Entry>
*/
private array $entries;

/**
* @param T ...$entries
*/
public function __construct(Entry ...$entries)
{
$this->entries = $entries;
}

/**
* @param T ...$entries
* @return $this
*/
public function add(Entry ...$entries): self
{
$this->entries = array_merge($this->entries, $entries);

return $this;
}

/**
* @param T ...$entries
* @return $this
*/
public function remove(Entry ...$entries): self
{
foreach ($entries as $entry) {
Expand Down
2 changes: 1 addition & 1 deletion src/FreeDSx/Ldap/Entry/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public static function create(
/**
* Construct an entry from an associative array.
*
* @param array<string, string|array<string|Stringable>> $attributes
* @param array<string, scalar|array<scalar|Stringable>> $attributes
*/
public static function fromArray(
Dn|Stringable|string $dn,
Expand Down
5 changes: 4 additions & 1 deletion tests/bin/ldapserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ private function logRequest(

class LdapServerRequestHandler extends GenericRequestHandler
{
private $users = [
/**
* @var array<string, string>
*/
private array $users = [
'cn=user,dc=foo,dc=bar' => '12345',
];

Expand Down
17 changes: 6 additions & 11 deletions tests/integration/LdapClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function tearDown(): void
public function testUsernamePasswordBind(): void
{
$response = $this->client->bind(
$_ENV['LDAP_USERNAME'],
$_ENV['LDAP_PASSWORD']
(string) getenv('LDAP_USERNAME'),
(string) getenv('LDAP_PASSWORD'),
)->getResponse();

$this->assertInstanceOf(
Expand Down Expand Up @@ -309,10 +309,6 @@ public function testRenameOperation(): void
ModifyDnResponse::class,
$result->getResponse()
);
$this->assertInstanceOf(
Entry::class,
$entry
);
$this->assertSame(
['Arleen Sevigny-Foo'],
$entry->get('cn')?->getValues()
Expand Down Expand Up @@ -420,10 +416,6 @@ public function testSubSearchOperation(): void
Filters::raw('(&(objectClass=inetOrgPerson)(cn=A*))')
));

$this->assertInstanceOf(
Entries::class,
$entries
);
$this->assertCount(
843,
$entries,
Expand Down Expand Up @@ -561,12 +553,15 @@ public function testUseSslIgnoreCertValidation(): void
$this->assertTrue($this->client->isConnected());
}

/**
* @return array<string, string>
*/
protected function getSaslOptions(): array
{
if ($this->isActiveDirectory()) {
return [
'username' => 'admin',
'password' => $_ENV['LDAP_PASSWORD'],
'password' => (string) getenv('LDAP_PASSWORD'),
'host' => 'ADDC3.example.com'
];
} else {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/LdapProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public function testItCanHandlePaging(): void
protected function authenticate(): void
{
$this->ldapClient()->bind(
$_ENV['LDAP_USERNAME'],
$_ENV['LDAP_PASSWORD']
(string) getenv('LDAP_USERNAME'),
(string) getenv('LDAP_PASSWORD'),
);
}
}
18 changes: 6 additions & 12 deletions tests/integration/LdapServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ public function setUp(): void

public function testItCanBind(): void
{
$response = $this->ldapClient()->bind(
$this->ldapClient()->bind(
'cn=user,dc=foo,dc=bar',
'12345'
);
$output = $this->waitForServerOutput('---bind---');

$this->assertNotNull($response);
$this->assertStringContainsString(
'username => cn=user,dc=foo,dc=bar',
$output
Expand Down Expand Up @@ -69,15 +68,14 @@ public function testItRejectsBindWithIncorrectCredentials(): void
public function testItPerformsAnAdd(): void
{
$this->authenticate();
$response = $this->ldapClient()->create(Entry::fromArray(
$this->ldapClient()->create(Entry::fromArray(
'cn=meh,dc=foo,dc=bar',
[
'foo' => 'bar',
]
));
$output = $this->waitForServerOutput('---add---');

$this->assertNotNull($response);
$this->assertStringContainsString(
'dn => cn=meh,dc=foo,dc=bar',
$output
Expand All @@ -91,10 +89,9 @@ public function testItPerformsAnAdd(): void
public function testItPerformsDelete(): void
{
$this->authenticate();
$response = $this->ldapClient()->delete('cn=meh,dc=foo,dc=bar');
$this->ldapClient()->delete('cn=meh,dc=foo,dc=bar');
$output = $this->waitForServerOutput('---delete---');

$this->assertNotNull($response);
$this->assertStringContainsString(
'dn => cn=meh,dc=foo,dc=bar',
$output
Expand All @@ -119,10 +116,9 @@ public function testItPerformsModify(): void
$entry->set('surname', 'LastName');
$entry->reset('phone');

$response = $this->ldapClient()->update($entry);
$this->ldapClient()->update($entry);
$output = $this->waitForServerOutput('---modify---');

$this->assertNotNull($response);
$this->assertStringContainsString(
'dn => cn=meh,dc=foo,dc=bar',
$output
Expand Down Expand Up @@ -155,14 +151,13 @@ public function testItCanPerformCompare(): void
{
$this->authenticate();

$response = $this->ldapClient()->compare(
$this->ldapClient()->compare(
'cn=meh,dc=foo,dc=bar',
'foo',
'bar'
);
$output = $this->waitForServerOutput('---compare---');

$this->assertNotNull($response);
$this->assertStringContainsString(
'dn => cn=meh,dc=foo,dc=bar',
$output
Expand All @@ -181,13 +176,12 @@ public function testItCanModifyDn(): void
{
$this->authenticate();

$response = $this->ldapClient()->move(
$this->ldapClient()->move(
'cn=meh,dc=foo,dc=bar',
'cn=bleh,dc=foo,dc=bar'
);
$output = $this->waitForServerOutput('---modify-dn---');

$this->assertNotNull($response);
$this->assertStringContainsString(
'dn => cn=meh,dc=foo,dc=bar',
$output
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/LdapTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class LdapTestCase extends TestCase
protected function makeOptions(): ClientOptions
{
return (new ClientOptions())
->setBaseDn((string) $_ENV['LDAP_BASE_DN'])
->setServers([(string) $_ENV['LDAP_SERVER']])
->setBaseDn((string) getenv('LDAP_BASE_DN'))
->setServers([(string) getenv('LDAP_SERVER')])
->setSslCaCert(
$_ENV['LDAP_CA_CERT'] === ''
? __DIR__ . '/../resources/cert/ca.crt'
: (string) $_ENV['LDAP_CA_CERT']
: (string) getenv('LDAP_CA_CERT')
)
->setBaseDn((string) $_ENV['LDAP_BASE_DN']);
->setBaseDn((string) getenv('LDAP_BASE_DN'));
}

protected function getClient(?ClientOptions $options = null): LdapClient
Expand All @@ -43,8 +43,8 @@ protected function getClient(?ClientOptions $options = null): LdapClient
protected function bindClient(LdapClient $client): void
{
$client->bind(
$_ENV['LDAP_USERNAME'],
$_ENV['LDAP_PASSWORD'],
(string) getenv('LDAP_USERNAME'),
(string) getenv('LDAP_PASSWORD'),
);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/integration/Search/RangeRetrievalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use FreeDSx\Ldap\LdapClient;
use FreeDSx\Ldap\Search\RangeRetrieval;
use Tests\Integration\FreeDSx\Ldap\LdapTestCase;
use Throwable;

class RangeRetrievalTest extends LdapTestCase
{
Expand All @@ -39,7 +40,7 @@ public function tearDown(): void
{
try {
$this->client->unbind();
} catch (\Exception|\Throwable $e) {
} catch (Throwable) {
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/resources/activedirectory/generate-ldif.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# A simple script to modify the OpenLDAP LDIF data to work with AD so we are working with the same data set.

$data = file_get_contents(__DIR__ . '/../openldap/ldif/data.ldif');
$data = (string) file_get_contents(__DIR__ . '/../openldap/ldif/data.ldif');
$ldif = explode("\n", $data);
foreach ($ldif as $i => $line) {
if (preg_match('/^userPassword/', $line)) {
Expand All @@ -11,7 +11,7 @@
}
file_put_contents(__DIR__ . '/ldif/data.ldif', implode("\n", $ldif));

$data = file_get_contents(__DIR__ . '/../openldap/ldif/data-group.ldif');
$data = (string) file_get_contents(__DIR__ . '/../openldap/ldif/data-group.ldif');
$ldif = explode("\n", $data);
foreach ($ldif as $i => $line) {
if (preg_match('/^objectClass/', $line)) {
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ protected function setUp(): void
]);
}

/**
* @return array<array{class-string}>
*/
public static function buildableDependenciesDataProvider(): array
{
return [
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Entry/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function test_it_should_remove_an_attribute_using_an_attribute(): void
self::assertNull($this->subject->get('cn', true));
}

public function if_should_check_if_it_has_an_attribute_using_a_string()
public function if_should_check_if_it_has_an_attribute_using_a_string(): void
{
self::assertTrue($this->subject->has('Cn'));
self::assertFalse($this->subject->has('bleh'));
Expand Down
48 changes: 22 additions & 26 deletions tests/unit/LdapClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,46 +155,42 @@ public function test_it_should_bind(): void

public function test_it_should_construct_a_pager_helper(): void
{
self::assertInstanceOf(
Paging::class,
$this->subject->paging(Operations::search(
Filters::equal(
'foo',
'bar'
))
),
self::expectNotToPerformAssertions();

$this->subject->paging(Operations::search(
Filters::equal(
'foo',
'bar'
))
);
}

public function test_it_should_construct_a_vlv_helper(): void
{
self::assertInstanceOf(
Vlv::class,
$this->subject->vlv(
Operations::search(Filters::equal(
'foo',
'bar'
)),
'cn',
100
),
self::expectNotToPerformAssertions();

$this->subject->vlv(
Operations::search(Filters::equal(
'foo',
'bar'
)),
'cn',
100
);
}

public function test_it_should_construct_a_dirsync_helper(): void
{
self::assertInstanceOf(
DirSync::class,
$this->subject->dirSync()
);
self::expectNotToPerformAssertions();

$this->subject->dirSync();
}

public function test_it_should_construct_a_range_retrieval_helper(): void
{
self::assertInstanceOf(
RangeRetrieval::class,
$this->subject->range(),
);
self::expectNotToPerformAssertions();

$this->subject->range();
}

public function test_it_should_start_tls(): void
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/Operation/Request/AbandonRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ protected function setUp(): void
$this->subject = new AbandonRequest(1);
}

public function testItIsInitializable(): void
{
$this->assertInstanceOf(AbandonRequest::class, $this->subject);
}

public function testItShouldGetTheMessageId(): void
{
$this->assertEquals(1, $this->subject->getMessageId());
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Operation/Request/SearchRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public function test_it_should_not_allow_invalid_cancel_stragegies(): void
{
$this->expectException(UnexpectedValueException::class);

/** @phpstan-ignore-next-line */
$this->subject->useCancelStrategy('foo');
}

Expand Down
Loading
Loading