given( $port = mt_rand(10000, 12000), exec( sprintf( 'php -S 127.0.0.1:%d -t %s > /dev/null 2>&1 & echo $! && sleep 0.2', $port, dirname(__DIR__) . DS . 'Fixtures' ), $outputs ), $pid = $outputs[0], $stream = new SUT('http://127.0.0.1:' . $port, null, true), $stream->on( 'connect', function (Event\Bucket $bucket) use ($self, &$connectCalled) { $connectCalled = true; $data = $bucket->getData(); $self ->array($data) ->isEqualTo([ 'code' => 0, 'severity' => 0, 'message' => null, 'transferred' => 0, 'max' => 0 ]); } ), $stream->on( 'mimetype', function (Event\Bucket $bucket) use ($self, &$mimetypeCalled) { $mimetypeCalled = true; $data = $bucket->getData(); $self ->array($data) ->isEqualTo([ 'code' => 0, 'severity' => 0, 'message' => 'text/html; charset=UTF-8', 'transferred' => 0, 'max' => 0 ]); } ), $stream->on( 'size', function (Event\Bucket $bucket) use ($self, &$sizeCalled) { $sizeCalled = true; $data = $bucket->getData(); $self ->array($data) ->isEqualTo([ 'code' => 0, 'severity' => 0, 'message' => 'Content-Length: 14', 'transferred' => 0, 'max' => 14 ]); } ), $stream->on( 'progress', function (Event\Bucket $bucket) use ($self, &$progressCalled) { $progressCalled = true; $data = $bucket->getData(); $self ->array($data) ->isEqualTo([ 'code' => 0, 'severity' => 0, 'message' => null, 'transferred' => 0, 'max' => 14 ]); } ) ) ->when($stream->open()) ->then ->boolean($connectCalled) ->isTrue() ->boolean($mimetypeCalled) ->isTrue() ->boolean($sizeCalled) ->isTrue() ->boolean($progressCalled) ->isTrue() ->let(!empty($pid) && exec('kill ' . $pid)); } } class SUT extends LUT\Stream { protected function &_open($streamName, LUT\Context $context = null) { if (null === $context) { $out = fopen($streamName, 'rb'); } else { $out = fopen($streamName, 'rb', false, $context->getContext()); } return $out; } protected function _close() { return fclose($this->getStream()); } }