Created
December 21, 2011 16:59
-
-
Save fixlr/1506771 to your computer and use it in GitHub Desktop.
Crazy little PHP idea I was toying with this morning...
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 | |
class Expectation | |
{ | |
function __construct($value) { | |
$this->value = $value; | |
} | |
function toBe($expected) { | |
return $this->value === $expected; | |
} | |
} | |
function describe($msg, $block) { | |
echo "{$msg}\n"; | |
$block(); | |
} | |
function it($msg, $block) { | |
echo "{$msg}\n"; | |
$result = $block(); | |
} | |
function expect($value) { | |
return new Expectation($value); | |
} | |
/* An example of a test */ | |
describe("A test", function() { | |
it("has expectations", function() { | |
expect(true)->toBe(true); | |
}); | |
}); | |
describe("Another test", function() { | |
describe("wrapped in another test", function() { | |
it("has even more expectations", function() { | |
expect(42)->toBe(42); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment