merged branch fabpot/client-streamed-response (PR #5961)

This PR was merged into the 2.1 branch.

Commits
-------

84b760b [HttpKernel] fixed Client when using StreamedResponses (closes #5370)

Discussion
----------

[HttpKernel] fixed Client when using StreamedResponses (closes #5370)
This commit is contained in:
Fabien Potencier 2012-11-10 09:18:00 +01:00
commit 5bdf8cbaf9
2 changed files with 23 additions and 1 deletions

View File

@ -179,6 +179,11 @@ EOF;
$headers['Set-Cookie'] = $cookies;
}
return new DomResponse($response->getContent(), $response->getStatusCode(), $headers);
// this is needed to support StreamResponse
ob_start();
$response->sendContent();
$content = ob_get_clean();
return new DomResponse($content, $response->getStatusCode(), $headers);
}
}

View File

@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpKernel\Tests\Fixtures\TestClient;
@ -86,6 +87,22 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, $domResponse->getHeader('Set-Cookie', false));
}
public function testFilterResponseSupportsStreamedResponses()
{
$client = new Client(new TestHttpKernel());
$r = new \ReflectionObject($client);
$m = $r->getMethod('filterResponse');
$m->setAccessible(true);
$response = new StreamedResponse(function () {
echo 'foo';
});
$domResponse = $m->invoke($client, $response);
$this->assertEquals('foo', $domResponse->getContent());
}
public function testUploadedFile()
{
$source = tempnam(sys_get_temp_dir(), 'source');