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

When a test appears in multiple suites, Infection errors out #1833

Open
andrewmy opened this issue Mar 6, 2023 · 4 comments
Open

When a test appears in multiple suites, Infection errors out #1833

andrewmy opened this issue Mar 6, 2023 · 4 comments
Labels

Comments

@andrewmy
Copy link

andrewmy commented Mar 6, 2023

Question Answer
Infection version 0.26.19
Test Framework version PHPUnit 10.0.14
PHP version 8.1.5 and 8.2.3
Platform Alpine, Ubuntu
Github Repo https://github.com/andrewmy/infection-multi-testsuite-issue/

A test may appear in multiple suites as a method of grouping, e.g. Unit + Functional + "Everything". When this happens, Infection errors out, and I think this was introduced in #1172

Reproducer:

Output with issue
In Assert.php line 2074:
                                          
 Expected a value identical to 1. Got: 2

No stacktrace here, but it pointed to https://github.com/infection/infection/blob/0.26.19/src/TestFramework/Coverage/JUnit/JUnitTestFileDataProvider.php#L84 when it printed it.

One could argue that this is a bad method for grouping tests but I'd say that it should work anyway. Thank you.

@andreaskienast
Copy link

I can confirm this issue. In our case we had multiple testsuites configured sharing the same directories. I think it would help to print some additional output, e.g. the used $queryString and $placeholder values.

@maks-rafalko
Copy link
Member

what do you mean by $queryString and $placeholder?

@andreaskienast
Copy link

The issue happens within src/TestFramework/Coverage/JUnit/JUnitTestFileDataProvider.php in the method getTestFileInfo(). The method iterates the results of self::testCaseMapGenerator(), leading to $queryString and $placeholder variables used to build the DOMNodeList that is checked later on.

@andreaskienast
Copy link

Perhaps it even makes more sense to move Assert::same($nodes->length, 1); into the loop, something like

foreach (self::testCaseMapGenerator($fullyQualifiedClassName) as $queryString => $placeholder) {
    $nodes = $xPath->query(sprintf($queryString, $placeholder));

    if ($nodes->length !== 0) {
        Assert::same($nodes->length, 1, sprintf(
            'Found %d occurrences while expecting 1 when querying %s in %s',
                $nodes->length,
                sprintf($queryString, $placeholder),
                $xPath->document->documentURI
            ));
        break;
    }
}

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

No branches or pull requests

4 participants