@@ -30,7 +30,7 @@ class MutexConcurrencyTest extends TestCase
3030 /** @var list<string> */
3131 protected static $ temporaryFiles = [];
3232 /** @var \PDO|null the pdo instance */
33- private $ pdo ;
33+ private static $ pdo ;
3434
3535 #[\Override]
3636 public static function tearDownAfterClass (): void
@@ -40,6 +40,8 @@ public static function tearDownAfterClass(): void
4040 }
4141 self ::$ temporaryFiles = [];
4242
43+ self ::$ pdo = null ;
44+
4345 parent ::tearDownAfterClass ();
4446 }
4547
@@ -52,14 +54,14 @@ public static function tearDownAfterClass(): void
5254 *
5355 * @return \PDO the PDO
5456 */
55- private function getPDO (string $ dsn , string $ user , string $ password ): \PDO
57+ private static function getPDO (string $ dsn , string $ user , string $ password ): \PDO
5658 {
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 );
6062 }
6163
62- return $ this -> pdo ;
64+ return self :: $ pdo ;
6365 }
6466
6567 /**
@@ -114,7 +116,7 @@ public function testHighContention(callable $code, callable $mutexFactory): void
114116 *
115117 * @return iterable<list<mixed>>
116118 */
117- public function provideHighContentionCases (): iterable
119+ public static function provideHighContentionCases (): iterable
118120 {
119121 $ cases = array_map (static function (array $ mutexFactory ): array {
120122 $ filename = tempnam (sys_get_temp_dir (), 'php-lock-high-contention ' );
@@ -136,8 +138,8 @@ static function (int $increment) use ($filename): int {
136138 ];
137139 }, static ::provideExecutionIsSerializedWhenLockedCases ());
138140
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 );
141143
142144 $ options = ['mysql ' => 'engine=InnoDB ' ];
143145 $ option = $ options [$ vendor ] ?? '' ;
@@ -148,15 +150,15 @@ static function (int $increment) use ($filename): int {
148150 $ pdo ->exec ('INSERT INTO counter VALUES (1, 0) ' );
149151 $ pdo ->commit ();
150152
151- $ this -> pdo = null ;
153+ self :: $ pdo = null ;
152154
153155 $ cases [$ vendor ] = [
154- function ($ increment ) use ($ dsn , $ user , $ password ) {
156+ static function ($ increment ) use ($ dsn , $ user , $ password ) {
155157 // This prevents using a closed connection from a child.
156158 if ($ increment == 0 ) {
157- $ this -> pdo = null ;
159+ self :: $ pdo = null ;
158160 }
159- $ pdo = $ this -> getPDO ($ dsn , $ user , $ password );
161+ $ pdo = self :: getPDO ($ dsn , $ user , $ password );
160162 $ id = 1 ;
161163 $ select = $ pdo ->prepare ('SELECT counter FROM counter WHERE id = ? FOR UPDATE ' );
162164 $ select ->execute ([$ id ]);
@@ -169,9 +171,9 @@ function ($increment) use ($dsn, $user, $password) {
169171
170172 return $ counter ;
171173 },
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 );
175177
176178 return new TransactionalMutex ($ pdo , $ timeout );
177179 },
0 commit comments