-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathrun_tests.php
More file actions
55 lines (52 loc) · 1.96 KB
/
run_tests.php
File metadata and controls
55 lines (52 loc) · 1.96 KB
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
<?php
// Simple custom test runner since PHPUnit is not available
$tests = glob('tests/*Test.php');
$passed = 0;
$failed = 0;
class TestCase {
public function setUp() {}
public function tearDown() {}
public function assertTrue($condition, $message = '') {
if (!$condition) throw new Exception($message ?: 'Failed asserting that condition is true');
}
public function assertFalse($condition, $message = '') {
if ($condition) throw new Exception($message ?: 'Failed asserting that condition is false');
}
public function assertEquals($expected, $actual, $message = '') {
if ($expected !== $actual) throw new Exception($message ?: "Failed asserting that '$actual' matches expected '$expected'");
}
public function assertNull($actual, $message = '') {
if ($actual !== null) throw new Exception($message ?: "Failed asserting that '$actual' is null");
}
public function assertNotNull($actual, $message = '') {
if ($actual === null) throw new Exception($message ?: 'Failed asserting that actual is not null');
}
}
foreach ($tests as $test) {
echo "Running $test...\n";
require_once $test;
$className = basename($test, '.php');
if (class_exists($className)) {
$instance = new $className();
$methods = get_class_methods($instance);
foreach ($methods as $method) {
if (strpos($method, 'test') === 0) {
try {
$instance->setUp();
$instance->$method();
echo " [PASS] $method\n";
$passed++;
} catch (Exception $e) {
echo " [FAIL] $method: " . $e->getMessage() . "\n";
$failed++;
} finally {
$instance->tearDown();
}
}
}
}
}
echo "\nTests run: " . ($passed + $failed) . ", Passed: $passed, Failed: $failed\n";
if ($failed > 0) {
exit(1);
}