-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTrackEntityTest.php
109 lines (93 loc) · 3.25 KB
/
TrackEntityTest.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace tests\RavenDB\Test\Client;
use Exception;
use RavenDB\Exceptions\Documents\Session\NonUniqueObjectException;
use RavenDB\Exceptions\IllegalStateException;
use tests\RavenDB\Infrastructure\Entity\User;
use tests\RavenDB\RemoteTestBase;
use Throwable;
// !status: DONE
class TrackEntityTest extends RemoteTestBase
{
public function testDeletingEntityThatIsNotTrackedShouldThrow(): void
{
$store = $this->getDocumentStore();
try {
$session = $store->openSession();
try {
try {
$session->delete(new User());
throw new Exception('It should throw exception before reaching this code');
} catch (Throwable $exception) {
$this->assertInstanceOf(IllegalStateException::class, $exception);
$this->assertStringEndsWith("is not associated with the session, cannot delete unknown entity instance", $exception->getMessage());
}
} finally {
$session->close();
}
} finally {
$store->close();
}
}
public function testLoadingDeletedDocumentShouldReturnNull(): void
{
$store = $this->getDocumentStore();
try {
$session = $store->openSession();
try {
$user1 = new User();
$user1->setName("John");
$user1->setId("users/1");
$user2 = new User();
$user2->setName("Jonathan");
$user2->setId("users/2");
$session->store($user1);
$session->store($user2);
$session->saveChanges();
} finally {
$session->close();
}
$session = $store->openSession();
try {
$session->delete("users/1");
$session->delete("users/2");
$session->saveChanges();
} finally {
$session->close();
}
$session = $store->openSession();
try {
$this->assertNull($session->load(User::class, "users/1"));
$this->assertNull($session->load(User::class, "users/2"));
} finally {
$session->close();
}
} finally {
$store->close();
}
}
public function testStoringDocumentWithTheSameIdInTheSameSessionShouldThrow(): void
{
$store = $this->getDocumentStore();
try {
$session = $store->openSession();
try {
$user = new User();
$user->setId("users/1");
$user->setName("User1");
$session->store($user);
$session->saveChanges();
$newUser = new User();
$newUser->setName("User2");
$newUser->setId("users/1");
$this->expectException(NonUniqueObjectException::class);
$this->expectExceptionMessage("Attempted to associate a different object with id 'users/1'");
$session->store($newUser);
} finally {
$session->close();
}
} finally {
$store->close();
}
}
}