1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Tester\Runner\Output;
9:
10: use Tester,
11: Tester\Runner\Runner;
12:
13:
14: 15: 16: 17: 18:
19: class Logger implements Tester\Runner\OutputHandler
20: {
21:
22: private $runner;
23:
24:
25: private $file;
26:
27:
28: public function __construct(Runner $runner, $file)
29: {
30: $this->runner = $runner;
31: $this->file = fopen($file, 'w');
32: }
33:
34:
35: public function begin()
36: {
37: fputs($this->file, 'PHP ' . $this->runner->getPhp()->getVersion()
38: . ' | ' . $this->runner->getPhp()->getCommandLine()
39: . " | {$this->runner->threadCount} threads\n\n");
40: }
41:
42:
43: public function result($testName, $result, $message)
44: {
45: $message = Tester\Dumper::removeColors(trim($message));
46: $outputs = array(
47: Runner::PASSED => "-- OK: $testName",
48: Runner::SKIPPED => "-- Skipped: $testName\n $message",
49: Runner::FAILED => "-- FAILED: $testName" . str_replace("\n", "\n ", "\n" . $message),
50: );
51: fputs($this->file, $outputs[$result] . "\n\n");
52: }
53:
54:
55: public function end()
56: {
57: $jobCount = $this->runner->getJobCount();
58: $results = $this->runner->getResults();
59: $count = array_sum($results);
60: fputs($this->file,
61: ($results[Runner::FAILED] ? 'FAILURES!' : 'OK')
62: . " ($jobCount tests"
63: . ($results[Runner::FAILED] ? ", {$results[Runner::FAILED]} failures" : '')
64: . ($results[Runner::SKIPPED] ? ", {$results[Runner::SKIPPED]} skipped" : '')
65: . ($jobCount !== $count ? ', ' . ($jobCount - $count) . ' not run' : '')
66: . ')'
67: );
68: }
69:
70: }
71: