mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
* code refactoring (adds Exec class to centralise proc_open like calls). * bump phpunit to ^11.0, as this is the last release that supports php8.2. Note, there is not (yet?) a phpunit release for php8.2 that fixes PKSA-z3gr-8qht-p93v or PKSA-5jz8-6tcw-pbk4, so ignore them for now in composer.json
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ExecTest extends TestCase
|
|
{
|
|
public function testArrayCommandSuccess()
|
|
{
|
|
$p = Exec::run(["ls", "/etc"]);
|
|
$this->assertEquals(0, $p->retval);
|
|
$this->assertEquals("", $p->stderr);
|
|
$this->assertNotEmpty($p->stdout);
|
|
}
|
|
|
|
public function testArrayCommandInvalidArg()
|
|
{
|
|
$p = Exec::run(["ls", "/etcasdasdasd"]);
|
|
$this->assertEquals(2, $p->retval);
|
|
$this->assertEquals("ls: cannot access '/etcasdasdasd': No such file or directory\n", $p->stderr);
|
|
$this->assertEmpty($p->stdout);
|
|
}
|
|
|
|
|
|
public function testStringCommandNotFound()
|
|
{
|
|
$p = Exec::run("lsasdasdasdasdasd /etc");
|
|
$this->assertEquals(127, $p->retval);
|
|
$this->assertEquals("sh: 1: lsasdasdasdasdasd: not found\n", $p->stderr);
|
|
$this->assertEmpty($p->stdout);
|
|
}
|
|
|
|
public function testStringCommandStdinUsage()
|
|
{
|
|
$p = Exec::run("cat -", "dog");
|
|
$this->assertEquals(0, $p->retval);
|
|
$this->assertEquals("dog", $p->stdout);
|
|
$this->assertEmpty($p->stderr);
|
|
}
|
|
}
|