File
2 years ago
Fixtures
2 years ago
Session
2 years ago
schema
2 years ago
AcceptHeaderItemTest.php
2 years ago
AcceptHeaderTest.php
2 years ago
ApacheRequestTest.php
2 years ago
BinaryFileResponseTest.php
2 years ago
CookieTest.php
2 years ago
ExpressionRequestMatcherTest.php
2 years ago
FileBagTest.php
2 years ago
HeaderBagTest.php
2 years ago
IpUtilsTest.php
2 years ago
JsonResponseTest.php
2 years ago
ParameterBagTest.php
2 years ago
RedirectResponseTest.php
2 years ago
RequestMatcherTest.php
2 years ago
RequestStackTest.php
2 years ago
RequestTest.php
2 years ago
ResponseFunctionalTest.php
2 years ago
ResponseHeaderBagTest.php
2 years ago
ResponseTest.php
2 years ago
ResponseTestCase.php
2 years ago
ServerBagTest.php
2 years ago
StreamedResponseTest.php
2 years ago
StreamedResponseTest.php
144 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | * |
| 11 | * Modified by impress-org on 23-January-2024 using Strauss. |
| 12 | * @see https://github.com/BrianHenryIE/strauss |
| 13 | */ |
| 14 | |
| 15 | namespace Give\Vendors\Symfony\Component\HttpFoundation\Tests; |
| 16 | |
| 17 | use PHPUnit\Framework\TestCase; |
| 18 | use Give\Vendors\Symfony\Component\HttpFoundation\Request; |
| 19 | use Give\Vendors\Symfony\Component\HttpFoundation\StreamedResponse; |
| 20 | |
| 21 | class StreamedResponseTest extends TestCase |
| 22 | { |
| 23 | public function testConstructor() |
| 24 | { |
| 25 | $response = new StreamedResponse(function () { echo 'foo'; }, 404, ['Content-Type' => 'text/plain']); |
| 26 | |
| 27 | $this->assertEquals(404, $response->getStatusCode()); |
| 28 | $this->assertEquals('text/plain', $response->headers->get('Content-Type')); |
| 29 | } |
| 30 | |
| 31 | public function testPrepareWith11Protocol() |
| 32 | { |
| 33 | $response = new StreamedResponse(function () { echo 'foo'; }); |
| 34 | $request = Request::create('/'); |
| 35 | $request->server->set('SERVER_PROTOCOL', 'HTTP/1.1'); |
| 36 | |
| 37 | $response->prepare($request); |
| 38 | |
| 39 | $this->assertEquals('1.1', $response->getProtocolVersion()); |
| 40 | $this->assertNotEquals('chunked', $response->headers->get('Transfer-Encoding'), 'Apache assumes responses with a Transfer-Encoding header set to chunked to already be encoded.'); |
| 41 | } |
| 42 | |
| 43 | public function testPrepareWith10Protocol() |
| 44 | { |
| 45 | $response = new StreamedResponse(function () { echo 'foo'; }); |
| 46 | $request = Request::create('/'); |
| 47 | $request->server->set('SERVER_PROTOCOL', 'HTTP/1.0'); |
| 48 | |
| 49 | $response->prepare($request); |
| 50 | |
| 51 | $this->assertEquals('1.0', $response->getProtocolVersion()); |
| 52 | $this->assertNull($response->headers->get('Transfer-Encoding')); |
| 53 | } |
| 54 | |
| 55 | public function testPrepareWithHeadRequest() |
| 56 | { |
| 57 | $response = new StreamedResponse(function () { echo 'foo'; }, 200, ['Content-Length' => '123']); |
| 58 | $request = Request::create('/', 'HEAD'); |
| 59 | |
| 60 | $response->prepare($request); |
| 61 | |
| 62 | $this->assertSame('123', $response->headers->get('Content-Length')); |
| 63 | } |
| 64 | |
| 65 | public function testPrepareWithCacheHeaders() |
| 66 | { |
| 67 | $response = new StreamedResponse(function () { echo 'foo'; }, 200, ['Cache-Control' => 'max-age=600, public']); |
| 68 | $request = Request::create('/', 'GET'); |
| 69 | |
| 70 | $response->prepare($request); |
| 71 | $this->assertEquals('max-age=600, public', $response->headers->get('Cache-Control')); |
| 72 | } |
| 73 | |
| 74 | public function testSendContent() |
| 75 | { |
| 76 | $called = 0; |
| 77 | |
| 78 | $response = new StreamedResponse(function () use (&$called) { ++$called; }); |
| 79 | |
| 80 | $response->sendContent(); |
| 81 | $this->assertEquals(1, $called); |
| 82 | |
| 83 | $response->sendContent(); |
| 84 | $this->assertEquals(1, $called); |
| 85 | } |
| 86 | |
| 87 | public function testSendContentWithNonCallable() |
| 88 | { |
| 89 | $this->expectException('LogicException'); |
| 90 | $response = new StreamedResponse(null); |
| 91 | $response->sendContent(); |
| 92 | } |
| 93 | |
| 94 | public function testSetContent() |
| 95 | { |
| 96 | $this->expectException('LogicException'); |
| 97 | $response = new StreamedResponse(function () { echo 'foo'; }); |
| 98 | $response->setContent('foo'); |
| 99 | } |
| 100 | |
| 101 | public function testGetContent() |
| 102 | { |
| 103 | $response = new StreamedResponse(function () { echo 'foo'; }); |
| 104 | $this->assertFalse($response->getContent()); |
| 105 | } |
| 106 | |
| 107 | public function testCreate() |
| 108 | { |
| 109 | $response = StreamedResponse::create(function () {}, 204); |
| 110 | |
| 111 | $this->assertInstanceOf('Give\Vendors\Symfony\Component\HttpFoundation\StreamedResponse', $response); |
| 112 | $this->assertEquals(204, $response->getStatusCode()); |
| 113 | } |
| 114 | |
| 115 | public function testReturnThis() |
| 116 | { |
| 117 | $response = new StreamedResponse(function () {}); |
| 118 | $this->assertInstanceOf('Give\Vendors\Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent()); |
| 119 | $this->assertInstanceOf('Give\Vendors\Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent()); |
| 120 | |
| 121 | $response = new StreamedResponse(function () {}); |
| 122 | $this->assertInstanceOf('Give\Vendors\Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders()); |
| 123 | $this->assertInstanceOf('Give\Vendors\Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders()); |
| 124 | } |
| 125 | |
| 126 | public function testSetNotModified() |
| 127 | { |
| 128 | $response = new StreamedResponse(function () { echo 'foo'; }); |
| 129 | $modified = $response->setNotModified(); |
| 130 | $this->assertObjectHasAttribute('headers', $modified); |
| 131 | $this->assertObjectHasAttribute('content', $modified); |
| 132 | $this->assertObjectHasAttribute('version', $modified); |
| 133 | $this->assertObjectHasAttribute('statusCode', $modified); |
| 134 | $this->assertObjectHasAttribute('statusText', $modified); |
| 135 | $this->assertObjectHasAttribute('charset', $modified); |
| 136 | $this->assertEquals(304, $modified->getStatusCode()); |
| 137 | |
| 138 | ob_start(); |
| 139 | $modified->sendContent(); |
| 140 | $string = ob_get_clean(); |
| 141 | $this->assertEmpty($string); |
| 142 | } |
| 143 | } |
| 144 |