示例#1
0
文件: run.php 项目: Thomvh/turbine
<?php

require_once dirname(__FILE__) . '/config.php';
require_once SWEETY_SIMPLETEST_PATH . '/unit_tester.php';
require_once SWEETY_SIMPLETEST_PATH . '/mock_objects.php';
require_once SWEETY_SIMPLETEST_PATH . '/reporter.php';
require_once SWEETY_SIMPLETEST_PATH . '/xml.php';
require_once 'Sweety/Runner.php';
require_once 'Sweety/Runner/CliRunner.php';
require_once 'Sweety/Reporter/CliReporter.php';
$exe = SWEETY_PHP_EXE;
if (!$exe) {
    if (getenv('_')) {
        $exe = getenv('_');
    } elseif (class_exists('Com')) {
        $wmi = new Com('winmgmts:');
        $exe = $wmi->get('//./root/cimv2:Win32_Process.Handle="' . getmypid() . '"')->executablePath;
    }
}
$runner = new Sweety_Runner_CliRunner(explode(PATH_SEPARATOR, SWEETY_TEST_PATH), $exe . ' ' . $argv[0]);
$name = !empty($argv[1]) ? $argv[1] : 'All Tests';
$runner->setReporter(new Sweety_Reporter_CliReporter(sprintf('%s - %s', SWEETY_SUITE_NAME, $name)));
$runner->setIgnoredClassRegex(SWEETY_IGNORED_CLASSES);
$locators = preg_split('/\\s*,\\s*/', SWEETY_TEST_LOCATOR);
foreach ($locators as $locator) {
    $runner->registerTestLocator(new $locator());
}
if (!empty($argv[1]) && !preg_match('~!?/.*?/~', $argv[1])) {
    $testName = $argv[1];
    $format = !empty($argv[2]) ? $argv[2] : Sweety_Runner::REPORT_TEXT;
    $runner->runTestCase($testName, $format);
 /**
  * prompts user for input
  * 
  * @param  string $_promptText   prompt text to dipslay
  * @param  bool   $_isPassword  is prompt a password?
  * @return string
  */
 public static function promptInput($_promptText, $_isPassword = FALSE)
 {
     fwrite(STDOUT, PHP_EOL . "{$_promptText}> ");
     if ($_isPassword) {
         if (preg_match('/^win/i', PHP_OS)) {
             $pwObj = new Com('ScriptPW.Password');
             $input = $pwObj->getPassword();
         } else {
             system('stty -echo');
             $input = fgets(STDIN);
             system('stty echo');
         }
         fwrite(STDOUT, PHP_EOL);
     } else {
         $input = fgets(STDIN);
     }
     return rtrim($input);
 }
示例#3
0
 /**
  * Get a process by process ID
  *
  * @param   int pid process id
  * @param   string exe
  * @return  self
  * @throws  lang.IllegalStateException
  */
 public static function getProcessById($pid, $exe = null) : self
 {
     $self = new self();
     $self->status = ['pid' => $pid, 'running' => true, 'exe' => $exe, 'command' => '', 'arguments' => null, 'owner' => false];
     // Determine executable and command line:
     // * On Windows, use Windows Management Instrumentation API - see
     //   http://en.wikipedia.org/wiki/Windows_Management_Instrumentation
     //
     // * On systems with a /proc filesystem, use information from /proc/self
     //   See http://en.wikipedia.org/wiki/Procfs. Before relying on it,
     //   also check that /proc is not just an empty directory; this assumes
     //   that process 1 always exists - which usually is `init`.
     //
     // * Fall back to use "_" environment variable for the executable and
     //   /bin/ps to retrieve the command line (please note unfortunately any
     //   quote signs have been lost and it can thus be only used for display
     //   purposes)
     if (strncasecmp(PHP_OS, 'Win', 3) === 0) {
         try {
             $c = new \Com('winmgmts:');
             $p = $c->get('//./root/cimv2:Win32_Process.Handle="' . $pid . '"');
             if (null === $exe) {
                 $self->status['exe'] = $p->executablePath;
             }
             $self->status['command'] = $p->commandLine;
         } catch (\Throwable $e) {
             throw new IllegalStateException('Cannot find executable: ' . $e->getMessage());
         }
     } else {
         if (is_dir('/proc/1')) {
             if (!file_exists($proc = '/proc/' . $pid)) {
                 throw new IllegalStateException('Cannot find executable in /proc');
             }
             if (null === $exe) {
                 do {
                     foreach (['/exe', '/file'] as $alt) {
                         if (!file_exists($proc . $alt)) {
                             continue;
                         }
                         $self->status['exe'] = readlink($proc . $alt);
                         break 2;
                     }
                     throw new IllegalStateException('Cannot find executable in ' . $proc);
                 } while (0);
             }
             $self->status['command'] = strtr(file_get_contents($proc . '/cmdline'), "", ' ');
         } else {
             try {
                 if (null !== $exe) {
                     // OK
                 } else {
                     if ($_ = getenv('_')) {
                         $self->status['exe'] = self::resolve($_);
                     } else {
                         throw new IllegalStateException('Cannot find executable');
                     }
                 }
                 $self->status['command'] = exec('ps -ww -p ' . $pid . ' -ocommand 2>&1', $out, $exit);
                 if (0 !== $exit) {
                     throw new IllegalStateException('Cannot find executable: ' . implode('', $out));
                 }
             } catch (\io\IOException $e) {
                 throw new IllegalStateException($e->getMessage());
             }
         }
     }
     $self->in = $self->out = $self->err = null;
     return $self;
 }