/** * @param Suite $suite */ public function onSuiteStart(Suite $suite) { $scope = new TemporaryScope(); $suite->getScope()->peridotAddChildScope($scope); $suite->addTearDownFunction(function () use(&$scope) { $scope->cleanUpTemporary(); }); }
/** * @param Suite $suite */ public function onSuiteStart(Suite $suite) { $suite->getScope()->peridotAddChildScope(new ProphecyScope()); $description = $suite->getDescription(); if (class_exists($description)) { $suite->addSetupFunction(function () use($description) { $prophet = $this->getProphet(); $this->subject = $prophet->prophesize($description); }); $suite->addTearDownFunction(function () { $this->clearProphet(); }); } }
}); $suite->getScope()->use(new SuiteScope()); $test = new Test("this is a test", function () { assert($this->getNumber() == 5, "parent scope should be set on test"); }); $suite->addTest($test); $result = new TestResult($this->eventEmitter); $suite->setEventEmitter($this->eventEmitter); $suite->run($result); assert('1 run, 0 failed' == $result->getSummary(), "result summary should show 1/0"); }); it("should pass teardown functions to tests", function () { $suite = new Suite("Suite", function () { }); $suite->addTearDownFunction(function () { $this->log = "torn"; }); $fn = function () { }; $test1 = new Test("should have log", $fn); $test2 = new Test("should have log too", $fn); $suite->addTest($test1); $suite->addTest($test2); $result = new TestResult($this->eventEmitter); $suite->setEventEmitter($this->eventEmitter); $suite->run($result); assert('torntorn' == $test1->getScope()->log . $test2->getScope()->log, "tear down should have run for both tests"); }); it("should set pending status on tests if not null", function () { $suite = new Suite("Suite", function () { });
$grandchild->addSetupFunction(function () use(&$log) { $log .= "grandchild"; }); $parent->addTest($child); $child->addTest($grandchild); $grandchild->run(new TestResult(new EventEmitter())); assert("parent child grandchild" == $log, "setup functions should be run in order"); }); }); context("when running tear down functions", function () { it('should run child tear down functions first', function () { $parent = new Suite("parent", function () { }); $log = ''; $parent->addTearDownFunction(function () use(&$log) { $log .= "parent"; }); $child = new Suite("child", function () { }); $child->addTearDownFunction(function () use(&$log) { $log .= "child "; }); $grandchild = new Test("grandchild", function () { }); $grandchild->addTearDownFunction(function () use(&$log) { $log .= "grandchild "; }); $parent->addTest($child); $child->addTest($grandchild); $grandchild->run(new TestResult(new EventEmitter())); assert("grandchild child parent" == $log, "tear down functions should be run in order");