forked from clue/reactphp-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionalExampleTest.php
More file actions
78 lines (57 loc) · 2.66 KB
/
FunctionalExampleTest.php
File metadata and controls
78 lines (57 loc) · 2.66 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
<?php
namespace Clue\Tests\React\SQLite;
use PHPUnit\Framework\TestCase;
class FunctionalExampleTest extends TestCase
{
public function testQueryExampleReturnsDefaultValue()
{
$output = $this->execExample(escapeshellarg(PHP_BINARY) . ' query.php');
$this->assertEquals('value' . "\n" . '42' . "\n", $output);
}
public function testQueryExampleReturnsCalculatedValueFromPlaceholderVariables()
{
$output = $this->execExample(escapeshellarg(PHP_BINARY) . ' query.php "SELECT ?+? AS result" 1 2');
$this->assertEquals('result' . "\n" . '3' . "\n", $output);
}
public function testQueryExampleExecutedWithCgiReturnsDefaultValueAfterContentTypeHeader()
{
if (!$this->canExecute('php-cgi --version')) {
$this->markTestSkipped('Unable to execute "php-cgi"');
}
$output = $this->execExample('php-cgi -dopcache.jit=off query.php');
$this->assertStringEndsWith("\n\n" . 'value' . "\n" . '42' . "\n", $output);
}
public function testQueryExampleWithOpenBasedirRestrictedReturnsDefaultValue()
{
$output = $this->execExample(escapeshellarg(PHP_BINARY) . ' -dopen_basedir=' . escapeshellarg(dirname(__DIR__)) . ' query.php');
$this->assertEquals('value' . "\n" . '42' . "\n", $output);
}
public function testQueryExampleWithOpenBasedirRestrictedAndAdditionalFileDescriptorReturnsDefaultValue()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Not supported on Windows');
}
$output = $this->execExample(escapeshellarg(PHP_BINARY) . ' -dopen_basedir=' . escapeshellarg(dirname(__DIR__)) . ' query.php 3</dev/null');
$this->assertEquals('value' . "\n" . '42' . "\n", $output);
}
public function testQueryExampleExecutedWithCgiAndOpenBasedirRestrictedRunsDefaultPhpAndReturnsDefaultValueAfterContentTypeHeader()
{
if (!$this->canExecute('php-cgi --version') || !$this->canExecute('php --version')) {
$this->markTestSkipped('Unable to execute "php-cgi" or "php"');
}
$output = $this->execExample('php-cgi -dopcache.jit=off -dopen_basedir=' . escapeshellarg(dirname(__DIR__)) . ' query.php');
$this->assertStringEndsWith("\n\n" . 'value' . "\n" . '42' . "\n", $output);
}
private function canExecute($command)
{
$code = 1;
$null = DIRECTORY_SEPARATOR === '\\' ? 'NUL' : '/dev/null';
system("$command >$null 2>$null", $code);
return $code === 0;
}
private function execExample($command)
{
chdir(__DIR__ . '/../examples/');
return str_replace("\r\n", "\n", shell_exec($command));
}
}