<?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();
$suite->before(function () { $this->usage = "run before current test suite"; })->before(function () { $this->note_1 = "can have multiple before hooks"; })->before(function () { $this->note_2 = "before hooks are run in order"; })->before(function () { $this->ref = new \stdClass(); $this->ref->name = "wenjun.yan"; $this->value = "string"; }); $suite->test("It can access vars defined in before hook", function () { ok($this->note_1); ok($this->note_2); ok($this->note_3); ok($this->ref->name); ok($this->value); $this->value = null; $this->ref->name = null; })->test("before hooks are run only once", function () { // $this-value and $this->ref are reassigned. ok($this->value); // string is passed by value ok(empty($this->ref->name)); // object is passed by "ref". }); $suite->before(function () { $this->note_3 = "wherever you put the before hook, " . "it will run before this suite"; }); // load this test suite. $suite->load();
<?php /* * How to make a test suite/case pending. */ namespace Preview\DSL\Testify; require_once __DIR__ . '/../ok.php'; $suite = new Suite("A sample test suite"); $suite->test("a test case", function () { ok(true); }); $suite->test("a pending test case"); // load this test suite. $suite->load();
<?php /* * Basic usage. */ namespace Preview\DSL\Testify; require_once __DIR__ . '/../ok.php'; $suite = new Suite("A sample test suite"); $suite->test("a test case", function () { ok(true); })->test(function () { // a test case with no description; ok(true); }); $child = new Suite("Child test suite"); $child->test("test case in child test suite", function () { ok(true); }); $suite->add_child($child); // load this test suite. $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();
<?php /* * How to use after_each hooks. */ namespace Preview\DSL\Testify; require_once __DIR__ . '/../ok.php'; $suite = new Suite("A sample test suite"); $suite->after_each(function () { $this->usage = "run after each test case in current test suite"; })->after_each(function () { $this->note_1 = "can have multiple after_each hooks"; })->after_each(function () { $this->note_2 = "after_each hooks are run in order"; }); $suite->test("a sample test case", function () { ok(true); }); $suite->after_each(function () { $this->note_3 = "wherever you put the after_each hook, " . "it will run after_each this suite"; }); // load this test suite. $suite->load();