| 1 |
<?php |
| 2 |
namespace ExecWithFallback\Tests; |
| 3 |
|
| 4 |
use PHPUnit\Framework\TestCase; |
| 5 |
use ExecWithFallback\Availability; |
| 6 |
|
| 7 |
class AvailabilityTest extends TestCase |
| 8 |
{ |
| 9 |
|
| 10 |
public function testMethodAvailable() |
| 11 |
{ |
| 12 |
$methods = ['exec', 'passthru', 'popen', 'proc_open', 'shell_exec']; |
| 13 |
$anyAvailable = false; |
| 14 |
$anyOtherThanShellExecAvailable = false; |
| 15 |
foreach ($methods as $method) { |
| 16 |
if (function_exists($method)) { |
| 17 |
$anyAvailable = true; |
| 18 |
if ($method == 'shell_exec') { |
| 19 |
$this->assertTrue(Availability::methodAvailable($method, false)); |
| 20 |
$this->assertFalse(Availability::methodAvailable($method, true)); |
| 21 |
$this->assertFalse(Availability::methodAvailable($method)); |
| 22 |
} else { |
| 23 |
$anyOtherThanShellExecAvailable = true; |
| 24 |
$this->assertTrue(Availability::methodAvailable($method)); |
| 25 |
} |
| 26 |
} else { |
| 27 |
$this->assertFalse(Availability::methodAvailable($method)); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
$this->assertSame($anyAvailable, Availability::anyAvailable(false)); |
| 32 |
$this->assertSame($anyOtherThanShellExecAvailable, Availability::anyAvailable(true)); |
| 33 |
$this->assertSame($anyOtherThanShellExecAvailable, Availability::anyAvailable()); |
| 34 |
} |
| 35 |
} |
| 36 |
|