-
Notifications
You must be signed in to change notification settings - Fork 0
/
TAPFormatter.php
56 lines (47 loc) · 1.27 KB
/
TAPFormatter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php namespace Devtools;
class TAPFormatter extends Formatter
{
private $testCount;
private $first;
private $timestamp;
public function __construct()
{
$this->textCount = 0;
$this->first = true;
}
public function header($content = '')
{
date_default_timezone_set('America/Chicago');
$this->timestamp = date("m-d-Y H:i:s");
$content = $this->timestamp . PHP_EOL . $content;
$this->first = false;
return $content;
}
public function footer()
{
return "1..{$this->testCount}" . PHP_EOL;
}
public function format($content, $result)
{
$content = $this->stringify($content);
$nextTest = $this->testCount + 1;
$prefix = 'ok ' . $nextTest . ' - ';
if (!is_null($result)) {
$this->testCount = $nextTest;
$content = $prefix . $content;
if (!$result) {
$content = 'not ' . $content;
}
}
if ($this->first) {
$content = $this->header($content);
}
return $content;
}
public function stringify($content)
{
return (is_array($content) || is_object($content)) ?
serialize($content) :
$content;
}
}