Skip to content

Commit 9b20209

Browse files
author
klapaudius
committed
Add test environment initialization and conditional output handling adjustments
- Introduced `tests/bootstrap.php` for PHPUnit-specific setup. - Updated `AbstractTransport` to check for test environment before modifying output settings. - Adjusted `phpunit.xml.dist` to use the new bootstrap file.
1 parent 33260fe commit 9b20209

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-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: 11 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,9 @@ protected function sendEvent(string $event, string $data): void
148152
echo sprintf('data: %s', $data).PHP_EOL;
149153
echo PHP_EOL;
150154

151-
if (false !== ob_get_length()) {
155+
// Only flush when not in test environment
156+
if (!defined('PHPUNIT_RUNNING')
157+
&& false !== ob_get_length()) {
152158
ob_flush(); // Flush PHP's output buffer first
153159
}
154160
flush(); // Then flush system/web server buffers

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)