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 */ public function write($text) { if (!$this->writable) { return $this->throwAndEmitException(new IoWriteException('Stream is no longer writable.')); } $this->buffer->push($text); if (!$this->listening && !$this->paused) { $this->listening = true; $this->loop->addWriteStream($this->resource, [$this, 'handleWrite']); } return $this->buffer->length() < $this->bufferSize; }
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()); }
public function testApiLength_ReturnsLengthOfData() { $this->assertSame(strlen($this->initialString), $this->buffer->length()); }
/** * @override */ public function readResponse(BufferInterface $buffer, $data) { $buffer->push($data); if (($position = $buffer->search(self::HTTP_EOM)) === false) { if ($buffer->length() > $this->maxStartLineLength) { throw new IoReadException(sprintf('Message start line exceeded maximum size of %d bytes.', $this->maxStartLineLength)); } return null; } try { $response = $this->parser->parseResponse($buffer->drain()); } catch (Error $ex) { throw new InvalidFormatException('Could not parse start line.'); } catch (Exception $ex) { throw new InvalidFormatException('Could not parse start line.'); } return $response; }