<?php namespace Preview\DSL\Testify; require_once 'stack.php'; require_once __DIR__ . '/../ok.php'; $suite = new Suite("Stack[testify]"); $suite->before_each(function () { $this->stack = new \Stack(array(1, 2, 3)); })->test("#size returns the size of stack", function () { ok($this->stack->size() == 3); })->test("#peek eturns the last element", function () { ok($this->stack->peek() == 3); })->test("#push pushes an element to stack", function () { $this->stack->push(4); ok($this->stack->peek() == 4); ok($this->stack->size() == 4); })->test("#pop pops out the last element", function () { ok($this->stack->pop() == 3); ok($this->stack->size() == 2); })->load();
<?php namespace Preview\DSL\Testify; require_once 'ok.php'; $suite = new Suite("array functions"); $child = new Suite("String functions"); $suite->add_child($child); $child->test(function () { ok(true); }); $suite->before_each(function () { $this->arr = array(1, 2, 3, 4); }); $suite->test("array_push", function () { array_push($this->arr, 1); ok(end($this->arr) == 1); }); $suite->test("array_pop", "pop", function () { array_pop($this->arr); ok(end($this->arr) == 3); }); $suite->load();
<?php /* * How to use before each hooks. */ namespace Preview\DSL\Testify; require_once __DIR__ . '/../ok.php'; $suite = new Suite("A sample test suite."); $suite->before_each(function () { $this->usage = "run before each test case in current test suite"; })->before_each(function () { $this->note_1 = "can have multiple before each hooks"; })->before_each(function () { $this->note_2 = "before each hooks are run in order"; }); $suite->test("It can access vars defined in before each hook", function () { ok($this->note_1); ok($this->note_2); ok($this->note_3); }); $suite->before_each(function () { $this->note_3 = "wherever you put the before each hook, " . "it will run before each test case"; }); // load this test suite. $suite->load();