-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Expand file tree
/
Copy pathDbMutexTest.php
More file actions
72 lines (62 loc) · 1.94 KB
/
DbMutexTest.php
File metadata and controls
72 lines (62 loc) · 1.94 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
declare(strict_types=1);
namespace yiiunit\framework\mutex;
use Yii;
use yii\base\InvalidConfigException;
use yii\db\Connection;
use yiiunit\TestCase;
/**
* @group mutex
* @group db
*/
class DbMutexTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->mockApplication([
'components' => [
'db' => [
'class' => Connection::class,
'dsn' => 'sqlite::memory:',
],
],
]);
}
public function testDbPropertyDefaultValue(): void
{
$mutex = $this->getMockForAbstractClass('yii\mutex\DbMutex');
$this->assertInstanceOf(Connection::class, $mutex->db);
}
public function testDbPropertyResolvesFromApplicationComponent(): void
{
$mutex = $this->getMockForAbstractClass('yii\mutex\DbMutex');
$this->assertSame(Yii::$app->db, $mutex->db);
}
public function testDbPropertyAcceptsConnectionObject(): void
{
$connection = new Connection(['dsn' => 'sqlite::memory:']);
$mutex = $this->getMockForAbstractClass('yii\mutex\DbMutex', [['db' => $connection]]);
$this->assertSame($connection, $mutex->db);
}
public function testDbPropertyAcceptsConfigArray(): void
{
$mutex = $this->getMockForAbstractClass('yii\mutex\DbMutex', [[
'db' => [
'class' => Connection::class,
'dsn' => 'sqlite::memory:',
],
]]);
$this->assertInstanceOf(Connection::class, $mutex->db);
}
public function testThrowsExceptionForInvalidDb(): void
{
$this->expectException(InvalidConfigException::class);
$this->getMockForAbstractClass('yii\mutex\DbMutex', [['db' => 'nonExistingComponent']]);
}
}