/**
  * @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();
         });
     }
 }
Exemple #2
0
     });
     $suite->addTest(new Test("should pass", function () {
     }));
     $suite->addTest(new Test('should fail', function () {
         throw new \Exception('woooooo!');
     }));
     $result = new TestResult($this->eventEmitter);
     $suite->setEventEmitter($this->eventEmitter);
     $suite->run($result);
     assert('2 run, 1 failed' == $result->getSummary(), "result summary should show 2/1");
 });
 it("should pass setup functions to tests", function () {
     $suite = new Suite("Suite", function () {
     });
     $suite->addSetupFunction(function () {
         $this->log = "setup";
     });
     $fn = function () {
         assert($this->log == "setup", "should have setup in log");
     };
     $suite->addTest(new Test("should have log", $fn));
     $suite->addTest(new Test("should also have log", $fn));
     $result = new TestResult($this->eventEmitter);
     $suite->setEventEmitter($this->eventEmitter);
     $suite->run($result);
     $expected = "2 run, 0 failed";
     $actual = $result->getSummary();
     assert($expected == $actual, "expected {$expected}, got {$actual}");
 });
 it('should pass child scopes to tests', function () {
     $suite = new Suite("Suite", function () {
Exemple #3
0
     $test->addSetupFunction(function () use(&$log) {
         $log = "thing";
     });
     $test->addSetupFunction(function () use(&$log) {
         $log = "thing2";
     });
     $test->run(new TestResult(new EventEmitter()));
     $expected = "thing2";
     assert($expected == $log, "expected {$expected}, got {$log}");
 });
 it('should run parent setup functions first', function () {
     $parent = new Suite("parent", function () {
     });
     $log = '';
     $parent->addSetupFunction(function () use(&$log) {
         $log .= "parent ";
     });
     $child = new Suite("child", function () {
     });
     $child->addSetupFunction(function () use(&$log) {
         $log .= "child ";
     });
     $grandchild = new Test("grandchild", 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");