-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
executable file
·31 lines (23 loc) · 1.06 KB
/
test.php
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
#!/usr/bin/php
<?php
use Symfony\Component\Process\Process;
require __DIR__ . "/vendor/autoload.php";
define('PHANTOM_CMD', 'docker run -v ' . __DIR__ . '/js:/mnt/test cmfatih/phantomjs /usr/bin/phantomjs /mnt/test/');
define('PROCESS_TIMEOUT', 2);
executeTest('Test execute non existent js', 'non-existent.js');
executeTest('Test failure exit code', 'return-failure-exit-code.js');
// cannot terminate process
//executeTest('Test syntax error js', 'syntax-error.js');
executeTest('Test successful js', 'success.js');
executeTest('Test load file from js', 'load-file.js');
function executeTest($title, $jsFile)
{
echo $title . PHP_EOL . str_repeat('-', 20) . PHP_EOL;
$process = new Process(PHANTOM_CMD . $jsFile);
$process->setTimeout(PROCESS_TIMEOUT);
$process->run();
echo 'Successful: ' . (int) $process->isSuccessful() . PHP_EOL;
echo 'Process exit code: ' . $process->getExitCode() . PHP_EOL;
echo 'Process stderr: ' . PHP_EOL . $process->getErrorOutput() . PHP_EOL;
echo 'Process stdout: ' . PHP_EOL . $process->getOutput() . PHP_EOL;
}