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); }
/** * Read the content of this stream and write it to another stream, by chunks of $bufferSize * * @param Stream $stream The destination stream to write to * * @return int Number of piped bytes */ public function pipe(Stream $stream) { return stream_copy_to_stream($this->getResource(), $stream->getResource()); }
/** * @param SourceInterface $source */ public function store(SourceInterface $source) { foreach ($source->getMetrics() as $metric) { $this->stream->write($this->formatter->format($metric)); } }
/** * @expectedException Streamer\Exception\LogicException */ public function testCloseThrowsExceptionOnClosedStreams() { $stream = new Stream(fopen('php://temp', 'r+')); $stream->close(); $stream->close(); }