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

Test with dependencies and data provider fails #6104

Open
adimwiesem opened this issue Jan 20, 2025 · 0 comments
Open

Test with dependencies and data provider fails #6104

adimwiesem opened this issue Jan 20, 2025 · 0 comments
Labels
feature/data-provider Data Providers feature/test-dependencies Issues related to explicitly declared dependencies between tests type/bug Something is broken

Comments

@adimwiesem
Copy link

Q A
PHPUnit version 11.5.2
PHP version 8.2.18
Installation Method Composer

Summary

This is a follow-up to #5827 which was closed for a specific case ("mixture of associative and non-associative arrays") but the originally reported issue wasn't answered.

Current behavior

Test cases having both a dependency and a data provider don't work anymore in PHPUnit 11 using the attribute syntax. The same specification worked fine in PHPUnit 10 using the annotation syntax.

How to reproduce

Here's a minimal example with two test functions. The second one depends on the first one and uses a data provider. Running the test yields this error:

1) dependencyTest::testTwo with data set "case 1" ('')
Error: Cannot use positional argument after named argument during unpacking

Code example:

<?php

class dependencyTest extends \PHPUnit\Framework\TestCase
{
    public function testOne(): void
    {
        $this->assertEmpty([]);
    }

    #[\PHPUnit\Framework\Attributes\Depends('testOne')]
    #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider')]
    public function testTwo(string $example): void
    {
        $this->assertEmpty($example);
    }

    public static function dataProvider(): array
    {
        return [
            'case 1' => [
                'example' => ''
            ]
        ];
    }
}

Expected behavior

I'd expect this to work because the data provider uses an associative array, i.e. the (single) argument IS a named one.
(Note: If I remove the dependency specification, the test runs successfully.)

@adimwiesem adimwiesem added the type/bug Something is broken label Jan 20, 2025
@sebastianbergmann sebastianbergmann added feature/data-provider Data Providers feature/test-dependencies Issues related to explicitly declared dependencies between tests labels Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/data-provider Data Providers feature/test-dependencies Issues related to explicitly declared dependencies between tests type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants