Example #1
0
 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());
 }
Example #2
0
 /**
  * @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;
 }
Example #3
0
 /**
  *
  */
 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());
 }
Example #4
0
 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());
 }
Example #5
0
 public function testGetInterator()
 {
     $iterator = $this->buffer->getIterator();
     $this->assertInstanceOf(BufferIterator::class, $iterator);
 }