}); it_behaves_like("error test"); }); }); describe("#set_parent", function () { it("set parent test suite", function () { $parent = new TestSuite("parent", function () { }); $this->subject->set_parent($parent); ok($this->subject->parent == $parent); ok($parent->suites == array($this->subject)); }); }); describe("#add", function () { it("add child test suite", function () { $parent = new TestSuite("parent", function () { }); $parent->add($this->subject); ok($this->subject->parent == $parent); ok($parent->suites == array($this->subject)); }); it("add child test suite", function () { $case = new TestCase("child case", function () { }); $this->subject->add($case); ok($case->parent == $this->subject); ok($this->subject->cases == array($case)); }); }); describe("#add_to_group", function () { before_each(function () { $this->subject->add(new TestSuite("child suite", function () {
} ok($run); }); }); describe("after_each_hook", function () { it("should run after every test case", function () { $run = false; $this->config->reporter = new BaseReporter(); $this->config->after_each_hook = function () use(&$run) { $run = true; }; $old_config = Preview::$config; Preview::$config = $this->config; $exception_in_sample_code = null; try { $suite = new TestSuite("sample suite", function () { }); $suite->add(new TestCase("sample case", function () { })); $suite->run(); } catch (\Exception $e) { $exception_in_sample_code = $e; } Preview::$config = $old_config; if ($exception_in_sample_code) { throw $exception_in_sample_code; } ok($run); }); }); });
$testsuite = new Testsuite("case-title-1", function () { }); $testsuite->set_parent(new TestSuite("suite-title-2", function () { })); $testsuite->add_to_group("group-1"); $testsuite->add_to_group("group-2"); $this->result = $testsuite->result; $this->groups = array("group-1", "group-2"); }); it_behaves_like("grouped test result"); }); describe("get cases and suites", function () { before_each(function () { $testsuite = new Testsuite("suite-title-1", function () { }); $testsuite_parent = new TestSuite("suite-title-2", function () { }); $testcase_1 = new TestCase("case-title-1", function () { }); $testcase_2 = new TestCase("case-title-2", function () { }); $testsuite->add($testcase_1); $testsuite_parent->add($testcase_2); $testsuite_parent->add($testsuite); $this->result = $testsuite_parent->result; }); describe("#cases", function () { it("should return its direct children case results", function () { $cases = $this->result->cases(); ok(count($cases) == 1); ok($cases[0]->title() == "case-title-2"); });