Skip to content

Instantly share code, notes, and snippets.

@cmbuckley
Last active May 3, 2017 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmbuckley/39d84aa212fd0adf9e4ed55349bf149c to your computer and use it in GitHub Desktop.
Save cmbuckley/39d84aa212fd0adf9e4ed55349bf149c to your computer and use it in GitHub Desktop.
<?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