Skip to content

Test with dependencies and data provider fails #6104

@adimwiesem

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature/data-providerData Providersfeature/test-dependenciesIssues related to explicitly declared dependencies between teststype/bugSomething is brokenversion/11Something affects PHPUnit 11version/12Something affects PHPUnit 12

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions