Last active
October 11, 2015 18:58
-
-
Save MarcelloDuarte/3904362 to your computer and use it in GitHub Desktop.
Building DSLs
This file contains hidden or 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 | |
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