Skip to content

Commit b14c12f

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 b14c12f

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ protected function sendEvent(string $event, string $data): void
148148
echo sprintf('data: %s', $data).PHP_EOL;
149149
echo PHP_EOL;
150150

151-
if (false !== ob_get_length()) {
151+
// Only flush when not in test environment
152+
if (!defined('PHPUNIT_RUNNING')
153+
&& false !== ob_get_length()) {
152154
ob_flush(); // Flush PHP's output buffer first
153155
}
154156
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)