public function test_that_we_can_retrieve_a_value_from_an_execution() { $e = new Execution('foo', 10.0, true, true); $this->assertEquals('foo', $e->getValue()); $e = new Execution('bar', 10.0, true, true); $this->assertEquals('bar', $e->getValue()); }
/** * 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); }