Exemplo n.º 1
0
 /**
  *    Uses reflection to run every method within itself
  *    starting with the string "test" unless a method
  *    is specified.
  *    @param SimpleReporter $reporter    Current test reporter.
  *    @return boolean                    True if all tests passed.
  *    @access public
  */
 function run($reporter)
 {
     /*
     Make sure that each (possibly nested!) test has its own fail/error/... queues, etc.
     so that the expectXXX() functions work like you'ld expect, even when a test invokes
     another test instance's run() method.
     
     BREAKING CHANGE: We do know that tests might want to access the context which was used
     to invoke the inner run(), but we MUST pop the context once the run() itself is
     done to ensure that all expectXXX queues are aligned with the correct (nested)
     tests. Hence, when a user wants access to the inner context's reporter, they should
     ask the test instance, not the global scope. (See test/errors_test.php ~ line )
     We do NOT pop context at the end of this call. Instead,
     we use a heuristic to keep the chain/number of contexts to a minimum by popping
     all /sub/contexts before we return, as those won't be accessible by grandparent
     tests anyhow.
     */
     $this->running = true;
     $context = SimpleTest::pushContext();
     $context->setTest($this);
     $context->setReporter($reporter);
     $this->reporter = $reporter;
     $started = false;
     foreach ($this->getTests() as $method) {
         if ($reporter->shouldInvoke($this->getLabel(), $method)) {
             $this->skip();
             if ($this->should_skip) {
                 break;
             }
             if (!$started) {
                 $reporter->paintCaseStart($this->getLabel());
                 $started = true;
             }
             $invoker = $this->reporter->createInvoker($this->createInvoker());
             $invoker->before($method);
             $invoker->invoke($method);
             $invoker->after($method);
         }
     }
     if ($started) {
         $reporter->paintCaseEnd($this->getLabel());
     }
     //$context->setTest(null);
     SimpleTest::popContext($context);
     $this->running = false;
     return $reporter->getStatus();
 }