| 1 |
<?php |
| 2 |
class Test { |
| 3 |
protected static $passed = 0; |
| 4 |
protected static $failed = 0; |
| 5 |
protected static $last_echoed; |
| 6 |
|
| 7 |
public static function true($test_name, $result){ |
| 8 |
return static::is($test_name, $result, true); |
| 9 |
} |
| 10 |
|
| 11 |
public static function is($test_name, $result, $expected){ |
| 12 |
if($result == $expected) { |
| 13 |
static::passed($test_name); |
| 14 |
} else { |
| 15 |
static::failed($test_name); |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
public static function not($test_name, $result, $expected){ |
| 20 |
if($result == $expected) { |
| 21 |
static::failed($test_name); |
| 22 |
} else { |
| 23 |
static::passed($test_name); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
public static function identical($test_name, $result, $expected){ |
| 28 |
if($result === $expected) { |
| 29 |
static::passed($test_name); |
| 30 |
} else { |
| 31 |
static::failed($test_name); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
public static function totals(){ |
| 36 |
echo "\n"; |
| 37 |
echo static::$passed." tests passed.\n"; |
| 38 |
echo static::$failed." tests failed.\n"; |
| 39 |
} |
| 40 |
|
| 41 |
private static function failed($test_name){ |
| 42 |
echo "\n".$test_name." -> FAILED\n"; |
| 43 |
static::$failed++; |
| 44 |
} |
| 45 |
|
| 46 |
private static function passed($test_name){ |
| 47 |
static::character("."); |
| 48 |
static::$passed++; |
| 49 |
} |
| 50 |
|
| 51 |
private static function character($char){ |
| 52 |
echo $char; |
| 53 |
static::$last_echoed = 'char'; |
| 54 |
} |
| 55 |
|
| 56 |
private static function line($msg){ |
| 57 |
if(static::$last_echoed == 'char') echo "\n"; |
| 58 |
echo $msg."\n"; |
| 59 |
static::$last_echoed = 'line'; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
|