-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTestCase.php
46 lines (35 loc) · 1.01 KB
/
TestCase.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
<?php
declare(strict_types=1);
namespace Yiisoft\Mutex\Pgsql\Tests;
use PDO;
use ReflectionClass;
use Yiisoft\Mutex\Pgsql\PgsqlMutex;
use function md5;
abstract class TestCase extends \PHPUnit\Framework\TestCase
{
private ?PDO $connection = null;
protected function tearDown(): void
{
$this->connection = null;
parent::setUp();
}
protected function connection(): PDO
{
if ($this->connection === null) {
$this->connection = new PDO(
'pgsql:host=127.0.0.1;dbname=yiitest',
'root',
'root-password',
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION],
);
}
return $this->connection;
}
protected function isFreeLock(PgsqlMutex $mutex, string $name): bool
{
$locks = (new ReflectionClass($mutex))
->getParentClass()
->getStaticPropertyValue('currentProcessLocks');
return !isset($locks[md5(PgsqlMutex::class . $name)]);
}
}