public function testIteration() { $result = null; for ($i = 0, $this->iterator->rewind(); $this->iterator->valid(); ++$i, $this->iterator->next()) { if ($i !== $this->iterator->key()) { $this->fail('Got invalid key from iterator.'); } $result .= $this->iterator->current(); } $this->assertSame($this->initialString, $result); $this->iterator->prev(); $this->assertTrue($this->iterator->valid()); $this->assertSame($this->buffer->length() - 1, $this->iterator->key()); }
/** * @override * @inheritDoc */ public function readResponse(BufferInterface $buffer, $data) { $buffer->push($data); if (($position = $buffer->search(self::HTTP_EOM)) === false) { if ($buffer->length() > $this->maxFrameSize) { throw new ReadException(sprintf('Message start line exceeded maximum size of %d bytes.', $this->maxFrameSize)); } return null; } try { return $this->parser->parseResponse($buffer->drain()); } catch (Error $ex) { } catch (Exception $ex) { } throw new InvalidFormatException('Could not parse start line.'); }
/** * */ private function writeEnd() { do { try { $sent = fwrite($this->resource, $this->buffer->peek()); $this->buffer->remove($sent); } catch (Error $ex) { $sent = 0; } catch (Exception $ex) { $sent = 0; } } while (is_resource($this->resource) && $sent > 0 && !$this->buffer->isEmpty()); }
public function testGetInterator() { $iterator = $this->buffer->getIterator(); $this->assertInstanceOf(BufferIterator::class, $iterator); }
public function testApiSeek() { $this->iterator->seek($this->buffer->length() - 1); $this->assertSame($this->buffer->length() - 1, $this->iterator->key()); $this->assertSame(substr($this->buffer, -1), $this->iterator->current()); }