/** * Encodes request into an traversable of records. * * @return Traversable|Record[] */ public function toRecords() { $result = [new Record(new Header(RecordType::beginRequest(), $this->getRequestId(), 8), \pack('xCCxxxxx', $this->role->value(), 0xff & ($this->keepConnection ? 1 : 0)))]; foreach ($this->getParameters()->encode($this->getRequestId()) as $value) { $result[] = $value; } while ($chunk = $this->stdin->read(65535)) { $result[] = new Record(new Header(RecordType::stdin(), $this->getRequestId(), strlen($chunk)), $chunk); } $result[] = new Record(new Header(RecordType::stdin(), $this->getRequestId(), 0, 0), ''); return new ArrayIterator($result); }
/** * @dataProvider payloadLengthMismatchExamples * @uses \Crunch\FastCGI\Protocol\Header * @uses \Crunch\FastCGI\Protocol\RecordType * @param integer $length * @param string $payload */ public function testPayloadLengthMismatch($length, $payload) { $this->setExpectedException('\\LengthException'); $header = new Header(RecordType::beginRequest(), 1, $length); new Record($header, $payload); }
/** * @covers ::beginRequest */ public function testDirectInstancationMethodOfBeginRequest() { $expectedRecordType = RecordType::instance(RecordType::BEGIN_REQUEST); $recordType = RecordType::beginRequest(); self::assertSame($expectedRecordType, $recordType); }