Skip to content

Instantly share code, notes, and snippets.

@fixlr
Created December 21, 2011 16:59
Show Gist options
  • Save fixlr/1506771 to your computer and use it in GitHub Desktop.
Save fixlr/1506771 to your computer and use it in GitHub Desktop.
Crazy little PHP idea I was toying with this morning...
<?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