Report abuse


			
 array(),
		"each" => array()
	);
	
	var $after = array(
		"all" => array(),
		"each" => array()
	);
	
	var $examples = array();
	
	function __construct()
	{
		
	}
	
	function run($block)
	{
		static::$current = $this;
		$block();
		
		foreach ($this->before["all"] as $before_all)
		{
			$before_all();
		}
		
		$this->run_examples();

		foreach ($this->after["all"] as $after_all)
		{
			$after_all();
		}

		static::$current = null;
	}
	
	function run_examples()
	{
		foreach ($this->examples as $example)
		{
			foreach ($this->before["each"] as $before_each)
			{
				$before_each();
			}

			$example->run();
			
			foreach ($this->after["each"] as $after_each)
			{
				$after_each();
			}
		}
	}
	
	function before($what, $block)
	{
		array_push($this->before[$what], $block);
	}
	
	function after($what, $block)
	{
		array_push($this->after[$what], $block);
	}
	
	function it($description, $block)
	{
		
	}
}

// represents the 'it'-part
class Example
{
	var $block;
	
	function __construct($context, $description, $block)
	{
		$this->context = $context;
		$this->description = $description;
		$this->block = $block;
		
		array_push($context->examples, $this);
	}
	
	function run()
	{
		$meh = $this->block;
		$meh();
	}
}

function describe($description, $block)
{
	$context = new Context($description);
	$context->run($block);
}

function before($what, $block)
{
	Context::$current->before($what, $block);
}

function after($what, $block)
{
	Context::$current->after($what, $block);
}

function it($description, $block)
{
	new Example(Context::$current, $description, $block);
}

describe("Some Context", function() {
	before("each", function() {
		echo "yay! (before each)\n";
	});
	
	after("all", function() {
		echo "yay! (after all)\n";
	});
	
	it("does stuff", function() {
		echo "yay! (it #1)\n";
	});

	it("does stuff", function() {
		echo "yay! (it #2)\n";
	});
});

?>