forked from clue/reactphp-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactoryTest.php
More file actions
153 lines (117 loc) · 4.65 KB
/
FactoryTest.php
File metadata and controls
153 lines (117 loc) · 4.65 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
namespace Clue\Tests\React\SQLite;
use PHPUnit\Framework\TestCase;
use Clue\React\SQLite\Factory;
class FactoryTest extends TestCase
{
public function testConstructWithoutLoopAssignsLoopAutomatically()
{
$factory = new Factory();
$ref = new \ReflectionProperty($factory, 'loop');
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$loop = $ref->getValue($factory);
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
}
public function testConstructWitLoopAndBinaryAssignsBothVariables()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$factory = new Factory($loop, 'php6.0');
$ref = new \ReflectionProperty($factory, 'loop');
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$this->assertSame($loop, $ref->getValue($factory));
$ref = new \ReflectionProperty($factory, 'bin');
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$this->assertSame('php6.0', $ref->getValue($factory));
}
public function testCtorThrowsForInvalidLoop()
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5.2+
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
} else {
// legacy PHPUnit
$this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
}
new Factory('loop');
}
public function testLoadLazyReturnsDatabaseImmediately()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$factory = new Factory($loop);
$db = $factory->openLazy(':memory:');
$this->assertInstanceOf('Clue\React\SQLite\DatabaseInterface', $db);
}
public function testLoadLazyWithIdleOptionsReturnsDatabaseWithIdleTimeApplied()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$factory = new Factory($loop);
$db = $factory->openLazy(':memory:', null, ['idle' => 10.0]);
$ref = new \ReflectionProperty($db, 'idlePeriod');
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$value = $ref->getValue($db);
$this->assertEquals(10.0, $value);
}
public function testLoadLazyWithAbsolutePathWillBeUsedAsIs()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$factory = new Factory($loop);
$db = $factory->openLazy(__DIR__ . '/users.db');
$ref = new \ReflectionProperty($db, 'filename');
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$value = $ref->getValue($db);
$this->assertEquals(__DIR__ . '/users.db', $value);
}
public function testLoadLazyWithMemoryPathWillBeUsedAsIs()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$factory = new Factory($loop);
$db = $factory->openLazy(':memory:');
$ref = new \ReflectionProperty($db, 'filename');
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$value = $ref->getValue($db);
$this->assertEquals(':memory:', $value);
}
public function testLoadLazyWithEmptyPathWillBeUsedAsIs()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$factory = new Factory($loop);
$db = $factory->openLazy('');
$ref = new \ReflectionProperty($db, 'filename');
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$value = $ref->getValue($db);
$this->assertEquals('', $value);
}
public function testLoadLazyWithRelativePathWillBeResolvedWhenConstructingAndWillNotBeAffectedByChangingDirectory()
{
$original = getcwd();
if ($original === false) {
$this->markTestSkipped('Unable to detect current working directory');
}
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$factory = new Factory($loop);
$db = $factory->openLazy('users.db');
chdir('../');
$ref = new \ReflectionProperty($db, 'filename');
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$value = $ref->getValue($db);
chdir($original);
$this->assertEquals($original . DIRECTORY_SEPARATOR . 'users.db', $value);
}
}