Skip to content

Commit 54ec105

Browse files
committed
Merge branch 'master' into query-builder-grammar-fixes
2 parents c27ad6c + c22323a commit 54ec105

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

src/Connection.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,11 @@ protected function configure(): void
153153
$this->ldap->setStartTLS();
154154
}
155155

156-
$this->ldap->setOptions(array_replace(
157-
$this->configuration->get('options'),
158-
[
159-
LDAP_OPT_PROTOCOL_VERSION => $this->configuration->get('version'),
160-
LDAP_OPT_NETWORK_TIMEOUT => $this->configuration->get('timeout'),
161-
LDAP_OPT_REFERRALS => $this->configuration->get('follow_referrals'),
162-
]
163-
));
156+
$this->ldap->setOptions(array_replace($this->configuration->get('options'), [
157+
LDAP_OPT_PROTOCOL_VERSION => $this->configuration->get('version'),
158+
LDAP_OPT_NETWORK_TIMEOUT => $this->configuration->get('timeout'),
159+
LDAP_OPT_REFERRALS => $this->configuration->get('follow_referrals'),
160+
]));
164161
}
165162

166163
/**

src/Models/Attributes/Timestamp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected function convertWindowsIntegerTimeToDateTime(string|int|null $value =
190190
}
191191

192192
return (new DateTime)->setTimestamp(
193-
round($value / 10000000) - 11644473600
193+
(int) ($value / 10000000) - 11644473600
194194
);
195195
}
196196

src/Query/Builder.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,15 @@ public function whereNotContains(string $attribute, string $value): static
948948
*/
949949
public function whereIn(string $attribute, array $values): static
950950
{
951+
if (empty($values)) {
952+
// If the array of values is empty, we will
953+
// add an empty OR filter to the query to
954+
// ensure that no results are returned.
955+
$this->addFilter(new OrGroup());
956+
957+
return $this;
958+
}
959+
951960
$query = $this->newNestedInstance(function (Builder $query) use ($attribute, $values) {
952961
foreach ($values as $value) {
953962
$query->orWhereEquals($attribute, $value);

tests/Integration/QueryTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,15 @@ public function test_it_cannot_override_limit_when_chunking()
6464

6565
$this->assertEquals(2, $pages);
6666
}
67+
68+
public function test_it_returns_no_results_with_empty_where_in_array()
69+
{
70+
$user = $this->makeUser($this->ou);
71+
72+
$user->save();
73+
74+
$this->assertCount(1, User::get());
75+
$this->assertCount(1, User::whereIn('cn', [$user->getFirstAttribute('cn')])->get());
76+
$this->assertEmpty(User::whereIn('cn', [])->get());
77+
}
6778
}

tests/Unit/Models/Attributes/TimestampTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,17 @@ public function test_windows_int_type_properly_handles_minimum()
146146
$this->assertSame($min, $timestamp->toDateTime($min));
147147
$this->assertSame($min, $timestamp->toDateTime((string) $min));
148148
}
149+
150+
public function test_windows_int_type_rounds_correctly()
151+
{
152+
$timestamp = new Timestamp('windows-int');
153+
154+
foreach (['133692539995000000', '133692539999500000'] as $windowsIntegerTime) {
155+
$dateTime = $timestamp->toDateTime($windowsIntegerTime);
156+
157+
$expectedUnixTimestamp = (int) ($windowsIntegerTime / 10000000) - 11644473600;
158+
159+
$this->assertEquals($expectedUnixTimestamp, $dateTime->getTimestamp());
160+
}
161+
}
149162
}

tests/Unit/Query/BuilderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,15 @@ public function test_built_where_in()
542542
$this->assertEquals('(|(name=john)(name=mary)(name=sue))', $b->getUnescapedQuery());
543543
}
544544

545+
public function test_built_where_in_with_empty_array()
546+
{
547+
$b = $this->newBuilder();
548+
549+
$b->whereIn('name', []);
550+
551+
$this->assertEquals('(|)', $b->getUnescapedQuery());
552+
}
553+
545554
public function test_built_where_approximately_equals()
546555
{
547556
$b = $this->newBuilder();

0 commit comments

Comments
 (0)