Files
postfixadmin/tests/ExecTest.php
T
Kent Riboe 2c0a06f932 Add Exec class to help refactor/reduce duplication of proc_open calls, update phpunit (see note) (#1009)
* 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
2026-04-18 10:05:35 +01:00

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);
}
}