Last active
May 3, 2017 16:50
-
-
Save cmbuckley/39d84aa212fd0adf9e4ed55349bf149c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// run all the tests | |
abstract class TestSuite { | |
public function __construct() { | |
$ref = new ReflectionClass($this); | |
$methods = $ref->getMethods(ReflectionMethod::IS_PUBLIC); | |
$output = ''; | |
foreach ($methods as $method) { | |
if ($method->getDeclaringClass() == $ref) { | |
try { | |
$method->invoke($this); | |
$output .= '.'; | |
} catch (Exception $ex) { | |
$errors[] = $method->getName() . ': ' . $ex->getMessage() . "\n"; | |
$output .= 'F'; | |
} | |
} | |
} | |
echo $output . "\n\n" . implode("\n", $errors); | |
} | |
protected function assertSame($expected, $actual) { | |
if ($expected !== $actual) { | |
throw new Exception("Expected $expected; got $actual"); | |
} | |
} | |
} | |
function multiply($a, $b) { | |
return -$a * $b; | |
} | |
class MultiplyTest extends TestSuite { | |
function test_multiply() { | |
$a = 5; | |
$b = 4; | |
$answer = 20; | |
$this->assertSame($answer, multiply($a, $b)); | |
} | |
} | |
new MultiplyTest; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment