Esempio n. 1
0
            $run_hook = "run_{$hook}";
            $this->subject->{$add_hook}(function () use(&$run) {
                $run = true;
            });
            $this->subject->{$run_hook}();
            Preview::$world = $old_world;
            ok($run);
        });
    });
});
shared_example("having hooks for its children", function ($hook) {
    describe("#run_{$hook}", function () use($hook) {
        it("should run {$hook} hooks and its parents'", function () use($hook) {
            $old_world = Preview::$world;
            $run = false;
            $parent_run = false;
            $add_hook = "add_{$hook}_hook";
            $run_hook = "run_{$hook}";
            $this->parent->{$add_hook}(function () use(&$parent_run) {
                $parent_run = true;
            });
            $this->subject->{$add_hook}(function () use(&$run) {
                $run = true;
            });
            $context = new \stdClass();
            $this->subject->{$run_hook}($context);
            Preview::$world = $old_world;
            ok($run and $parent_run);
        });
    });
});
Esempio n. 2
0
     qunit\test("c1", function () {
     });
     qunit\test("c2", function () {
     })->skip();
     qunit\test("c3");
     qunit\suite("s2");
     qunit\test(function () {
     });
     qunit\test("c5", function () {
     })->skip();
     qunit\test("c6");
     $this->results = $this->world->run();
     // ------ end test -------
     // end new env
     // and go back to our normal test env
     Preview::$world = $this->test_world;
     Preview::$config = $this->test_config;
 });
 it("should have 2 suite", function () {
     ok(count($this->results) == 2);
 });
 it("first suite should have 3 test cases", function () {
     ok(count($this->results[0]->cases()) == 3);
 });
 it("second suite should have 3 test cases", function () {
     ok(count($this->results[1]->cases()) == 3);
 });
 describe("reporter", function () {
     describe("#before_all", function () {
         it("should be called once", function () {
             ok($this->config->reporter->before_all == 1);
Esempio n. 3
0
 public function run($args = null)
 {
     // parse options
     $br = PHP_EOL;
     $this->parse($args);
     $options = $this->cmd->getOptions();
     // setup loader and test config, test world
     Preview::$world = new World();
     Preview::$config = new Configuration();
     $loader = new Loader();
     // get parsed args, update config and load test files.
     $config_file = "preview.config.php";
     if (isset($options["config"])) {
         $config_file = $options["config"];
     }
     $config_file = realpath($config_file);
     if (is_file($config_file)) {
         Preview::$config->load_from_file($config_file);
     }
     if (isset($options["help"])) {
         $this->cmd->showHelp($this->padding);
         exit(0);
     }
     if (isset($options["list-reporters"])) {
         $reporters = array("spec (defualt)", "dropdown", "tree", "dot", "line", "blank");
         foreach ($reporters as $index => $reporter) {
             $index = $index + 1;
             echo "    {$index}) {$reporter}{$br}";
         }
         echo $br;
         exit(0);
     }
     if (isset($options["reporter"])) {
         $reporter_class = ucfirst($options['reporter']);
         $reporter = "\\Preview\\Reporter\\{$reporter_class}";
         Preview::$config->reporter = new $reporter();
     }
     if (isset($options["backtrace"])) {
         Preview::$config->full_backtrace = true;
     }
     if (isset($options["no-this"])) {
         Preview::$config->use_implicit_context = false;
     }
     if (isset($options["no-color"])) {
         Preview::$config->color_support = false;
     }
     if (isset($options["with-error"])) {
         Preview::$config->error_exception = false;
     }
     if (isset($options["fail-fast"])) {
         Preview::$config->fail_fast = true;
     }
     if (isset($options["order"])) {
         Preview::$config->order = true;
     }
     if (isset($options["group"])) {
         Preview::$config->test_groups = explode(",", $options["group"]);
     }
     if (isset($options["exclude-group"])) {
         Preview::$config->exclude_groups = explode(",", $options["exclude-group"]);
     }
     if (isset($options["title"])) {
         Preview::$config->title = $options["title"];
     }
     $files = $this->cmd->getOperands();
     // default help message
     if (empty($options) and empty($files)) {
         $this->cmd->showHelp($this->padding);
         exit(0);
     }
     // load all test file
     foreach ($files as $file) {
         $loader->load($file);
     }
     // list groups
     if (isset($options["list-groups"])) {
         $groups = Preview::$world->groups();
         if (empty($groups)) {
             echo "    No test groups.{$br}{$br}";
             exit(0);
         }
         foreach ($groups as $index => $group) {
             $index = $index + 1;
             echo "    {$index}) {$group}{$br}";
         }
         echo $br;
         exit(0);
     }
     $this->execute();
 }