Skip to content

Commit 231c68c

Browse files
committed
Add Json report
1 parent 19cf757 commit 231c68c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/Reports/JsonReport.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
namespace Tendo\Reports;
3+
4+
class JsonReport implements ReportInterface {
5+
private $json = '';
6+
private $title;
7+
8+
public function __construct() {
9+
$this->json = ['title' => '', 'tests' => []];
10+
}
11+
12+
public function onTitle($title) {
13+
$this->json['title'] = $title;
14+
}
15+
16+
public function onTest($title, $hasPass, $messages = null, array $stack = null) {
17+
$this->json['tests'][] = [
18+
'title' => $title,
19+
'pass' => $hasPass,
20+
'messages' => $messages,
21+
'stack' => $stack
22+
];
23+
}
24+
25+
public function onResults($pass, $fail) {
26+
$this->json['results'] = ['pass' => $pass, 'fail' => $fail];
27+
28+
echo json_encode($this->json, JSON_PRETTY_PRINT);
29+
}
30+
}

0 commit comments

Comments
 (0)