Skip to content

Instantly share code, notes, and snippets.

@MarcelloDuarte
Last active October 11, 2015 18:58
Show Gist options
  • Save MarcelloDuarte/3904362 to your computer and use it in GitHub Desktop.
Save MarcelloDuarte/3904362 to your computer and use it in GitHub Desktop.
Building DSLs
<?php
function describe($testedClass, callable $tests) {
print ("$testedClass" . PHP_EOL);
$tests();
}
function it($testName, callable $test) {
print(" $test" . PHP_EOL);
$test();
}
// because the last argument is a callable we can now:
describe ("BankAccount") {
it ("starts with a zero amount") {
$amount = (new BankAccount())->getAmount();
if ($amount !== 0) throw new Failure("Expected 0, got $amount");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment