Skip to content

Commit 052de90

Browse files
committed
Update tests
1 parent 988bb20 commit 052de90

File tree

10 files changed

+90
-315
lines changed

10 files changed

+90
-315
lines changed

tests/Unit/Models/ActiveDirectory/ModelTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public function relation(): HasMany
110110

111111
$this->assertInstanceOf(HasMany::class, $relation);
112112
$this->assertInstanceOf(ActiveDirectoryBuilder::class, $query = $relation->getQuery());
113-
$this->assertEquals('(|(foo=\66\6f\6f))', $query->getQuery()->getQuery());
113+
// With a single value, whereIn produces a single Equals filter (no OR wrapper needed)
114+
$this->assertEquals('(foo=\66\6f\6f)', $query->getQuery()->getQuery());
114115
}
115116
}
116117

tests/Unit/Models/ActiveDirectory/UserTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,16 @@ public function test_reject_computer_object_class_is_a_default_scope()
142142

143143
public function test_scope_where_has_mailbox_is_applied()
144144
{
145-
$filters = User::whereHasMailbox()->getQuery()->filters;
145+
$query = User::whereHasMailbox()->getQuery()->getQuery();
146146

147-
$this->assertEquals('msExchMailboxGuid', $filters['and'][4]['attribute']);
148-
$this->assertEquals('*', $filters['and'][4]['operator']);
147+
$this->assertStringContainsString('(msExchMailboxGuid=*)', $query);
149148
}
150149

151150
public function test_scope_where_has_lockout_is_applied()
152151
{
153-
$filters = User::whereHasLockout()->getQuery()->filters;
152+
$query = User::whereHasLockout()->getQuery()->getQuery();
154153

155-
$this->assertEquals('lockoutTime', $filters['and'][4]['attribute']);
156-
$this->assertEquals('>=', $filters['and'][4]['operator']);
157-
$this->assertEquals('\31', $filters['and'][4]['value']);
154+
$this->assertStringContainsString('(lockoutTime>=\31)', $query);
158155
}
159156

160157
public function test_is_locked_out()

tests/Unit/Models/ModelHasManyTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ public function test_detaching_all()
225225

226226
public function test_only_related_with_many_relation_object_classes()
227227
{
228+
// Scopes are wrapped in their own AndGroup for isolation
228229
$this->assertEquals(
229-
'(&(|(objectclass=top)(objectclass=person)(objectclass=organizationalperson)(objectclass=user))(|(objectclass=top)(objectclass=group)))',
230+
'(&(&(|(objectclass=top)(objectclass=person)(objectclass=organizationalperson)(objectclass=user))(|(objectclass=top)(objectclass=group))))',
230231
(new ModelHasManyStubWithManyRelated)->relation()->onlyRelated()->getQuery()->getUnescapedQuery()
231232
);
232233
}

tests/Unit/Models/ModelQueryTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function test_new_query_without_scopes()
5757
$query = $model->newQueryWithoutScopes();
5858

5959
$this->assertEquals($model, $query->getModel());
60-
$this->assertEquals(['and' => [], 'or' => [], 'raw' => []], $query->getQuery()->filters);
60+
$this->assertNull($query->getQuery()->getFilter());
6161
}
6262

6363
public function test_new_query_has_connection_base_dn()
@@ -80,8 +80,9 @@ public function test_new_queries_apply_object_class_scopes()
8080
{
8181
Container::addConnection(new Connection);
8282

83+
// Scopes are wrapped in their own AndGroup for isolation
8384
$this->assertEquals(
84-
'(&(objectclass=foo)(objectclass=bar)(objectclass=baz))',
85+
'(&(&(objectclass=foo)(objectclass=bar)(objectclass=baz)))',
8586
ModelWithObjectClassStub::query()->getUnescapedQuery()
8687
);
8788
}
@@ -447,9 +448,15 @@ public function test_date_objects_are_converted_to_ldap_timestamps_in_where_clau
447448
->whereRaw('windows', '=', $datetime)
448449
->whereRaw('windowsinteger', '=', $datetime);
449450

450-
$this->assertEquals((new Timestamp('ldap'))->fromDateTime($datetime), $query->getQuery()->filters['and'][0]['value']);
451-
$this->assertEquals((new Timestamp('windows'))->fromDateTime($datetime), $query->getQuery()->filters['and'][1]['value']);
452-
$this->assertEquals((new Timestamp('windows-int'))->fromDateTime($datetime), $query->getQuery()->filters['and'][2]['value']);
451+
$ldapTimestamp = (new Timestamp('ldap'))->fromDateTime($datetime);
452+
$windowsTimestamp = (new Timestamp('windows'))->fromDateTime($datetime);
453+
$windowsIntTimestamp = (new Timestamp('windows-int'))->fromDateTime($datetime);
454+
455+
// Check that the filter string contains the converted timestamps
456+
$filterString = (string) $query->getQuery()->getFilter();
457+
$this->assertStringContainsString("(standard={$ldapTimestamp})", $filterString);
458+
$this->assertStringContainsString("(windows={$windowsTimestamp})", $filterString);
459+
$this->assertStringContainsString("(windowsinteger={$windowsIntTimestamp})", $filterString);
453460
}
454461

455462
public function test_exception_is_thrown_when_date_objects_cannot_be_converted()

tests/Unit/Models/ModelRelationTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ public function test_has_default_model()
6262

6363
public function test_query_has_no_filters()
6464
{
65-
$this->assertEquals(
66-
['and' => [], 'or' => [], 'raw' => []],
67-
(new ModelRelationTestStub)->relation()->getQuery()->getQuery()->filters
65+
$this->assertNull(
66+
(new ModelRelationTestStub)->relation()->getQuery()->getQuery()->getFilter()
6867
);
6968
}
7069

tests/Unit/Models/ModelScopeTest.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ public function test_scopes_are_applied_to_query()
5656
{
5757
$query = ModelWithGlobalScopeTestStub::query();
5858

59-
$this->assertEquals([
60-
'attribute' => 'foo',
61-
'operator' => '=',
62-
'value' => 'bar',
63-
], $query->toBase()->filters['and'][0]);
59+
$this->assertStringContainsString('(foo=bar)', $query->toBase()->getQuery());
6460
}
6561

6662
public function test_scopes_are_applied_to_pagination_request()
@@ -73,44 +69,36 @@ public function test_scopes_are_applied_to_pagination_request()
7369
->expect(['search' => []]);
7470

7571
$this->assertEmpty($query->paginate());
72+
$this->assertEmpty($query->paginate());
73+
$this->assertEmpty($query->paginate());
7674

77-
$this->assertEquals([
78-
'attribute' => 'foo',
79-
'operator' => '=',
80-
'value' => 'bar',
81-
], $query->toBase()->filters['and'][0]);
75+
$this->assertStringContainsString('(foo=bar)', $query->toBase()->getQuery());
8276
}
8377

8478
public function test_scopes_are_not_stacked_multiple_times()
8579
{
8680
$query = ModelWithGlobalScopeTestStub::query();
87-
$query->getQuery();
88-
$query->getQuery();
81+
// Call toBase() multiple times to verify scopes aren't stacked
82+
$query->toBase();
83+
$query->toBase();
8984

90-
$this->assertCount(1, $query->toBase()->filters['and']);
91-
$this->assertEquals('(foo=bar)', $query->getQuery()->getQuery());
85+
$this->assertEquals('(&(foo=bar))', $query->toBase()->getQuery());
9286
}
9387

9488
public function test_local_scopes_can_be_called()
9589
{
9690
$query = ModelWithLocalScopeTestStub::fooBar();
9791

9892
$this->assertInstanceOf(Builder::class, $query);
99-
$this->assertCount(1, $query->toBase()->filters['and']);
100-
$this->assertEquals('foo', $query->toBase()->filters['and'][0]['attribute']);
101-
$this->assertEquals('=', $query->toBase()->filters['and'][0]['operator']);
102-
$this->assertEquals('\62\61\72', $query->toBase()->filters['and'][0]['value']);
93+
$this->assertEquals('(foo=\62\61\72)', $query->toBase()->getQuery());
10394
}
10495

10596
public function test_local_scopes_accept_arguments()
10697
{
10798
$query = ModelWithLocalScopeTestStub::barBaz('zal');
10899

109100
$this->assertInstanceOf(Builder::class, $query);
110-
$this->assertCount(1, $query->toBase()->filters['and']);
111-
$this->assertEquals('bar', $query->toBase()->filters['and'][0]['attribute']);
112-
$this->assertEquals('=', $query->toBase()->filters['and'][0]['operator']);
113-
$this->assertEquals('\7a\61\6c', $query->toBase()->filters['and'][0]['value']);
101+
$this->assertEquals('(bar=\7a\61\6c)', $query->toBase()->getQuery());
114102
}
115103

116104
public function test_scopes_do_not_impact_model_refresh()

0 commit comments

Comments
 (0)