From 4acf4d7c94b322ca2d7c70132c518e31910c27c0 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Wed, 3 May 2023 00:42:39 +0300 Subject: [PATCH 01/19] Support stream output --- src/SapiEmitter.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/SapiEmitter.php b/src/SapiEmitter.php index e157a1a..8a432c6 100644 --- a/src/SapiEmitter.php +++ b/src/SapiEmitter.php @@ -110,7 +110,15 @@ private function emitBody(ResponseInterface $response): void } while (!$body->eof()) { - echo $body->read($this->bufferSize); + $output = $body->read($this->bufferSize); + if ($output === '') { + continue; + } + echo $output; + // flush the output buffer and send echoed messages to the browser + while (ob_get_level() > 0) { + ob_end_flush(); + } flush(); } } From e52adf03074cb1afee07e0ea792dec217f90cab5 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Sun, 11 Jun 2023 15:17:40 +0300 Subject: [PATCH 02/19] Fix tests --- src/SapiEmitter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SapiEmitter.php b/src/SapiEmitter.php index 8a432c6..1223b80 100644 --- a/src/SapiEmitter.php +++ b/src/SapiEmitter.php @@ -109,6 +109,7 @@ private function emitBody(ResponseInterface $response): void $body->rewind(); } + $level = ob_get_level(); while (!$body->eof()) { $output = $body->read($this->bufferSize); if ($output === '') { @@ -116,7 +117,7 @@ private function emitBody(ResponseInterface $response): void } echo $output; // flush the output buffer and send echoed messages to the browser - while (ob_get_level() > 0) { + while (ob_get_level() > $level) { ob_end_flush(); } flush(); From 704604ffe0ac30c3ee1757231fd2525422481b38 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Sun, 9 Jul 2023 22:11:59 +0300 Subject: [PATCH 03/19] Add a test --- tests/SapiEmitterTest.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/SapiEmitterTest.php b/tests/SapiEmitterTest.php index ab8e57a..14e2c10 100644 --- a/tests/SapiEmitterTest.php +++ b/tests/SapiEmitterTest.php @@ -6,8 +6,8 @@ include 'Support/Emitter/httpFunctionMocks.php'; -use InvalidArgumentException; use HttpSoft\Message\Response; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -248,6 +248,24 @@ public function testEmitDuplicateHeaders(): void $this->expectOutputString($body); } + public function testObLevel(): void + { + ob_start(); + $expectedLevel = ob_get_level(); + $response = $this->createResponse(Status::OK, ['X-Test' => 1]); + + $this + ->createEmitter() + ->emit($response); + + (new SapiEmitter())->emit($response); + + $actualLevel = ob_get_level(); + $this->assertSame($expectedLevel, $actualLevel); + // clean output buffers before the end because phpunit has its own output buffers + ob_get_clean(); + } + private function createEmitter(?int $bufferSize = null): SapiEmitter { return new SapiEmitter($bufferSize); From fa98d0acfc20097f5cd465b7567f70d993c9aec1 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Sun, 9 Jul 2023 22:12:48 +0300 Subject: [PATCH 04/19] Add a changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 746ccf2..7f82d66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Yii Runner HTTP Change Log -## 2.0.1 under development +## 2.1.0 under development -- no changes in this release. +- Enh #50: Support stream output (@xepozz) ## 2.0.0 February 19, 2023 From 8baf26cfd9014293ea58af46f870990d5f8e7f08 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Sun, 9 Jul 2023 22:31:16 +0300 Subject: [PATCH 05/19] Add more code coverage --- tests/SapiEmitterTest.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/SapiEmitterTest.php b/tests/SapiEmitterTest.php index 14e2c10..4c71ddb 100644 --- a/tests/SapiEmitterTest.php +++ b/tests/SapiEmitterTest.php @@ -250,7 +250,6 @@ public function testEmitDuplicateHeaders(): void public function testObLevel(): void { - ob_start(); $expectedLevel = ob_get_level(); $response = $this->createResponse(Status::OK, ['X-Test' => 1]); @@ -262,8 +261,30 @@ public function testObLevel(): void $actualLevel = ob_get_level(); $this->assertSame($expectedLevel, $actualLevel); - // clean output buffers before the end because phpunit has its own output buffers - ob_get_clean(); + } + + public function testExtraObLevel(): void + { + $expectedLevel = ob_get_level(); + $stream = $this->createMock(StreamInterface::class); + $stream->method('read')->willReturnCallback(static function () { + ob_start(); + ob_start(); + ob_start(); + return '-'; + }); + $response = $this->createResponse(Status::OK, ['X-Test' => 1]) + ->withBody($stream) + ; + + $this + ->createEmitter() + ->emit($response); + + (new SapiEmitter())->emit($response); + + $actualLevel = ob_get_level(); + $this->assertSame($expectedLevel, $actualLevel); } private function createEmitter(?int $bufferSize = null): SapiEmitter From 23d89de28a761ea06727ee895cec80c2dfcd309e Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Sun, 9 Jul 2023 22:50:25 +0300 Subject: [PATCH 06/19] Fix tests --- tests/SapiEmitterTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/SapiEmitterTest.php b/tests/SapiEmitterTest.php index 4c71ddb..688d966 100644 --- a/tests/SapiEmitterTest.php +++ b/tests/SapiEmitterTest.php @@ -257,8 +257,6 @@ public function testObLevel(): void ->createEmitter() ->emit($response); - (new SapiEmitter())->emit($response); - $actualLevel = ob_get_level(); $this->assertSame($expectedLevel, $actualLevel); } @@ -273,6 +271,8 @@ public function testExtraObLevel(): void ob_start(); return '-'; }); + $stream->method('isReadable')->willReturn(true); + $stream->method('eof')->willReturnOnConsecutiveCalls(false, true); $response = $this->createResponse(Status::OK, ['X-Test' => 1]) ->withBody($stream) ; @@ -281,8 +281,6 @@ public function testExtraObLevel(): void ->createEmitter() ->emit($response); - (new SapiEmitter())->emit($response); - $actualLevel = ob_get_level(); $this->assertSame($expectedLevel, $actualLevel); } From dba4bcb8272603cb9224a40b7cde8ebc30e13687 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Mon, 11 Sep 2023 03:32:04 +0700 Subject: [PATCH 07/19] Fix emitter for stream response --- src/SapiEmitter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SapiEmitter.php b/src/SapiEmitter.php index 1223b80..47fd477 100644 --- a/src/SapiEmitter.php +++ b/src/SapiEmitter.php @@ -97,6 +97,7 @@ public function emit(ResponseInterface $response, bool $withoutBody = false): vo header("Content-Length: $contentLength", true); } } + flush(); $this->emitBody($response); } @@ -117,7 +118,7 @@ private function emitBody(ResponseInterface $response): void } echo $output; // flush the output buffer and send echoed messages to the browser - while (ob_get_level() > $level) { + while (ob_get_level() >= $level) { ob_end_flush(); } flush(); From d26b5ce5b709e3bce6ff95a4fe6be1990fc9b406 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Sat, 16 Sep 2023 17:03:39 +0300 Subject: [PATCH 08/19] Add one flush call for streamed responses --- src/SapiEmitter.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/SapiEmitter.php b/src/SapiEmitter.php index 1223b80..c7713b7 100644 --- a/src/SapiEmitter.php +++ b/src/SapiEmitter.php @@ -98,6 +98,13 @@ public function emit(ResponseInterface $response, bool $withoutBody = false): vo } } + /** + * Sends headers before the body. + * Makes a client possible to recognize the type of the body content if it is sent with a delay, + * for instance, for a streamed response. + */ + flush(); + $this->emitBody($response); } From f6f6dea5edeb49f1182307e6cf9d198a84f03619 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Sat, 16 Sep 2023 17:05:21 +0300 Subject: [PATCH 09/19] Add changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f82d66..d7136b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.1.0 under development -- Enh #50: Support stream output (@xepozz) +- Enh #50, #58: Support stream output (@xepozz) ## 2.0.0 February 19, 2023 From bf6b5a1fc4de88822f71b3b1a7578c20f1c021b2 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Sat, 16 Sep 2023 17:06:21 +0300 Subject: [PATCH 10/19] Fix changelog --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d706b69..a691910 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,8 @@ # Yii Runner HTTP Change Log -## 2.1.0 under development ## 2.1.1 under development -- Enh #50, #58: Support stream output (@xepozz) +- Enh #58: Support stream output headers (@xepozz) ## 2.1.0 July 10, 2023 From 8d5b6d20b3b184da5d21e7c8a3483a1ecfc8c7ae Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Tue, 27 Feb 2024 14:43:56 +0700 Subject: [PATCH 11/19] Update data providers --- tests/RequestFactoryTest.php | 6 +++--- tests/SapiEmitterTest.php | 4 ++-- tests/ServerRequestFactoryTest.php | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/RequestFactoryTest.php b/tests/RequestFactoryTest.php index 846ab46..5e8bf4d 100644 --- a/tests/RequestFactoryTest.php +++ b/tests/RequestFactoryTest.php @@ -84,7 +84,7 @@ public function testInvalidMethodException(): void $requestFactory->create(); } - public function bodyDataProvider(): array + public static function bodyDataProvider(): array { return [ 'string' => ['content', 'content'], @@ -105,7 +105,7 @@ public function testBody(string $expected, ?string $body): void $this->assertSame($expected, (string) $request->getBody()); } - public function hostParsingDataProvider(): array + public static function hostParsingDataProvider(): array { return [ 'host' => [ @@ -387,7 +387,7 @@ public function testHostParsingFromGlobals(array $serverParams, array $expectPar $this->assertSame($expectParams['query'], $request->getUri()->getQuery()); } - public function dataPostInParsedBody(): array + public static function dataPostInParsedBody(): array { return [ [ diff --git a/tests/SapiEmitterTest.php b/tests/SapiEmitterTest.php index 688d966..7e5c4f0 100644 --- a/tests/SapiEmitterTest.php +++ b/tests/SapiEmitterTest.php @@ -32,7 +32,7 @@ public static function tearDownAfterClass(): void HTTPFunctions::reset(); } - public function bufferSizeProvider(): array + public static function bufferSizeProvider(): array { return [[null], [1], [100], [1000]]; } @@ -56,7 +56,7 @@ public function testEmit(?int $bufferSize): void $this->expectOutputString($body); } - public function noBodyResponseCodeProvider(): array + public static function noBodyResponseCodeProvider(): array { return [[100], [101], [102], [204], [205], [304]]; } diff --git a/tests/ServerRequestFactoryTest.php b/tests/ServerRequestFactoryTest.php index 8f132d5..a08b88b 100644 --- a/tests/ServerRequestFactoryTest.php +++ b/tests/ServerRequestFactoryTest.php @@ -91,7 +91,7 @@ public function testInvalidMethodException(): void ->createFromParameters([]); } - public function bodyDataProvider(): array + public static function bodyDataProvider(): array { $content = 'content'; $resource = fopen('php://memory', 'wb+'); @@ -119,7 +119,7 @@ public function testBody(mixed $body, string $expected): void $this->assertSame($expected, (string) $request->getBody()); } - public function invalidBodyDataProvider(): array + public static function invalidBodyDataProvider(): array { return [ 'int' => [1], @@ -150,7 +150,7 @@ public function testInvalidBodyException(mixed $body): void ->createFromParameters($server, [], [], [], [], [], $body); } - public function hostParsingDataProvider(): array + public static function hostParsingDataProvider(): array { return [ 'host' => [ From 56cae2bebae70954cd7df364f1c3ca31da9c906e Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Tue, 27 Feb 2024 14:53:37 +0700 Subject: [PATCH 12/19] Replace internal stubs with xepozz/internal-mocker --- composer.json | 3 +- phpunit.xml.dist | 4 ++ tests/SapiEmitterTest.php | 4 +- tests/Support/Emitter/HTTPFunctions.php | 25 +++++++-- tests/Support/Emitter/HTTPFunctionsTest.php | 2 - tests/Support/Emitter/httpFunctionMocks.php | 49 ----------------- tests/Support/MockerExtension.php | 60 +++++++++++++++++++++ 7 files changed, 89 insertions(+), 58 deletions(-) delete mode 100644 tests/Support/Emitter/httpFunctionMocks.php create mode 100644 tests/Support/MockerExtension.php diff --git a/composer.json b/composer.json index 647275e..eadc8e9 100644 --- a/composer.json +++ b/composer.json @@ -50,6 +50,7 @@ "roave/infection-static-analysis-plugin": "^1.25", "spatie/phpunit-watcher": "^1.23", "vimeo/psalm": "^4.30|^5.2", + "xepozz/internal-mocker": "dev-stubs-generator", "yiisoft/middleware-dispatcher": "^5.0", "yiisoft/test-support": "^3.0" }, @@ -77,7 +78,7 @@ } }, "scripts": { - "test": "phpunit --testdox --no-interaction", + "test": "php -ddisable_functions=flush,header,http_response_code,headers_sent,header_remove ./vendor/bin/phpunit", "test-watch": "phpunit-watcher watch" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9d86391..aa612bb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -28,4 +28,8 @@ ./src + + + + diff --git a/tests/SapiEmitterTest.php b/tests/SapiEmitterTest.php index 7e5c4f0..b2bcdbd 100644 --- a/tests/SapiEmitterTest.php +++ b/tests/SapiEmitterTest.php @@ -4,8 +4,6 @@ namespace Yiisoft\Yii\Runner\Http\Tests; -include 'Support/Emitter/httpFunctionMocks.php'; - use HttpSoft\Message\Response; use InvalidArgumentException; use PHPUnit\Framework\TestCase; @@ -20,6 +18,8 @@ use function is_string; +use function is_string; + final class SapiEmitterTest extends TestCase { public function setUp(): void diff --git a/tests/Support/Emitter/HTTPFunctions.php b/tests/Support/Emitter/HTTPFunctions.php index 3192fb1..054e5f0 100644 --- a/tests/Support/Emitter/HTTPFunctions.php +++ b/tests/Support/Emitter/HTTPFunctions.php @@ -23,6 +23,7 @@ final class HTTPFunctions private static string $headersSentFile = ''; private static int $headersSentLine = 0; private static string $rawHttpHeader = ''; + private static int $flushedTimes = 0; /** * Reset state @@ -35,6 +36,7 @@ public static function reset(): void self::$headersSentFile = ''; self::$headersSentLine = 0; self::$rawHttpHeader = ''; + self::$flushedTimes = 0; } /** @@ -60,7 +62,7 @@ public static function headers_sent(&$file = null, &$line = null): bool /** * Send a raw HTTP header */ - public static function header(string $string, bool $replace = true, ?int $http_response_code = null): void + public static function header(string $string, bool $replace = true, ?int $http_response_code = 0): void { if (!str_starts_with($string, 'HTTP/')) { $header = strtolower(explode(':', $string, 2)[0]); @@ -71,7 +73,7 @@ public static function header(string $string, bool $replace = true, ?int $http_r } else { self::$rawHttpHeader = $string; } - if ($http_response_code !== null) { + if ($http_response_code !== 0) { self::$responseCode = $http_response_code; } } @@ -107,9 +109,9 @@ public static function headers_list(): array /** * Get or Set the HTTP response code */ - public static function http_response_code(?int $response_code = null): int + public static function http_response_code(?int $response_code = 0): int { - if ($response_code !== null) { + if ($response_code !== 0) { self::$responseCode = $response_code; } return self::$responseCode; @@ -127,4 +129,19 @@ public static function rawHttpHeader(): string { return self::$rawHttpHeader; } + + public static function getHeader(string $header): array + { + return self::$headers[strtolower($header)] ?? []; + } + + public static function flush(): void + { + self::$flushedTimes++; + } + + public static function getFlushTimes(): int + { + return self::$flushedTimes; + } } diff --git a/tests/Support/Emitter/HTTPFunctionsTest.php b/tests/Support/Emitter/HTTPFunctionsTest.php index 7806392..669b7d6 100644 --- a/tests/Support/Emitter/HTTPFunctionsTest.php +++ b/tests/Support/Emitter/HTTPFunctionsTest.php @@ -4,8 +4,6 @@ namespace Yiisoft\Yii\Runner\Http\Tests\Support\Emitter; -include 'httpFunctionMocks.php'; - use PHPUnit\Framework\TestCase; use Yiisoft\Http\Status; diff --git a/tests/Support/Emitter/httpFunctionMocks.php b/tests/Support/Emitter/httpFunctionMocks.php deleted file mode 100644 index fbf18cb..0000000 --- a/tests/Support/Emitter/httpFunctionMocks.php +++ /dev/null @@ -1,49 +0,0 @@ - '', + 'name' => 'http_response_code', + 'function' => fn(?int $response_code = null) => HTTPFunctions::http_response_code($response_code), + ], + [ + 'namespace' => '', + 'name' => 'header', + 'function' => fn(string $string, bool $replace = true, ?int $http_response_code = null) => HTTPFunctions::header($string, $replace, $http_response_code), + ], + [ + 'namespace' => '', + 'name' => 'headers_sent', + 'function' => fn(&$file = null, &$line = null) => HTTPFunctions::headers_sent($file, $line), + ], + [ + 'namespace' => '', + 'name' => 'header_remove', + 'function' => fn() => HTTPFunctions::header_remove(), + ], + [ + 'namespace' => '', + 'name' => 'header_list', + 'function' => fn() => HTTPFunctions::headers_list(), + ], + [ + 'namespace' => '', + 'name' => 'flush', + 'function' => fn() => HTTPFunctions::flush(), + ], + ]; + + $mocker = new Mocker(); + $mocker->load($mocks); + MockerState::saveState(); + } + + public function executeBeforeTest(string $test): void + { + MockerState::resetState(); + } + +} From 04f920f25b9ed03d4ef6b5e450cd9d5f1d4034ae Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Tue, 27 Feb 2024 15:02:40 +0700 Subject: [PATCH 13/19] Test flush --- src/SapiEmitter.php | 4 ++-- tests/SapiEmitterTest.php | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/SapiEmitter.php b/src/SapiEmitter.php index cb2fd83..1911254 100644 --- a/src/SapiEmitter.php +++ b/src/SapiEmitter.php @@ -10,6 +10,7 @@ use Yiisoft\Yii\Runner\Http\Exception\HeadersHaveBeenSentException; use function flush; +use function headers_sent; use function in_array; use function sprintf; @@ -97,7 +98,6 @@ public function emit(ResponseInterface $response, bool $withoutBody = false): vo header("Content-Length: $contentLength", true); } } - flush(); /** * Sends headers before the body. @@ -125,7 +125,7 @@ private function emitBody(ResponseInterface $response): void } echo $output; // flush the output buffer and send echoed messages to the browser - while (ob_get_level() >= $level) { + while (ob_get_level() > $level) { ob_end_flush(); } flush(); diff --git a/tests/SapiEmitterTest.php b/tests/SapiEmitterTest.php index b2bcdbd..9c5a812 100644 --- a/tests/SapiEmitterTest.php +++ b/tests/SapiEmitterTest.php @@ -18,8 +18,6 @@ use function is_string; -use function is_string; - final class SapiEmitterTest extends TestCase { public function setUp(): void @@ -285,6 +283,40 @@ public function testExtraObLevel(): void $this->assertSame($expectedLevel, $actualLevel); } + public function testFlushWithBody(): void + { + $stream = $this->createMock(StreamInterface::class); + $stream->method('read')->willReturnCallback(static fn() => '-'); + $stream->method('isReadable')->willReturn(true); + $stream->method('eof')->willReturnOnConsecutiveCalls(false, true); + $response = $this->createResponse(Status::OK, ['X-Test' => 1]) + ->withBody($stream); + + $this + ->createEmitter() + ->emit($response); + + $this->assertSame(['X-Test: 1'], HTTPFunctions::getHeader('X-Test')); + $this->assertSame(2, HTTPFunctions::getFlushTimes()); + } + + public function testFlushWithoutBody(): void + { + $stream = $this->createMock(StreamInterface::class); + $stream->method('isReadable')->willReturn(true); + $stream->method('eof')->willReturnOnConsecutiveCalls(true); + $response = $this->createResponse(Status::OK, ['X-Test' => 1]) + ->withBody($stream) + ; + + $this + ->createEmitter() + ->emit($response); + + $this->assertSame(['X-Test: 1'], HTTPFunctions::getHeader('X-Test')); + $this->assertSame(1, HTTPFunctions::getFlushTimes()); + } + private function createEmitter(?int $bufferSize = null): SapiEmitter { return new SapiEmitter($bufferSize); From 3ed2f019999ea089dec6b0ea2c8b22e96444c9b9 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Tue, 27 Feb 2024 15:07:26 +0700 Subject: [PATCH 14/19] Cover empty body buffer flush --- src/SapiEmitter.php | 3 +++ tests/SapiEmitterTest.php | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/SapiEmitter.php b/src/SapiEmitter.php index 1911254..f5be71c 100644 --- a/src/SapiEmitter.php +++ b/src/SapiEmitter.php @@ -121,6 +121,9 @@ private function emitBody(ResponseInterface $response): void while (!$body->eof()) { $output = $body->read($this->bufferSize); if ($output === '') { + while (ob_get_level() > $level) { + ob_end_flush(); + } continue; } echo $output; diff --git a/tests/SapiEmitterTest.php b/tests/SapiEmitterTest.php index 9c5a812..e4ce056 100644 --- a/tests/SapiEmitterTest.php +++ b/tests/SapiEmitterTest.php @@ -259,15 +259,30 @@ public function testObLevel(): void $this->assertSame($expectedLevel, $actualLevel); } - public function testExtraObLevel(): void + public static function dataExtraObLevel(): iterable + { + yield 'empty response' => [ + '', + 1, + ]; + yield 'some response' => [ + 'Example body', + 2, + ]; + } + + /** + * @dataProvider dataExtraObLevel + */ + public function testExtraObLevel(string $responseBody, int $expectedFlushes): void { $expectedLevel = ob_get_level(); $stream = $this->createMock(StreamInterface::class); - $stream->method('read')->willReturnCallback(static function () { + $stream->method('read')->willReturnCallback(static function () use ($responseBody) { ob_start(); ob_start(); ob_start(); - return '-'; + return $responseBody; }); $stream->method('isReadable')->willReturn(true); $stream->method('eof')->willReturnOnConsecutiveCalls(false, true); @@ -281,6 +296,7 @@ public function testExtraObLevel(): void $actualLevel = ob_get_level(); $this->assertSame($expectedLevel, $actualLevel); + $this->assertSame($expectedFlushes, HTTPFunctions::getFlushTimes()); } public function testFlushWithBody(): void From 1fafddb27c3255d951cb92382b8ecfc0b99a2e58 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 27 Feb 2024 08:07:43 +0000 Subject: [PATCH 15/19] Apply fixes from StyleCI --- tests/Support/MockerExtension.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Support/MockerExtension.php b/tests/Support/MockerExtension.php index 043339e..e4335f6 100644 --- a/tests/Support/MockerExtension.php +++ b/tests/Support/MockerExtension.php @@ -56,5 +56,4 @@ public function executeBeforeTest(string $test): void { MockerState::resetState(); } - } From 2a4190a2a697b5b9441d3474474ea6e383a5e131 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Tue, 27 Feb 2024 15:20:50 +0700 Subject: [PATCH 16/19] Pass disabled functions to CI --- .github/workflows/build.yml | 1 + .github/workflows/mutation.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d9a999f..755a00b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,6 +26,7 @@ jobs: uses: yiisoft/actions/.github/workflows/phpunit.yml@master with: extensions: sockets + ini-values: disable_functions=flush,header,http_response_code,headers_sent,header_remove os: >- ['ubuntu-latest', 'windows-latest'] php: >- diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index c1aca98..ce7963a 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -23,6 +23,7 @@ jobs: mutation: uses: yiisoft/actions/.github/workflows/roave-infection.yml@master with: + ini-values: disable_functions=flush,header,http_response_code,headers_sent,header_remove os: >- ['ubuntu-latest'] php: >- From 4ddd0f6c3a4b25eb9d1c6c19e35273950cb8b181 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Tue, 27 Feb 2024 15:23:29 +0700 Subject: [PATCH 17/19] Pass disabled functions to CI --- .github/workflows/build.yml | 2 +- .github/workflows/mutation.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 755a00b..d4430f2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: uses: yiisoft/actions/.github/workflows/phpunit.yml@master with: extensions: sockets - ini-values: disable_functions=flush,header,http_response_code,headers_sent,header_remove + ini-values: 'disable_functions=flush,header,http_response_code,headers_sent,header_remove' os: >- ['ubuntu-latest', 'windows-latest'] php: >- diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index ce7963a..770a974 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -23,7 +23,7 @@ jobs: mutation: uses: yiisoft/actions/.github/workflows/roave-infection.yml@master with: - ini-values: disable_functions=flush,header,http_response_code,headers_sent,header_remove + ini-values: 'disable_functions=flush,header,http_response_code,headers_sent,header_remove' os: >- ['ubuntu-latest'] php: >- From 45a31b5b65115a4942afb8498900d4d66eaf9516 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Tue, 27 Feb 2024 15:27:21 +0700 Subject: [PATCH 18/19] Pass disabled functions to CI --- .github/workflows/build.yml | 2 +- .github/workflows/mutation.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d4430f2..ce828ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: uses: yiisoft/actions/.github/workflows/phpunit.yml@master with: extensions: sockets - ini-values: 'disable_functions=flush,header,http_response_code,headers_sent,header_remove' + ini-values: disable_functions="flush,header,http_response_code,headers_sent,header_remove" os: >- ['ubuntu-latest', 'windows-latest'] php: >- diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 770a974..a08948e 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -23,7 +23,7 @@ jobs: mutation: uses: yiisoft/actions/.github/workflows/roave-infection.yml@master with: - ini-values: 'disable_functions=flush,header,http_response_code,headers_sent,header_remove' + ini-values: disable_functions="flush,header,http_response_code,headers_sent,header_remove" os: >- ['ubuntu-latest'] php: >- From 172f2262efee3e34fc40d6cd9ffb9315eb6b86ff Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Fri, 1 Mar 2024 12:41:11 +0700 Subject: [PATCH 19/19] Use stable version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4f96cf2..e2aaf35 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "roave/infection-static-analysis-plugin": "^1.25", "spatie/phpunit-watcher": "^1.23", "vimeo/psalm": "^4.30|^5.2", - "xepozz/internal-mocker": "dev-stubs-generator", + "xepozz/internal-mocker": "^1.4", "yiisoft/middleware-dispatcher": "^5.0", "yiisoft/test-support": "^3.0" },