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