/
UnitTest.php
104 lines (88 loc) · 2.28 KB
/
UnitTest.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
require_once 'Autoload.php';
// same thing as JrMnt, but no comments.
// I kind of find them really distracting.
class UnitTest extends TestRunner
{
public function setUp()
{
}
public function tearDown()
{
}
public function skip($message = null)
{
throw new SkippedTestException($message);
}
public function pass($message = null)
{
throw new PassedTestException($message);
}
public function fail($message = null)
{
throw new FailedTestException($message);
}
public function should($boolean)
{
if (!($boolean)) {
throw new FailedTestException();
}
}
public function shouldnt($boolean)
{
if ($boolean) {
throw new FailedTestException();
}
}
public function shouldBeEqual($one, $other)
{
if ($one != $other) {
throw new FailedTestException("$one does not equal $other");
}
}
public function shouldBeIdentical($one, $other)
{
if ($one !== $other) {
throw new FailedTestException("$one is not identical to $other");
}
}
public function findTests()
{
return parent::findTests();
}
protected $allResults;
public function runTest($test, TestResult $result = null)
{
return parent::runTest($test, $this, $result);
}
public function runAllTests(TestClassResult $allResults = null)
{
return parent::runAllTests($allResults, $this);
/*
if ($allResults === null) {
$allResults = new TestClassResult;
}
$tests = $this->findTests();
$allResults->setClass(get_class($this));
foreach ($tests as $test) {
$result = $this->runTest($test);
$allResults->addResult($result);
}
return $allResults;
*/
}
public function runAndReport(Reporter $reporter = null)
{
$output = $this->runAllTests();
if ($reporter == null) {
$reporter = new AsciiFailureReporter;
}
$reporter->report($output);
}
public static function runrun()
{
$testClassName = get_called_class();
$testClass = new $testClassName;
$testClass->runAndReport();
}
}