Exemplo n.º 1
0
        it("should extend test suite context", function () {
            // start new env
            Preview::$world = $this->world;
            Preview::$config = $this->config;
            $exception_in_sample_code = null;
            try {
                $suite = ["before" => function () {
                    $this->user = "******";
                }, "before_each" => function () {
                    ok($this->user == "wenjun.yan");
                }, "should have a user" => function () {
                    ok($this->user == "wenjun.yan");
                }, "after_each" => function () {
                    ok($this->user == "wenjun.yan");
                }];
                Export\export($suite);
                $results = Preview::$world->run();
            } catch (Exception $e) {
                $exception_in_sample_code = $e;
                // end new env
            }
            Preview::$world = $this->test_world;
            Preview::$config = $this->test_config;
            if ($exception_in_sample_code) {
                throw $exception_in_sample_code;
            }
            $result = $results[0];
            ok($result->passed());
        });
    });
});
Exemplo n.º 2
0
         Preview::$world = $this->test_world;
         Preview::$config = $this->test_config;
         if ($exception_in_sample_code) {
             throw $exception_in_sample_code;
         }
     });
 });
 describe("test array", function () {
     it("before/after before each, after each are keys for hooks", function () {
         Preview::$world = $this->world;
         Preview::$config = $this->config;
         $exception_in_sample_code = null;
         try {
             Export\export("title", array("before" => function () {
             }, "before each" => function () {
             }, "after" => function () {
             }, "after each" => function () {
             }, "this one is test" => function () {
             }));
             $results = Preview::$world->run();
         } catch (\Exception $e) {
             $exception_in_sample_code = $e;
             // end new env
         }
         Preview::$world = $this->test_world;
         Preview::$config = $this->test_config;
         if ($exception_in_sample_code) {
             throw $exception_in_sample_code;
         }
         ok(count($results[0]->cases()) == 1);
     });
     it("value should be \\Closure");
Exemplo n.º 3
0
            Preview::$config = $this->config;
            $exception_in_sample_code = null;
            try {
                $message = array();
                $total = 0;
                $suite = array("after" => function () use(&$message, &$total) {
                    $message[] = "after";
                    $total++;
                }, "after_each" => function () use(&$message) {
                    $message[] = "then after_each";
                }, "add a new message" => function () use(&$message) {
                    $message[] = "it first";
                }, "add a new message" => function () use(&$message) {
                    $message[] = "it first";
                });
                Export\export("sample suite", $suite);
                $this->world->run();
            } catch (\Exception $e) {
                $exception_in_sample_code = $e;
                // end new env
            }
            Preview::$world = $this->test_world;
            Preview::$config = $this->test_config;
            if ($exception_in_sample_code) {
                throw $exception_in_sample_code;
            }
            ok(end($message) == "after");
            ok($total == 1);
        });
    });
});