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
96 lines (69 loc) · 2.83 KB
/
FactoryTest.php
File metadata and controls
96 lines (69 loc) · 2.83 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
<?php
use PHPUnit\Framework\TestCase;
use Clue\React\SQLite\Factory;
class FactoryTest extends TestCase
{
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');
$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');
$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');
$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');
$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');
$ref->setAccessible(true);
$value = $ref->getValue($db);
chdir($original);
$this->assertEquals($original . DIRECTORY_SEPARATOR . 'users.db', $value);
}
}