5
5
namespace Doctrine \Tests \ORM \Functional \Locking ;
6
6
7
7
use DateTime ;
8
+ use Doctrine \DBAL \Connection ;
8
9
use Doctrine \DBAL \LockMode ;
9
10
use Doctrine \ORM \Mapping \Column ;
10
11
use Doctrine \ORM \Mapping \DiscriminatorColumn ;
24
25
25
26
class OptimisticTest extends OrmFunctionalTestCase
26
27
{
28
+ /** @var Connection */
29
+ private $ _conn ;
30
+
27
31
protected function setUp (): void
28
32
{
29
33
parent ::setUp ();
34
+ $ this ->_conn = $ this ->_em ->getConnection ();
35
+ }
30
36
31
- try {
32
- $ this ->_schemaTool ->createSchema (
33
- [
34
- $ this ->_em ->getClassMetadata (OptimisticJoinedParent::class),
35
- $ this ->_em ->getClassMetadata (OptimisticJoinedChild::class),
36
- $ this ->_em ->getClassMetadata (OptimisticStandard::class),
37
- $ this ->_em ->getClassMetadata (OptimisticTimestamp::class),
38
- ]
39
- );
40
- } catch (Exception $ e ) {
41
- // Swallow all exceptions. We do not test the schema tool here.
42
- }
37
+ private function createSchema (): void
38
+ {
39
+ $ this ->_schemaTool ->createSchema ([
40
+ $ this ->_em ->getClassMetadata (OptimisticJoinedParent::class),
41
+ $ this ->_em ->getClassMetadata (OptimisticJoinedChild::class),
42
+ $ this ->_em ->getClassMetadata (OptimisticStandard::class),
43
+ $ this ->_em ->getClassMetadata (OptimisticTimestamp::class),
44
+ ]);
45
+ }
43
46
44
- $ this ->_conn = $ this ->_em ->getConnection ();
47
+ private function dropSchema (): void
48
+ {
49
+ $ this ->_schemaTool ->dropSchema ([
50
+ $ this ->_em ->getClassMetadata (OptimisticJoinedParent::class),
51
+ $ this ->_em ->getClassMetadata (OptimisticJoinedChild::class),
52
+ $ this ->_em ->getClassMetadata (OptimisticStandard::class),
53
+ $ this ->_em ->getClassMetadata (OptimisticTimestamp::class),
54
+ ]);
45
55
}
46
56
47
57
public function testJoinedChildInsertSetsInitialVersionValue (): OptimisticJoinedChild
48
58
{
59
+ $ this ->createSchema ();
49
60
$ test = new OptimisticJoinedChild ();
50
61
51
62
$ test ->name = 'child ' ;
@@ -83,10 +94,13 @@ public function testJoinedChildFailureThrowsException(OptimisticJoinedChild $chi
83
94
} catch (OptimisticLockException $ e ) {
84
95
self ::assertSame ($ test , $ e ->getEntity ());
85
96
}
97
+
98
+ $ this ->dropSchema ();
86
99
}
87
100
88
101
public function testJoinedParentInsertSetsInitialVersionValue (): OptimisticJoinedParent
89
102
{
103
+ $ this ->createSchema ();
90
104
$ test = new OptimisticJoinedParent ();
91
105
92
106
$ test ->name = 'parent ' ;
@@ -123,10 +137,14 @@ public function testJoinedParentFailureThrowsException(OptimisticJoinedParent $p
123
137
} catch (OptimisticLockException $ e ) {
124
138
self ::assertSame ($ test , $ e ->getEntity ());
125
139
}
140
+
141
+ $ this ->dropSchema ();
126
142
}
127
143
128
144
public function testMultipleFlushesDoIncrementalUpdates (): void
129
145
{
146
+ $ this ->createSchema ();
147
+
130
148
$ test = new OptimisticStandard ();
131
149
132
150
for ($ i = 0 ; $ i < 5 ; $ i ++) {
@@ -138,10 +156,14 @@ public function testMultipleFlushesDoIncrementalUpdates(): void
138
156
self ::assertIsInt ($ test ->getVersion ());
139
157
self ::assertEquals ($ i + 1 , $ test ->getVersion ());
140
158
}
159
+
160
+ $ this ->dropSchema ();
141
161
}
142
162
143
163
public function testStandardInsertSetsInitialVersionValue (): OptimisticStandard
144
164
{
165
+ $ this ->createSchema ();
166
+
145
167
$ test = new OptimisticStandard ();
146
168
147
169
$ test ->name = 'test ' ;
@@ -179,10 +201,13 @@ public function testStandardFailureThrowsException(OptimisticStandard $entity):
179
201
} catch (OptimisticLockException $ e ) {
180
202
self ::assertSame ($ test , $ e ->getEntity ());
181
203
}
204
+
205
+ $ this ->dropSchema ();
182
206
}
183
207
184
208
public function testLockWorksWithProxy (): void
185
209
{
210
+ $ this ->createSchema ();
186
211
$ test = new OptimisticStandard ();
187
212
$ test ->name = 'test ' ;
188
213
@@ -195,10 +220,12 @@ public function testLockWorksWithProxy(): void
195
220
$ this ->_em ->lock ($ proxy , LockMode::OPTIMISTIC , 1 );
196
221
197
222
$ this ->addToAssertionCount (1 );
223
+ $ this ->dropSchema ();
198
224
}
199
225
200
226
public function testOptimisticTimestampSetsDefaultValue (): OptimisticTimestamp
201
227
{
228
+ $ this ->createSchema ();
202
229
$ test = new OptimisticTimestamp ();
203
230
204
231
$ test ->name = 'Testing ' ;
@@ -274,6 +301,8 @@ public function testOptimisticTimestampLockFailureThrowsException(OptimisticTime
274
301
275
302
self ::assertNotNull ($ caughtException , 'No OptimisticLockingException was thrown ' );
276
303
self ::assertSame ($ test , $ caughtException ->getEntity ());
304
+
305
+ $ this ->dropSchema ();
277
306
}
278
307
}
279
308
0 commit comments