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

Running feature tests in a separate process in PHP 8.3 fails #49593

Closed
PHLAK opened this issue Jan 5, 2024 · 9 comments
Closed

Running feature tests in a separate process in PHP 8.3 fails #49593

PHLAK opened this issue Jan 5, 2024 · 9 comments

Comments

@PHLAK
Copy link
Contributor

PHLAK commented Jan 5, 2024

Laravel Version

10.39.0

PHP Version

8.3.1

Database Driver & Version

No response

Description

Running a feature test with the RunInSeparateProcess attribute (or @runInSeparateProcess annotation) on PHP 8.3 fails immediately.

Steps To Reproduce

Create a feature test that uses the RunInSeparateProcess attribute (or @runInSeparateProcess annotation).

namespace Tests\Feature;

use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

class ExampleTest extends TestCase
{
    #[Test, RunInSeparateProcess]
    public function it_can_run_in_a_separate_process(): void
    {
        $this->assertTrue(true);
    }
}

Run the test.

$ artisan test tests/Feature/ExampleTest.php

   FAIL  Tests\Feature\ExampleTest
  ⨯ it can run in a separate process                                                                                                     3199.78s  
  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────  
   FAILED  Tests\Feature\ExampleTest > it can run in a separate process                                                     AssertionFailedError   
  Test was run in child process and ended unexpectedly

NOTE: The above does not fail on PHP 8.2 and the following unit test does not fail on PHP 8.3.

namespace Tests\Unit;

use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class ExampleTest extends TestCase
{
    #[Test, RunInSeparateProcess]
    public function it_can_run_in_a_separate_process(): void
    {
        $this->assertTrue(true);
    }
}
@SimplyCorey
Copy link

I'm having the same issues when moving my projects over to PHP 8.3.

#49237 seems like a duplicate but I think this should be revisited as it backwards breaking.

@websitevirtuoso
Copy link

I have the same problem. Temporary I had to disable flag
processIsolation="false"
in phpunit config

@crynobone
Copy link
Member

Laravel Framework never officially supports using this flag as mentioned in the other issue and instead suggest using php artisan test --parallel option.

@websitevirtuoso
Copy link

websitevirtuoso commented Jan 6, 2024

Then why does it work with php8.2? I never used flag --parallel
it require extra package

@crynobone
Copy link
Member

Then why does it work with php8.2?

When we say "it's not officially supported" that's mean that whether it is working or not it not something that we provide or guarantee support for, and any breaking to what we don't officially support are not consider as breaking changes.

@SimplyCorey
Copy link

Is this lack of support listed anywhere? This feature has been working for years within Laravel and a recent update broke it. Some repos, including mine have thousands of tests that will need rethinking which the --parallel flag doesn't provide equity for.

@arclw
Copy link

arclw commented Jan 14, 2024

In the same boat!! Any solutions ?

@adrianodias8
Copy link

On the same boat!!
from Laravel 9 / PHP 8.1 with processIsolation="true" everything work

on Laravel 10 / PHP 8.2 fails with either #[RunInSeparateProcess] or processIsolation="true"
on Laravel 11 / PHP 8.3 fails with either #[RunInSeparateProcess] or processIsolation="true"

From what I see in my case seems related with tests that make use of Mockery::mock()

Any ideas??

I see reference of this issue here:
#49237
#49791 (was at this point that i decided to go directly to Laravel 11 hoping for some fix)

sebastianbergmann/phpunit#5677

Hey @siketyan, have you reached any conclusions on this? Can you shed some light on the matter?

@siketyan
Copy link

siketyan commented May 14, 2024

@adrianodias8 IIRC Laravel 11 already supports PHPUnit 11, and PHPUnit 11 has a detector of remained error handler settings; this issue should be resolved in Laravel 11. Did you tried PHPUnit 11 to see any error handler is detected after tests? If so, your code might set an error handler without removing it, not an issue of pure Laravel. I still don't know why this issue occurs on PHP >= 8.3 only. I am going to close the PR as the issue is considered as resolved in Laravel 11 or PHPUnit 11.

(I am no longer in any Laravel/PHP project for now so cannot check this issue still reproducible in Laravel 11, sorry)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants