forked from clue/reactphp-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionalFactoryTest.php
More file actions
92 lines (74 loc) · 2.8 KB
/
FunctionalFactoryTest.php
File metadata and controls
92 lines (74 loc) · 2.8 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
<?php
namespace Clue\Tests\React\SQLite;
use Clue\React\SQLite\DatabaseInterface;
use Clue\React\SQLite\Factory;
use PHPUnit\Framework\TestCase;
use React\EventLoop\Loop;
class FunctionalFactoryTest extends TestCase
{
public function testOpenReturnsPromiseWhichFulfillsWithConnectionForMemoryPath()
{
$factory = new Factory();
$promise = $factory->open(':memory:');
$promise->then(function (DatabaseInterface $db) {
echo 'open.';
$db->on('close', function () {
echo 'close.';
});
$db->close();
}, function (\Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
$this->expectOutputString('open.close.');
Loop::run();
}
public function testOpenReturnsPromiseWhichFulfillsWithConnectionForMemoryPathAndExplicitPhpBinary()
{
$factory = new Factory(null, PHP_BINARY);
$promise = $factory->open(':memory:');
$promise->then(function (DatabaseInterface $db) {
echo 'open.';
$db->on('close', function () {
echo 'close.';
});
$db->close();
}, function (\Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
$this->expectOutputString('open.close.');
Loop::run();
}
public function testOpenReturnsPromiseWhichRejectsWithExceptionWhenPathIsInvalid()
{
$factory = new Factory();
$promise = $factory->open('/dev/foo/bar');
$promise->then(function (DatabaseInterface $db) {
echo 'open.';
$db->close();
}, function (\Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
// Unable to open database: unable to open database file
// Unable to open database: bad parameter or other API misuse (only between PHP 7.4.0 and PHP 7.4.7 as per https://3v4l.org/9SjgK)
$this->expectOutputRegex('/^' . preg_quote('Error: Unable to open database: ', '/') . '.*$/');
Loop::run();
}
public function testOpenReturnsPromiseWhichRejectsWithExceptionWhenExplicitPhpBinaryExitsImmediately()
{
$factory = new Factory(null, 'echo');
$ref = new \ReflectionProperty($factory, 'useSocket');
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($factory, true);
$promise = $factory->open(':memory:');
$promise->then(function (DatabaseInterface $db) {
echo 'open.';
$db->close();
}, function (\Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
$this->expectOutputString('Error: Database process died while setting up connection' . PHP_EOL);
Loop::run();
}
}