Example #1
0
 public function test_that_we_can_retrieve_a_match_status_from_an_execution()
 {
     $e = new Execution('foo', 10.2, true, true);
     $this->assertTrue($e->isMatch());
     $e = new Execution('foo', 10.2, false, true);
     $this->assertFalse($e->isMatch());
 }
Example #2
0
 /**
  * Execute a callback and record an execution.
  *
  * @param callable                    $callable
  * @param array                       $params
  * @param \Scientist\Matchers\Matcher $matcher
  * @param \Scientist\Execution|null   $control
  *
  * @return \Scientist\Execution
  */
 protected function executeCallback(callable $callable, array $params, Matcher $matcher, Execution $control = null)
 {
     /**
      * We'll execute the provided callable between two
      * recorded timestamps, so that we can calculate
      * the execution time of the code.
      */
     $exception = null;
     $before = microtime(true);
     if ($control) {
         try {
             $value = call_user_func_array($callable, $params);
         } catch (Exception $ex) {
             $value = null;
             $exception = $ex;
         }
     } else {
         $value = call_user_func_array($callable, $params);
     }
     $after = microtime(true);
     /**
      * A control value is provided for trail executions.
      */
     $compare = $control ? $control->getValue() : null;
     return new Execution($value, $after - $before, $matcher->match($value, $compare), $exception);
 }