phpunit: Test does not complete when using ob_start and fpassthru

Q A
PHPUnit version 10.4.x
PHP version PHP8.3.0RC4 (alpine and github actions)
Installation Method Composer

Summary

The test works:

  • with all versions of PHP8.1 until the recent PHP8.3.0RC4 in PHPUnit.
  • Outside of PHPUnit the code works as expected.
  • Test also work with PHPUnit 10.3.1 (I checked the results of the github action)

Current behaviour

The test never ends nor report any failure.

How to reproduce

public function testOutputDoesNotStripBOM(): void
{
      $raw_csv = "\xEF\xBB\xBFjohn,doe,john.doe@example.com\njane,doe,jane.doe@example.com\n";
      $stream = fopen('php://temp', 'r+');
      fwrite($stream, $raw_csv);
      ob_start();
      rewind($stream);
      echo "\xFE\xFF";
      fpassthru($stream);
      $result = ob_get_clean();
      fclose($stream);

      self::assertStringContainsString("\xFE\xFF", $result);
      self::assertStringContainsString("\xEF\xBB\xBF", $result);
      self::assertTrue(str_starts_with($result, "\xFE\xFF\xEF\xBB\xBF"));
}

Expected behavior

Works in PHP8.1+ with PHPUnit 10.4.0 the test ends and pass successfully

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Reactions: 1
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Sorry for the delay. I have just opened a PR to fix this bug: https://github.com/php/php-src/pull/12541

I have reported this bug for PHP and will now close this ticket.

using your settings I have the following

PHPUnit Started (PHPUnit 10.4.1 using PHP 8.3.0RC4 (cli) on Linux)
Test Runner Configured
Bootstrap Finished (/app/vendor/autoload.php)
Test Suite Loaded (1 test)
Test Runner Triggered Warning (No code coverage driver available)
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Runner Execution Started (1 test)
Test Suite Started (League\Csv\BugTest, 1 test)
Test Preparation Started (League\Csv\BugTest::testOutputDoesNotStripBOM)
Test Prepared (League\Csv\BugTest::testOutputDoesNotStripBOM)
Assertion Succeeded (Constraint: contains "��" [Encoding detection failed](length: 2), Value: '��john,doe,john.doe@example.com\n
jane,doe,jane.doe@example.com\n
')

So the test passes but the result is never returned

Assertion Succeeded (Constraint: is true, Value: true)
Test Passed (Issue5546Test::testOutputDoesNotStripBOM)
Test Finished (Issue5546Test::testOutputDoesNotStripBOM)
Test Suite Finished (Issue5546Test, 1 test)
Test Suite Finished (CLI Arguments, 1 test)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 0)

☝🏾 The following never happened