@@ -30,7 +30,7 @@ class MutexConcurrencyTest extends TestCase
30
30
/** @var list<string> */
31
31
protected static $ temporaryFiles = [];
32
32
/** @var \PDO|null the pdo instance */
33
- private $ pdo ;
33
+ private static $ pdo ;
34
34
35
35
#[\Override]
36
36
public static function tearDownAfterClass (): void
@@ -40,6 +40,8 @@ public static function tearDownAfterClass(): void
40
40
}
41
41
self ::$ temporaryFiles = [];
42
42
43
+ self ::$ pdo = null ;
44
+
43
45
parent ::tearDownAfterClass ();
44
46
}
45
47
@@ -52,14 +54,14 @@ public static function tearDownAfterClass(): void
52
54
*
53
55
* @return \PDO the PDO
54
56
*/
55
- private function getPDO (string $ dsn , string $ user , string $ password ): \PDO
57
+ private static function getPDO (string $ dsn , string $ user , string $ password ): \PDO
56
58
{
57
- if ($ this -> pdo === null ) {
58
- $ this -> pdo = new \PDO ($ dsn , $ user , $ password );
59
- $ this -> pdo ->setAttribute (\PDO ::ATTR_ERRMODE , \PDO ::ERRMODE_EXCEPTION );
59
+ if (self :: $ pdo === null ) {
60
+ self :: $ pdo = new \PDO ($ dsn , $ user , $ password );
61
+ self :: $ pdo ->setAttribute (\PDO ::ATTR_ERRMODE , \PDO ::ERRMODE_EXCEPTION );
60
62
}
61
63
62
- return $ this -> pdo ;
64
+ return self :: $ pdo ;
63
65
}
64
66
65
67
/**
@@ -114,7 +116,7 @@ public function testHighContention(callable $code, callable $mutexFactory): void
114
116
*
115
117
* @return iterable<list<mixed>>
116
118
*/
117
- public function provideHighContentionCases (): iterable
119
+ public static function provideHighContentionCases (): iterable
118
120
{
119
121
$ cases = array_map (static function (array $ mutexFactory ): array {
120
122
$ filename = tempnam (sys_get_temp_dir (), 'php-lock-high-contention ' );
@@ -136,8 +138,8 @@ static function (int $increment) use ($filename): int {
136
138
];
137
139
}, static ::provideExecutionIsSerializedWhenLockedCases ());
138
140
139
- $ addPDO = function ($ dsn , $ user , $ password , $ vendor ) use (&$ cases ) {
140
- $ pdo = $ this -> getPDO ($ dsn , $ user , $ password );
141
+ $ addPDO = static function ($ dsn , $ user , $ password , $ vendor ) use (&$ cases ) {
142
+ $ pdo = self :: getPDO ($ dsn , $ user , $ password );
141
143
142
144
$ options = ['mysql ' => 'engine=InnoDB ' ];
143
145
$ option = $ options [$ vendor ] ?? '' ;
@@ -148,15 +150,15 @@ static function (int $increment) use ($filename): int {
148
150
$ pdo ->exec ('INSERT INTO counter VALUES (1, 0) ' );
149
151
$ pdo ->commit ();
150
152
151
- $ this -> pdo = null ;
153
+ self :: $ pdo = null ;
152
154
153
155
$ cases [$ vendor ] = [
154
- function ($ increment ) use ($ dsn , $ user , $ password ) {
156
+ static function ($ increment ) use ($ dsn , $ user , $ password ) {
155
157
// This prevents using a closed connection from a child.
156
158
if ($ increment == 0 ) {
157
- $ this -> pdo = null ;
159
+ self :: $ pdo = null ;
158
160
}
159
- $ pdo = $ this -> getPDO ($ dsn , $ user , $ password );
161
+ $ pdo = self :: getPDO ($ dsn , $ user , $ password );
160
162
$ id = 1 ;
161
163
$ select = $ pdo ->prepare ('SELECT counter FROM counter WHERE id = ? FOR UPDATE ' );
162
164
$ select ->execute ([$ id ]);
@@ -169,9 +171,9 @@ function ($increment) use ($dsn, $user, $password) {
169
171
170
172
return $ counter ;
171
173
},
172
- function ($ timeout = 3 ) use ($ dsn , $ user , $ password ) {
173
- $ this -> pdo = null ;
174
- $ pdo = $ this -> getPDO ($ dsn , $ user , $ password );
174
+ static function ($ timeout = 3 ) use ($ dsn , $ user , $ password ) {
175
+ self :: $ pdo = null ;
176
+ $ pdo = self :: getPDO ($ dsn , $ user , $ password );
175
177
176
178
return new TransactionalMutex ($ pdo , $ timeout );
177
179
},
0 commit comments