Skip to content

Inclusion of embedded nikic/php-parser is broken with PHPUnit 10 #9437

@bburnichon

Description

@bburnichon

Bug Report

Subject Details
Rector version v2.2.3

I have some services in a symfony container that requires nikic/php-parser.
When invoking this service in an end-to-end test, the dumped service container adds several lines
to include include_once $root . '/vendor/nikic/php-parser/lib/PhpParser/Parser.php';

When running tests,
I encounter PHP Fatal error: Cannot declare interface PhpParser\Parser, because the name is already in use in ##redacted##/vendor/nikic/php-parser/lib/PhpParser/Parser.php on line 5

Minimal PHP Code Causing Issue

Not related with a code change. It does not work

Suppose this test file in tests directory

final class PhpParserBreakTest extends TestCase
{
    public function testItBreaksWhenIncludingLocalPhpParserInPHPUnitTest(): void
    {
        $this->expectNotToPerformAssertions();

        include_once \dirname(__DIR__, 4).'/vendor/nikic/php-parser/lib/PhpParser/Parser.php';
        include_once \dirname(__DIR__, 4).'/vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php';
    }
}

Expected Behaviour

Test should be pass without issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions