Skip to content

Test with dependencies and data provider fails #6104

Open
@adimwiesem

Description

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.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions