예제 #1
0
파일: Tap.php 프로젝트: crysalead/kahlan
 /**
  * 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");
             }
         }
     }
 }
예제 #2
0
파일: Json.php 프로젝트: crysalead/kahlan
 /**
  * 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));
 }
예제 #3
0
파일: Bar.php 프로젝트: Ilyes512/kahlan
 /**
  * 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);
 }
예제 #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"');
        });
    });
});
예제 #5
0
파일: Mon.php 프로젝트: crysalead/kahlan
 public function dump($value)
 {
     return Text::dump($value);
 }
예제 #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");
 }
예제 #7
0
파일: Class.php 프로젝트: nurka1109/kahlan
 public function staticCallFromUsed()
 {
     return Text::hash((object) 'hello');
 }
예제 #8
0
파일: Trait.php 프로젝트: nurka1109/kahlan
 protected function dump()
 {
     return Text::dump('Hello');
 }