Tester\Runner\Runner::run PHP 메소드

run() 공개 메소드

Runs all tests.
public run ( ) : boolean
리턴 boolean
    public function run()
    {
        $this->interrupted = FALSE;
        foreach ($this->outputHandlers as $handler) {
            $handler->begin();
        }
        $this->results = [self::PASSED => 0, self::SKIPPED => 0, self::FAILED => 0];
        $this->jobs = $running = [];
        foreach ($this->paths as $path) {
            $this->findTests($path);
        }
        $this->jobCount = count($this->jobs) + array_sum($this->results);
        $threads = range(1, $this->threadCount);
        $this->installInterruptHandler();
        while (($this->jobs || $running) && !$this->isInterrupted()) {
            while ($threads && $this->jobs) {
                $running[] = $job = array_shift($this->jobs);
                $async = $this->threadCount > 1 && count($running) + count($this->jobs) > 1;
                $job->setEnvironmentVariable(Environment::THREAD, array_shift($threads));
                $job->run($async ? $job::RUN_ASYNC : NULL);
            }
            if (count($running) > 1) {
                usleep(Job::RUN_USLEEP);
                // stream_select() doesn't work with proc_open()
            }
            foreach ($running as $key => $job) {
                if ($this->isInterrupted()) {
                    break 2;
                }
                if (!$job->isRunning()) {
                    $threads[] = $job->getEnvironmentVariable(Environment::THREAD);
                    $this->testHandler->assess($job);
                    unset($running[$key]);
                }
            }
        }
        $this->removeInterruptHandler();
        foreach ($this->outputHandlers as $handler) {
            $handler->end();
        }
        return !$this->results[self::FAILED];
    }

Usage Example

예제 #1
0
 /** @return void */
 private function watch(Runner $runner)
 {
     $prev = array();
     $counter = 0;
     while (TRUE) {
         $state = array();
         foreach ($this->options['--watch'] as $directory) {
             foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)) as $file) {
                 if (substr($file->getExtension(), 0, 3) === 'php' && substr($file->getBasename(), 0, 1) !== '.') {
                     $state[(string) $file] = md5_file((string) $file);
                 }
             }
         }
         if ($state !== $prev) {
             $prev = $state;
             $runner->run();
         }
         echo "Watching " . implode(', ', $this->options['--watch']) . " " . str_repeat('.', ++$counter % 5) . "    \r";
         sleep(2);
     }
 }