/** * @depends test_doRun * @covers ::getStatus */ public function test_getStatus() { $this->assertTrue($this->Command->open($this->Input), 'ShellCommand::open() should return TRUE'); $this->assertTrue($this->Command->getStatus('running'), 'ShellCommand::getStatus() should return TRUE'); # Invalid arguments try { $this->Command->getStatus(null); $this->fail('Failed to generate exception with invalid arguments'); } catch (InvalidArgumentException $e) { } }
/** * @coversNothing */ public function test_doRun() { // Only Windows if (DIRECTORY_SEPARATOR != '\\') { return true; } $Expected = 'foo'; $this->assertEquals(0, $this->Command->run($this->Input, $this->Output), 'ShellCommand::run() returned an invalid result'); $this->assertEquals($Expected, $this->Output->stdOut->getContents(), 'ShellCommand::doRun() Failed to process command output'); $this->assertEmpty($this->Output->stdErr->getContents(), 'ShellCommand::doRun() Failed to process command error'); }
if ($path->isDir()) { continue; } elseif ($path->isFile()) { if (!is_dir($Dir = str_replace($Src, $Dest, $path->getPath()))) { mkdir($Dir); } copy($path->getPathname(), str_replace($Src, $Dest, $path->getPathname())); } } }; // ##################### // RUN COMPOSER // ##################### $Print('Running Composer...'); $ShellInput = new Input(new Handle(fopen('data:text/plain,', 'r'))); $Composer = new ShellCommand('composer dumpautoload -o', new Config(array('Timeout' => 60, 'CWD' => dirname(__DIR__), 'Environment' => null, 'Extras' => array())), $Command->getMediator(), $Command->getMediatorID()); // Check results if ($code = $Composer->run($ShellInput, $Output)) { return $code; } $Output->write("\r\n"); // ##################### // COMPILE APPLICATION // ##################### $Print('Compiling application...'); @unlink(BLW_DIR . 'build' . DIRECTORY_SEPARATOR . 'BLW.phar'); @unlink(BLW_DIR . 'build' . DIRECTORY_SEPARATOR . 'BLW.tar.gz'); $Output->write("-Collecting files\r\n"); $Output->write('[--------------------------------------------------]'); // Create PHAR $Compiler = new Compiler(new GenericFile(BLW_DIR . 'build'), new GenericFile(BLW_DIR), new GenericFile(BLW_DIR . 'temp'), $Command->getMediator());
use BLW\Model\Stream\Handle; Application::configure(); Application::run(function (BLW\Type\Command\IInput $Input, BLW\Type\Command\IOutput $Output, BLW\Type\Command\ICommand $Command) { $Print = function ($Message) use(&$Output, &$Command) { $Output->write("{$Message}\r\n"); $Command->Config['Logger']->debug($Message); }; // ##################### // TEST LIBRARY // ##################### $Print('Testing BLW Library...'); // Run framework tests $ShellInput = new Input(new Handle(fopen('data:text/plain,', 'r'))); $ShellInput->Options[] = new Option('testsuite', 'Types'); $ShellInput->Options[] = new Option('coverage-php', 'temp/coverage-types.serialized'); $PHPUnit = new ShellCommand('phpunit', new Config(array('Timeout' => 60, 'CWD' => dirname(__DIR__), 'Environment' => null, 'Extras' => array())), $Command->getMediator(), $Command->getMediatorID()); // Check results if ($code = $PHPUnit->run($ShellInput, $Output)) { return $code; } // Run library tests $ShellInput = new Input(new Handle(fopen('data:text/plain,', 'r'))); $ShellInput->Options[] = new Option('testsuite', 'Models'); $ShellInput->Options[] = new Option('coverage-php', 'temp/coverage-models.serialized'); $PHPUnit->run($ShellInput, $Output); // Merge coverage files // ... $Print('Finished testing.'); // Done return 0; });
/** * Sends a JSON command to PhantomJS * * @codeCoverageIngore * * @param array $Command * Command to send * @param integer $Timeout * Timeout for reads / writes to process. * @return string Output of command. <code>FALSE</code> on error. */ private function _sendJSON(array $Command, $Timeout = 10) { // `evaluate` command $Command = json_encode($Command); // Add end of transmition marker $Command .= "\r\n"; // Run Processes $Input = new CommandInput(new StringStream($Command)); $Output = new CommandOutput(new StringStream($stdOut, IFile::WRITE | IFile::TRUNCATE), new StringStream($stdErr, IFile::WRITE | IFile::TRUNCATE)); // Transfer output try { $this->_Process->transferStreams($Input, $Output, $Timeout); // @codeCoverageIgnoreStart } catch (CommandException $e) { // Restart PhantomJS just to be sure $this->phantomRestart(); return false; } // @codeCoverageIgnoreEnd unset($Input, $Output); // Normalize output $stdOut = substr($stdOut, strpos($stdOut, '{'), strrpos($stdOut, '}') - strlen($stdOut) + 1); // Done return $stdOut; }
/** * Constructor * * @param mixed $Command * Command to run. * @param IConfig $Config * Command configuration. * @param IMediator $Mediator * Mediator for command. * @param string $ID * Command Name / Label */ public function __construct($Command, IConfig $Config, IMediator $Mediator = null, $ID = null) { // Parent constructor parent::__construct($Command, $Config, $Mediator, $ID); // Bypass CMD $Config['Extras']['bypass_shell'] = true; }