Example #1
0
 /**
  * Bootstraps parts of our test enviornment and iteratively invokes each
  * file.
  *
  * @return ResultSet
  */
 public function run()
 {
     $tests = $this->collectFiles();
     $this->emit('test_run.start');
     foreach ($tests as $test_file) {
         $suite = new Suite(new InvocationContext(), function () use($test_file) {
             require $test_file;
         }, $test_file->getPathName());
         $suite->build();
         $suite_result = new ResultSet();
         $suite_runner = new SuiteRunner($suite, $suite_result, array('grep' => $this->options['grep']));
         $this->result_set->addResult($suite_result);
         // Forward my listeners.
         foreach ($this->listeners as $listener) {
             $suite_runner->addListener($listener);
         }
         $suite_runner->run();
     }
     $this->emit('test_run.complete', array('result_set' => $this->result_set));
     return $this->result_set;
 }
Example #2
0
                });
            }
        }
    };
    return suite('Root', function ($ctx) use($generate) {
        $generate(1, array());
    });
}
describe('Ordering', function ($ctx) {
    it('should invoke 1 test and its hooks in the correct order.', function ($ctx) {
        $spy = new Spy();
        $suite = gentree($spy, 1, 1, array('before' => 1, 'after' => 1, 'before_all' => 1, 'after_all' => 1, 'it' => 1));
        $suite_runner = new SuiteRunner($suite, new ResultSet());
        $suite_runner->run();
        expect($spy->invocations)->to->eql(array('before_all.1', 'before.1', 'it.1', 'after.1', 'after_all.1'));
    });
    it('should invoke 2 tests and its hooks in the correct order.', function ($ctx) {
        $spy = new Spy();
        $suite = gentree($spy, 1, 1, array('before' => 1, 'after' => 1, 'before_all' => 1, 'after_all' => 1, 'it' => 2));
        $suite_runner = new SuiteRunner($suite, new ResultSet());
        $suite_runner->run();
        expect($spy->invocations)->to->eql(array('before_all.1', 'before.1', 'it.1', 'after.1', 'before.1', 'it.2', 'after.1', 'after_all.1'));
    });
    it('should invoke nested describes and their hooks in the correct order.', function ($ctx) {
        $spy = new Spy();
        $suite = gentree($spy, 2, 2, array('before' => 1, 'after' => 1, 'before_all' => 1, 'after_all' => 1, 'it' => 2));
        $suite_runner = new SuiteRunner($suite, new ResultSet());
        $suite_runner->run();
        expect($spy->invocations)->to->eql(array('before_all.1', 'before.1', 'it.1', 'after.1', 'before.1', 'it.2', 'after.1', 'describe.1.before_all.1', 'before.1', 'describe.1.before.1', 'describe.1.it.1', 'describe.1.after.1', 'after.1', 'before.1', 'describe.1.before.1', 'describe.1.it.2', 'describe.1.after.1', 'after.1', 'describe.1.after_all.1', 'describe.2.before_all.1', 'before.1', 'describe.2.before.1', 'describe.2.it.1', 'describe.2.after.1', 'after.1', 'before.1', 'describe.2.before.1', 'describe.2.it.2', 'describe.2.after.1', 'after.1', 'describe.2.after_all.1', 'after_all.1'));
    });
});