Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing sent headers when 'RunInSeparateProcess' is used #6105

Open
yurii-stickee-2023 opened this issue Jan 21, 2025 · 0 comments
Open

missing sent headers when 'RunInSeparateProcess' is used #6105

yurii-stickee-2023 opened this issue Jan 21, 2025 · 0 comments
Labels
feature/process-isolation Issues related to running tests in separate PHP processes type/bug Something is broken

Comments

@yurii-stickee-2023
Copy link

yurii-stickee-2023 commented Jan 21, 2025

Q A
PHPUnit version 11.5.3
PHP version 8.3.16
Installation Method Composer / PHAR

Summary

Good day, @sebastianbergmann

Thank you for fixing this issue #6103
You have said there that it was executing for you once and it was just the print issue.
The output was fixed there and that's great, but the problem with headers still exists for me.

I have very small understanding of PHPUnit internals, so I will try my best to explain the problem.

I am using Xdebug for testing headers (specifically xdebug_get_headers() ), and for some reason they are not properly sent (or not reported by xDebug) with RunInSeparateProcess while using PHPUnit 11.x (PHPUnit 10.x is working fine! Very strange situation, considering that it printed output twice as 11.x did)

Originally I thought that it somehow run test twice with headers and without, but after your output fix I am curious what is happening here now.

Current behavior

xdebug_get_headers() return empty, while sent headers are expected to be there.

My PHP setup is next

php -v
PHP 8.3.16 (cli) (built: Jan 19 2025 13:29:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.16, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.16, Copyright (c), by Zend Technologies
    with Xdebug v3.4.0, Copyright (c) 2002-2024, by Derick Rethans

How to reproduce

  1. Install xDebug and test that it works. Make some file like 1.php
<?php
header( "X-Test", "Testing" );
setcookie( "TestCookie", "test-value" );
var_dump( xdebug_get_headers() );

and run it as php 1.php. It should output

$ php 1.php 
/var/www/test-phpunit/1.php:4:
array(2) {
  [0] =>
  string(6) "X-Test"
  [1] =>
  string(33) "Set-Cookie: TestCookie=test-value"
}

I took example from https://xdebug.org/docs/all_functions#xdebug_get_headers

  1. create composer project with "minimum-stability": "dev"
  2. create test case tests/TestAnnotation4.php
<?php

#[\PHPUnit\Framework\Attributes\CoversNothing]
class TestAnnotation4 extends \PHPUnit\Framework\TestCase
{
    public static int $calls = 0;

    public function test_1()
    {
        $this->assertTrue(true);
    }

    #[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
    public function test_case_2_check()
    {
        var_dump(++self::$calls);

        ob_start();
        header("X-Test", "Testing");
        echo 'asd';
        $content = ob_get_clean();

        $this->assertSame('asd', $content);
        $this->assertSame(['X-Test'], xdebug_get_headers());
    }
}
  1. require PHPUnit as composer require phpunit/phpunit:11.5.3 -W
  2. run test case as ./vendor/bin/phpunit tests/TestAnnotation4.php
  3. See output with failed test
 ./vendor/bin/phpunit tests/TestAnnotation4.php
PHPUnit 11.5.3 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.16

.int(1)
F                                                                  2 / 2 (100%)int(1)


Time: 00:00.059, Memory: 8.00 MB

There was 1 failure:

1) TestAnnotation4::test_case_2_check
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
-Array &0 [
-    0 => 'X-Test',
-]
+Array &0 []

/var/www/test-phpunit/tests/TestAnnotation4.php:26

FAILURES!
Tests: 2, Assertions: 3, Failures: 1, PHPUnit Deprecations: 2.

NOTE! If you run it with the fix from #6103 you will see that output is fixed (it outputs int(1) once), but the issue with headers is still there.

composer require phpunit/phpunit:11.5.x-dev -W

 ./vendor/bin/phpunit tests/TestAnnotation4.php

PHPUnit 11.5.3 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.16

.int(1)
F                                                                  2 / 2 (100%)

Time: 00:00.059, Memory: 8.00 MB

There was 1 failure:

1) TestAnnotation4::test_case_2_check
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
-Array &0 [
-    0 => 'X-Test',
-]
+Array &0 []

/var/www/test-phpunit/tests/TestAnnotation4.php:26

FAILURES!
Tests: 2, Assertions: 3, Failures: 1, PHPUnit Deprecations: 2.

Expected behavior

The expected behavior is that xdebug_get_headers() returns sent headers and not empty array.
For example, in PHPUnit 10.x it works as expected and returns sent headers

composer require phpunit/phpunit:10.5 -W

./vendor/bin/phpunit tests/TestAnnotation4.php

PHPUnit 10.5.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.16

./var/www/test-phpunit/tests/TestAnnotation4.php:18:
int(1)
.                                                                  2 / 2 (100%)/var/www/test-phpunit/tests/TestAnnotation4.php:18:
int(1)


Time: 00:00.059, Memory: 8.00 MB

OK (2 tests, 3 assertions)

that is what I expected before. It works correctly in PHPUnit 9.x with annotations too.

Best regards

@yurii-stickee-2023 yurii-stickee-2023 added the type/bug Something is broken label Jan 21, 2025
@sebastianbergmann sebastianbergmann added the feature/process-isolation Issues related to running tests in separate PHP processes label Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/process-isolation Issues related to running tests in separate PHP processes type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants