public function testItErrorsWhenIncorrectStatusCodeIsFound() { try { Response::createFromString("010 server ready - posting allowed\r\n"); $this->fail('::createFromString() throws a Rvdv\\Nntp\\Exception\\RuntimeException because status code is less than 100'); } catch (\Exception $e) { $this->assertInstanceof('Rvdv\\Nntp\\Exception\\RuntimeException', $e, '::createFromString() throws a Rvdv\\Nntp\\Exception\\RuntimeException because status code is less than 100'); } try { Response::createFromString("700 server ready - posting allowed\r\n"); $this->fail('::createFromString() throws a Rvdv\\Nntp\\Exception\\RuntimeException because status code is greater than 600'); } catch (\Exception $e) { $this->assertInstanceof('Rvdv\\Nntp\\Exception\\RuntimeException', $e, '::createFromString() throws a Rvdv\\Nntp\\Exception\\RuntimeException because status code is greater than 600'); } }
public function testItReturnsInjectedResponseAsString() { $response = Response::createFromString("200 server ready - posting allowed\r\n"); $multiLineResponse = new MultiLineResponse($response, new \SplFixedArray()); $this->assertEquals('server ready - posting allowed [200]', (string) $multiLineResponse); }
protected function getResponse() { $buffer = ''; while (!$this->socket->eof()) { $buffer .= $this->socket->gets(self::BUFFER_SIZE); if ("\r\n" === substr($buffer, -2)) { break; } if ($buffer === false) { $this->disconnect(); throw new RuntimeException('Incorrect data received from buffer'); } } return Response::createFromString($buffer); }