-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathContainsTest.php
67 lines (56 loc) · 2.2 KB
/
ContainsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace tests\RavenDB\Test\Client\ContainsTest;
use RavenDB\Type\Collection;
use RavenDB\Type\StringList;
use tests\RavenDB\RemoteTestBase;
use tests\RavenDB\Test\Client\ContainsTest\Entity\UserWithFavs;
class ContainsTest extends RemoteTestBase
{
public function testContainsTest(): void
{
$store = $this->getDocumentStore();
try {
$session = $store->openSession();
try {
$userCreator = function ($name, $favs) use ($session) {
$user = new UserWithFavs();
$user->setName($name);
$user->setFavourites($favs);
$session->store($user);
};
$userCreator("John", StringList::fromArray(["java", "c#"]));
$userCreator("Tarzan", StringList::fromArray(["java", "go"]));
$userCreator("Jane", StringList::fromArray(["pascal"]));
$session->saveChanges();
} finally {
$session->close();
}
try {
$pascalOrGoDeveloperNames = $session
->query(UserWithFavs::class)
->containsAny("favourites", Collection::fromArray(["pascal", "go"]))
->selectFields(null, "name")
->toList();
$this->assertCount(2, $pascalOrGoDeveloperNames);
$this->assertContains("Jane", $pascalOrGoDeveloperNames);
$this->assertContains("Tarzan", $pascalOrGoDeveloperNames);
} finally {
$session->close();
}
try {
$javaDevelopers = $session
->query(UserWithFavs::class)
->containsAll("favourites", Collection::fromArray(["java"]))
->selectFields(null, "name")
->toList();
$this->assertCount(2, $javaDevelopers);
$this->assertContains("John", $javaDevelopers);
$this->assertContains("Tarzan", $javaDevelopers);
} finally {
$session->close();
}
} finally {
$store->close();
}
}
}