Beispiel #1
0
 /**
  * Callback called after a spec execution.
  *
  * @param object $log The log object of the whole spec.
  */
 public function specEnd($log = null)
 {
     $isOk = $log->passed() ? "ok" : "not ok";
     switch ($log->type()) {
         case 'skipped':
         case 'pending':
         case 'excluded':
             $prefix = "# {$log->type()} ";
             break;
         default:
             $prefix = '- ';
             break;
     }
     $message = $prefix . trim(implode(" ", $log->messages()));
     $this->_counter++;
     $this->write("{$isOk} {$this->_counter} {$message}\n");
     if ($exception = $log->exception()) {
         $this->write('# Exception: `' . get_class($exception) . '` Code(' . $exception->getCode() . '):' . "\n");
         $this->write('# Message: ' . $exception->getMessage() . "\n");
     } else {
         foreach ($log->children() as $log) {
             if ($log->passed()) {
                 continue;
             }
             $toString = function ($instance) {
                 return 'an instance of `' . get_class($instance) . '`';
             };
             foreach ($log->data() as $key => $value) {
                 $key = ucfirst($key);
                 $value = Text::toString($value, ['object' => ['method' => $toString]]);
                 $this->write("# {$key}: {$value}\n");
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Callback called at the end of specs processing.
  *
  * @param object $summary The execution summary instance.
  */
 public function end($summary)
 {
     $toString = function ($instance) {
         return 'an instance of `' . get_class($instance) . '`';
     };
     foreach ($summary->logs() as $log) {
         if ($log->passed()) {
             continue;
         }
         switch ($log->type()) {
             case 'failed':
                 foreach ($log->children() as $log) {
                     if ($log->passed()) {
                         continue;
                     }
                     $data = [];
                     foreach ($log->data() as $key => $value) {
                         $data[$key] = Text::toString($value, ['object' => ['method' => $toString]]);
                     }
                     $this->_json['errors'][] = ['spec' => trim(implode(' ', $log->messages())), 'suite' => $log->file(), 'data' => $data];
                 }
                 break;
             case 'errored':
                 $exception = $log->exception();
                 $this->_json['errors'][] = ['spec' => trim(implode(' ', $log->messages())), 'suite' => $log->file(), 'exception' => '`' . get_class($exception) . '` Code(' . $exception->getCode() . ')', 'trace' => $exception->getMessage()];
                 break;
         }
     }
     $this->_json['summary'] = ['total' => $summary->total(), 'passed' => $summary->passed(), 'pending' => $summary->pending(), 'skipped' => $summary->skipped(), 'excluded' => $summary->excluded(), 'failed' => $summary->failed(), 'errored' => $summary->errored()];
     $this->write(json_encode($this->_json));
 }
Beispiel #3
0
 /**
  * Ouputs the progress bar to STDOUT.
  */
 protected function _progressBar()
 {
     if ($this->_current > $this->_total) {
         return;
     }
     $percent = $this->_current / $this->_total;
     $nb = $percent * $this->_size;
     $b = str_repeat($this->_chars['bar'], floor($nb));
     $i = '';
     if ($nb < $this->_size) {
         $i = str_pad($this->_chars['indicator'], $this->_size - strlen($b));
     }
     $p = floor($percent * 100);
     $string = Text::insert($this->_format, compact('p', 'b', 'i'));
     $this->write("\r" . $string, $this->_color);
 }
Beispiel #4
0
        });
        it("dumps a string with double quote", function () {
            $dump = Text::dump('Hel"lo');
            $this->expect($dump)->toBe('"Hel\\"lo"');
        });
        it("dumps a string with simple quote", function () {
            $dump = Text::dump("Hel'lo", "'");
            $this->expect($dump)->toBe("'Hel\\'lo'");
        });
        it("expands escape sequences and escape special chars", function () {
            $dump = Text::dump(" \t \nHello   \r\n \v \f World\n\n");
            $this->expect($dump)->toBe("\" \\t \\nHello \\x07 \\x08 \\r\\n \\v \\f World\\n\\n\"");
        });
        it("expands an empty string as \"\"", function () {
            $dump = Text::dump('');
            $this->expect($dump)->toBe('""');
        });
        it("expands an zero string as 0", function () {
            $dump = Text::dump('2014');
            $this->expect($dump)->toBe('"2014"');
        });
        it("expands espcape special chars", function () {
            $dump = Text::dump('20$14');
            $this->expect($dump)->toBe('"20\\$14"');
            $dump = Text::dump('20"14');
            $this->expect($dump)->toBe('"20\\"14"');
            $dump = Text::dump('20\\14');
            $this->expect($dump)->toBe('"20\\\\14"');
        });
    });
});
Beispiel #5
0
 public function dump($value)
 {
     return Text::dump($value);
 }
Beispiel #6
0
 protected function _reportException($exception)
 {
     $msg = '`' . get_class($exception) . '` Code(' . $exception->getCode() . ') with ';
     $message = $exception->getMessage();
     if ($message) {
         $msg .= 'message ' . Text::dump($exception->getMessage());
     } else {
         $msg .= 'no message';
     }
     $this->write("{$msg}\n\n");
 }
Beispiel #7
0
 public function staticCallFromUsed()
 {
     return Text::hash((object) 'hello');
 }
Beispiel #8
0
 protected function dump()
 {
     return Text::dump('Hello');
 }