|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of tenside/core. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Christian Schiffler <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* This project is provided in good faith and hope to be usable by anyone. |
|
12
|
|
|
* |
|
13
|
|
|
* @package tenside/core |
|
14
|
|
|
* @author Christian Schiffler <[email protected]> |
|
15
|
|
|
* @copyright 2015 Christian Schiffler <[email protected]> |
|
16
|
|
|
* @license https://github.com/tenside/core/blob/master/LICENSE MIT |
|
17
|
|
|
* @link https://github.com/tenside/core |
|
18
|
|
|
* @filesource |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Tenside\Core\SelfTest\Cli; |
|
22
|
|
|
|
|
23
|
|
|
use Symfony\Component\Process\Process; |
|
24
|
|
|
use Tenside\Core\SelfTest\AbstractSelfTest; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* This class tests that a valid php-cli binary is available. |
|
28
|
|
|
*/ |
|
29
|
|
|
abstract class AbstractSelfTestCli extends AbstractSelfTest |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* The interpreter to use. |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
private $interpreter; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Check that the interpreter is available. |
|
40
|
|
|
* |
|
41
|
|
|
* @return bool |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function hasInterpreter() |
|
44
|
|
|
{ |
|
45
|
|
|
return (null !== ($this->interpreter = $this->getAutoConfig()->getPhpCliBinary())); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Runs the passed test script through the php cli and returns the output. |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $testScript The test script to run. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $arguments Optional cli arguments to use. |
|
54
|
|
|
* |
|
55
|
|
|
* @return null|string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function testCliRuntime($testScript, $arguments = '') |
|
58
|
|
|
{ |
|
59
|
|
|
if ($arguments) { |
|
60
|
|
|
$arguments = escapeshellarg($arguments); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$process = new Process( |
|
64
|
|
|
sprintf( |
|
65
|
|
|
'%s %s %s', |
|
66
|
|
|
escapeshellcmd($this->interpreter), |
|
67
|
|
|
$arguments, |
|
68
|
|
|
escapeshellarg('-r ' . $testScript) |
|
69
|
|
|
) |
|
70
|
|
|
); |
|
71
|
|
|
|
|
72
|
|
|
if (0 !== $process->run()) { |
|
73
|
|
|
return null; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $process->getOutput(); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|