123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- <?php
- require_once(dirname(__FILE__) . '/test_case.php');
- class SimpleShell {
- var $_output;
-
- function SimpleShell() {
- $this->_output = false;
- }
-
- function execute($command) {
- $this->_output = false;
- $ret = null;
- exec($command, $this->_output, $ret);
- return $ret;
- }
-
- function getOutput() {
- return implode("\n", $this->_output);
- }
-
- function getOutputAsList() {
- return $this->_output;
- }
- }
- class ShellTestCase extends SimpleTestCase {
- var $_current_shell;
- var $_last_status;
- var $_last_command;
-
- function ShellTestCase($label = false) {
- $this->SimpleTestCase($label);
- $this->_current_shell = &$this->_createShell();
- $this->_last_status = false;
- $this->_last_command = '';
- }
-
- function execute($command) {
- $shell = &$this->_getShell();
- $this->_last_status = $shell->execute($command);
- $this->_last_command = $command;
- return ($this->_last_status === 0);
- }
-
- function dumpOutput() {
- $this->dump($this->getOutput());
- }
-
- function getOutput() {
- $shell = &$this->_getShell();
- return $shell->getOutput();
- }
-
- function getOutputAsList() {
- $shell = &$this->_getShell();
- return $shell->getOutputAsList();
- }
-
- function assertTrue($result, $message = false) {
- return $this->assert(new TrueExpectation(), $result, $message);
- }
-
- function assertFalse($result, $message = '%s') {
- return $this->assert(new FalseExpectation(), $result, $message);
- }
-
- function assertEqual($first, $second, $message = "%s") {
- return $this->assert(
- new EqualExpectation($first),
- $second,
- $message);
- }
-
- function assertNotEqual($first, $second, $message = "%s") {
- return $this->assert(
- new NotEqualExpectation($first),
- $second,
- $message);
- }
-
- function assertExitCode($status, $message = "%s") {
- $message = sprintf($message, "Expected status code of [$status] from [" .
- $this->_last_command . "], but got [" .
- $this->_last_status . "]");
- return $this->assertTrue($status === $this->_last_status, $message);
- }
-
- function assertOutput($expected, $message = "%s") {
- $shell = &$this->_getShell();
- return $this->assert(
- new EqualExpectation($expected),
- $shell->getOutput(),
- $message);
- }
-
- function assertOutputPattern($pattern, $message = "%s") {
- $shell = &$this->_getShell();
- return $this->assert(
- new PatternExpectation($pattern),
- $shell->getOutput(),
- $message);
- }
-
- function assertNoOutputPattern($pattern, $message = "%s") {
- $shell = &$this->_getShell();
- return $this->assert(
- new NoPatternExpectation($pattern),
- $shell->getOutput(),
- $message);
- }
-
- function assertFileExists($path, $message = "%s") {
- $message = sprintf($message, "File [$path] should exist");
- return $this->assertTrue(file_exists($path), $message);
- }
-
- function assertFileNotExists($path, $message = "%s") {
- $message = sprintf($message, "File [$path] should not exist");
- return $this->assertFalse(file_exists($path), $message);
- }
-
- function assertFilePattern($pattern, $path, $message = "%s") {
- $shell = &$this->_getShell();
- return $this->assert(
- new PatternExpectation($pattern),
- implode('', file($path)),
- $message);
- }
-
- function assertNoFilePattern($pattern, $path, $message = "%s") {
- $shell = &$this->_getShell();
- return $this->assert(
- new NoPatternExpectation($pattern),
- implode('', file($path)),
- $message);
- }
-
- function &_getShell() {
- return $this->_current_shell;
- }
-
- function &_createShell() {
- $shell = &new SimpleShell();
- return $shell;
- }
- }
- ?>
|