/**
  * @param BenchmarkInterface $benchmark
  * @param string $field
  * @param mixed $value
  * @return bool
  */
 protected function acceptFilter(BenchmarkInterface $benchmark, $field, $value)
 {
     if (is_array($value)) {
         return in_array($benchmark->getMetadataValue($field), $value, true);
     }
     return $benchmark->getMetadataValue($field) === $value;
 }
Esempio n. 2
0
 /**
  * @covers Fabfuel\Prophiler\Toolbar\Formatter\TimelineFormatter::getOffset
  * @covers Fabfuel\Prophiler\Toolbar\Formatter\TimelineFormatter::getProfilerDuration
  * @uses Fabfuel\Prophiler\Toolbar\Formatter\TimelineFormatter
  * @uses Fabfuel\Prophiler\Toolbar\Formatter\BenchmarkFormatterAbstract
  */
 public function testGetOffset()
 {
     $startTimeBenchmark = 100000;
     $startTimeProfiler = 100050;
     $durationProfiler = 100;
     $this->benchmark->expects($this->any())->method('getStartTime')->willReturn($startTimeBenchmark);
     $this->profiler->expects($this->any())->method('getStartTime')->willReturn($startTimeProfiler);
     $this->profiler->expects($this->any())->method('getDuration')->willReturn($durationProfiler);
     $offset = $startTimeBenchmark - $startTimeProfiler;
     $expectedOffset = number_format($offset / ($durationProfiler * TimelineFormatter::TIMEBUFFER_FACTOR) * 100, 2, '.', '');
     $this->assertSame($expectedOffset, $this->formatter->getOffset());
 }
Esempio n. 3
0
 /**
  * @param BenchmarkInterface $benchmark
  */
 public function aggregate(BenchmarkInterface $benchmark)
 {
     $this->totalExecutions += 1;
     $this->totalDuration += (double) $benchmark->getDuration();
     $this->avgDuration = (double) $this->totalDuration / $this->totalExecutions;
     if ($benchmark->getDuration() > $this->maxDuration) {
         $this->maxDuration = (double) $benchmark->getDuration();
     }
     if ($benchmark->getDuration() < $this->minDuration || !$this->minDuration) {
         $this->minDuration = (double) $benchmark->getDuration();
     }
     $this->benchmarks[] = $benchmark;
 }
Esempio n. 4
0
 /**
  * @param string $severity
  * @param string $colorClass
  * @dataProvider getLabels
  */
 public function testGetLabels($severity, $colorClass)
 {
     $this->benchmark->expects($this->any())->method('getMetadata')->willReturn(['severity' => $severity]);
     $this->assertSame($colorClass, $this->formatter->getLabel());
 }
Esempio n. 5
0
 /**
  * @param BenchmarkInterface $benchmark
  * @return string
  */
 public function getCommand(BenchmarkInterface $benchmark)
 {
     return $benchmark->getName();
 }
 public function testGetMetadata()
 {
     $this->benchmark->expects($this->once())->method('getMetadata')->willReturn(['lorem' => 'ipsum']);
     $this->assertSame(['lorem' => 'ipsum'], $this->formatter->getMetadata());
 }
Esempio n. 7
0
 /**
  * @param BenchmarkInterface $benchmark
  * @return string
  */
 public function getCommand(BenchmarkInterface $benchmark)
 {
     return $benchmark->getMetadataValue('query') ?: $benchmark->getName();
 }