Skip to content

Commit d7bd4b9

Browse files
committed
Add exists tests
1 parent d245f24 commit d7bd4b9

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

tests/Unit/Models/CollectionTest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,84 @@
99

1010
class CollectionTest extends TestCase
1111
{
12+
public function test_exists_with_no_parameters()
13+
{
14+
$collection = new Collection;
15+
16+
$this->assertFalse(
17+
$collection->exists()
18+
);
19+
20+
$collection = new Collection([new User]);
21+
22+
$this->assertTrue(
23+
$collection->exists()
24+
);
25+
}
26+
27+
public function test_exists_with_dn()
28+
{
29+
$user = new User(['dn' => 'cn=John Doe']);
30+
31+
$collection = new Collection([$user]);
32+
33+
$this->assertTrue(
34+
$collection->exists('cn=John Doe')
35+
);
36+
37+
$this->assertFalse(
38+
$collection->exists('cn=Jane Doe')
39+
);
40+
}
41+
42+
public function test_exists_with_multiple_dns()
43+
{
44+
$user = new User(['dn' => 'cn=John Doe']);
45+
46+
$collection = new Collection([$user]);
47+
48+
$this->assertTrue(
49+
$collection->exists(['cn=John Doe'])
50+
);
51+
52+
$this->assertFalse(
53+
$collection->exists(['cn=Jane Doe', 'cn=Foo Bar'])
54+
);
55+
}
56+
57+
public function test_exists_with_model()
58+
{
59+
$user = new User(['dn' => 'cn=John Doe']);
60+
61+
$collection = new Collection([$user]);
62+
63+
$this->assertTrue(
64+
$collection->exists($user)
65+
);
66+
67+
$this->assertFalse(
68+
$collection->exists(new User(['dn' => 'cn=Jane Doe']))
69+
);
70+
}
71+
72+
public function test_exists_with_model_collection()
73+
{
74+
$user = new User(['dn' => 'cn=John Doe']);
75+
76+
$collection = new Collection([$user]);
77+
78+
$this->assertTrue(
79+
$collection->exists(new Collection([$user]))
80+
);
81+
82+
$this->assertFalse(
83+
$collection->exists(new Collection([
84+
new User(['dn' => 'cn=Jane Doe']),
85+
new User(['dn' => 'cn=Foo Bar']),
86+
]))
87+
);
88+
}
89+
1290
public function test_contains_with_closure()
1391
{
1492
$user = new User(['cn' => 'John Doe']);

0 commit comments

Comments
 (0)