mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-17 20:34:51 +08:00
69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace SPC\Tests\util;
|
|
|
|
use SPC\exception\RuntimeException;
|
|
use SPC\util\WindowsCmd;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
final class WindowsCmdTest extends TestBase
|
|
{
|
|
public function testConstructorOnUnix(): void
|
|
{
|
|
if (PHP_OS_FAMILY === 'Windows') {
|
|
$this->markTestSkipped('This test is for Unix systems only');
|
|
}
|
|
|
|
$this->expectException(RuntimeException::class);
|
|
$this->expectExceptionMessage('Only windows can use WindowsCmd');
|
|
|
|
new WindowsCmd();
|
|
}
|
|
|
|
/**
|
|
* @dataProvider commandProvider
|
|
*/
|
|
public function testExecWithResult(string $command): void
|
|
{
|
|
if (PHP_OS_FAMILY !== 'Windows') {
|
|
$this->markTestSkipped('This test is for Windows systems only');
|
|
}
|
|
|
|
$cmd = $this->createWindowsCmd();
|
|
[$code, $output] = $cmd->execWithResult($command);
|
|
|
|
$this->assertIsInt($code);
|
|
$this->assertEquals(0, $code);
|
|
$this->assertIsArray($output);
|
|
$this->assertNotEmpty($output);
|
|
}
|
|
|
|
public function testExecWithResultWithLog(): void
|
|
{
|
|
if (PHP_OS_FAMILY !== 'Windows') {
|
|
$this->markTestSkipped('This test is for Windows systems only');
|
|
}
|
|
|
|
$cmd = $this->createWindowsCmd();
|
|
[$code, $output] = $cmd->execWithResult('echo test', false);
|
|
|
|
$this->assertIsInt($code);
|
|
$this->assertIsArray($output);
|
|
$this->assertEquals(0, $code);
|
|
$this->assertEquals(['test'], $output);
|
|
}
|
|
|
|
public static function commandProvider(): array
|
|
{
|
|
return [
|
|
'echo-command' => ['echo test'],
|
|
'dir-command' => ['dir'],
|
|
'cd-command' => ['cd'],
|
|
];
|
|
}
|
|
}
|