Beispiel #1
0
 /**
  * @throws Exception\RuntimeException
  * @return Collection The result of tests
  */
 public function run()
 {
     $breakOnFailure = $this->getConfig()->getBreakOnFailure();
     $em = $this->getEventManager();
     $testRun = new RunEvent();
     $results = new Collection();
     $testRun->setResults($results);
     $testRun->setParam('tests', $this->tests);
     // trigger START event
     $em->trigger(RunEvent::EVENT_START, $testRun);
     // Iterate over all tests
     foreach ($this->tests as $test) {
         $testRun->setTarget($test);
         $testRun->clearLastResult();
         // Skip testing if BEFORE_RUN returned false or has been stopped
         $beforeRun = $em->trigger(RunEvent::EVENT_BEFORE_RUN, $testRun);
         if ($beforeRun->stopped() || $beforeRun->contains(false)) {
             continue;
         }
         // Run the test!
         $result = $em->trigger(RunEvent::EVENT_RUN, $testRun, function ($r) {
             if ($r instanceof ResultInterface) {
                 return true;
             } else {
                 return false;
             }
         })->last();
         // Interpret result
         if (!is_object($result) || !$result instanceof ResultInterface) {
             $what = is_object($result) ? 'object of class ' . get_class($result) : gettype($result);
             throw new RuntimeException('Test run resulted in ' . $what . ' Expected instance of ' . __NAMESPACE__ . '\\Result\\ResultInterface');
         }
         // Save test result
         $results[$test] = $result;
         $testRun->setLastResult($result);
         // Stop testing if AFTER_RUN returned false or has been stopped
         $afterRun = $em->trigger(RunEvent::EVENT_AFTER_RUN, $testRun);
         if ($afterRun->stopped() || $afterRun->contains(false)) {
             $em->trigger(RunEvent::EVENT_STOP, $testRun);
             break;
         }
         // Stop testing on first failure
         if ($breakOnFailure && $result instanceof Failure) {
             $em->trigger(RunEvent::EVENT_STOP, $testRun);
             break;
         }
     }
     // trigger FINISH event
     $em->trigger(RunEvent::EVENT_FINISH, $testRun);
     return $results;
 }
Beispiel #2
0
 public function testStoppedNotice()
 {
     $e = new RunEvent();
     $tests = array();
     $test = null;
     $results = new Collection();
     for ($x = 0; $x < 15; $x++) {
         $tests[] = $test = new AlwaysSuccessTest();
         $results[$test] = new Success();
     }
     $e->setParam('tests', $tests);
     $e->setResults($results);
     ob_start();
     $this->em->trigger(RunEvent::EVENT_START, $e);
     ob_clean();
     $this->em->trigger(RunEvent::EVENT_STOP, $e);
     $this->em->trigger(RunEvent::EVENT_FINISH, $e);
     $this->assertStringMatchesFormat('%ADiagnostics aborted%A', trim(ob_get_clean()));
 }