/** * Dispatch a report to storage. * * @param \Scientist\Experiment $experiment * @param \Scientist\Report $report * @return mixed */ public function report(Experiment $experiment, Report $report) { $this->experiment = $experiment; $this->report = $report; $results = $report->getTrials(); if (isset($results['control'])) { throw new Exception('Please use a trial name other than "control"'); } $results['control'] = $report->getControl(); /** @var Result $result */ foreach ($results as $key => $result) { $data_array = [$this->config->getIsMatchKey() => $result->isMatch(), $this->config->getStartTimeKey() => $result->getStartTime(), $this->config->getEndTimeKey() => $result->getEndTime(), $this->config->getTimeKey() => $result->getTime(), $this->config->getStartMemoryKey() => $result->getStartMemory(), $this->config->getEndMemoryKey() => $result->getEndMemory(), $this->config->getMemoryKey() => $result->getMemory()]; if ($this->config->shouldReportValue()) { $data_array[$this->config->getValueKey()] = $this->config->formatValue($result->getValue()); } $this->logger->{$this->config->getLevel()}($this->config->formatMessage($experiment, $report, $result, $key), $data_array); } }
public function test_that_report_can_hold_multiple_trial_results() { $r = new Result(); $rp = new Report('foo', $r, ['bar' => $r, 'baz' => $r]); $this->assertInstanceOf(Result::class, $rp->getTrial('bar')); $this->assertInstanceOf(Result::class, $rp->getTrial('baz')); $this->assertSame($r, $rp->getTrial('bar')); $this->assertSame($r, $rp->getTrial('baz')); $this->assertCount(2, $rp->getTrials()); $this->assertEquals(['bar' => $r, 'baz' => $r], $rp->getTrials()); }
public function test_that_report_can_hold_multiple_trial_results() { $r = new Result(); $rp = new Report('foo', $r, array('bar' => $r, 'baz' => $r)); $this->assertInstanceOf('\\Scientist\\Result', $rp->getTrial('bar')); $this->assertInstanceOf('\\Scientist\\Result', $rp->getTrial('baz')); $this->assertSame($r, $rp->getTrial('bar')); $this->assertSame($r, $rp->getTrial('baz')); $this->assertCount(2, $rp->getTrials()); $this->assertEquals(array('bar' => $r, 'baz' => $r), $rp->getTrials()); }
/** * Format the message to be used * * @param Experiment $experiment * @param Report $report * @param Result $result * @param string $result_key * * @return string */ public function formatMessage(Experiment $experiment, Report $report, Result $result, $result_key) { return "{$report->getName()}: {$result_key}"; }