/** * @param SourceInterface $source */ public function store(SourceInterface $source) { $chunk = []; foreach ($source->getMetrics() as $metric) { $chunk[] = $metric; if (count($chunk) === $this->chunkSize) { } } }
public function it_stores_metrics(Stream $stream, FormatterInterface $formatter, SourceInterface $source, Metric $metric1, Metric $metric2) { $source->getMetrics()->willReturn([$metric1, $metric2])->shouldBeCalled(); $formatter->format($metric1)->willReturn('metric_1_formatted')->shouldBeCalled(); $formatter->format($metric2)->willReturn('metric_2_formatted')->shouldBeCalled(); $stream->write('metric_1_formatted')->shouldBeCalled(); $stream->write('metric_2_formatted')->shouldBeCalled(); $this->store($source); }
public function it_returns_metrics(SourceInterface $source1, SourceInterface $source2, Metric $metric1, Metric $metric2, Metric $metric3, Metric $metric4) { $source1->getMetrics()->willReturn([$metric1])->shouldBeCalled(); $source2->getMetrics()->willReturn([$metric2, $metric3, $metric4])->shouldBeCalled(); $result = $this->getMetrics(); $result->shouldHaveCount(4); $result[0]->shouldBe($metric1); $result[1]->shouldBe($metric2); $result[2]->shouldBe($metric3); $result[3]->shouldBe($metric4); }
/** * @param SourceInterface $source */ public function store(SourceInterface $source) { foreach ($source->getMetrics() as $metric) { $this->stream->write($this->formatter->format($metric)); } }