Skip to content

Commit c857779

Browse files
authored
Merge pull request #37 from Wolfgang-check24/fix-sse-streaming-issue
Fixes #36 SSE stream is blocking
2 parents 92e3dec + 8cc7103 commit c857779

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
55
backupGlobals="false"
6-
bootstrap="vendor/autoload.php"
6+
bootstrap="tests/bootstrap.php"
77
colors="true"
88
processIsolation="false"
99
stopOnFailure="false"

src/Transports/AbstractTransport.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,14 @@ public function start(): void
9797
return;
9898
}
9999

100-
set_time_limit(0);
101-
ini_set('output_buffering', 'off');
102-
ini_set('zlib.output_compression', false);
103-
ini_set('zlib.default_socket_timeout', 5);
100+
// Only modify these settings if not in test environment
101+
// Tests need output buffering to capture output
102+
if (!defined('PHPUNIT_RUNNING')) {
103+
set_time_limit(0);
104+
ini_set('output_buffering', 'off');
105+
ini_set('zlib.output_compression', false);
106+
ini_set('zlib.default_socket_timeout', 5);
107+
}
104108

105109
$this->connected = true;
106110
$this->initialize();
@@ -148,7 +152,12 @@ protected function sendEvent(string $event, string $data): void
148152
echo sprintf('data: %s', $data).PHP_EOL;
149153
echo PHP_EOL;
150154

151-
flush(); // Ensure the data is sent to the client
155+
// Only flush when not in test environment
156+
if (!defined('PHPUNIT_RUNNING')
157+
&& false !== ob_get_length()) {
158+
ob_flush(); // Flush PHP's output buffer first
159+
}
160+
flush(); // Then flush system/web server buffers
152161
}
153162

154163
/**

tests/bootstrap.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
// Define constant to indicate we're in a test environment
6+
define('PHPUNIT_RUNNING', true);
7+
8+
// Load the composer autoloader
9+
require dirname(__DIR__).'/vendor/autoload.php';

0 commit comments

Comments
 (0)