Skip to content

Test with dependencies and data provider fails #5827

Closed
@Justinas-Jurciukonis

Description

@Justinas-Jurciukonis
Q A
PHPUnit version 11.1.3
PHP version 8.3.1
Installation Method Composer

Summary

If test case has dependency on other test and has data provider, than it will fail to pass arguments with error

1) App\Tests\MyTest::testSomething with data set "DataSet1" (true, ['a', 'b'])
Error: Cannot use positional argument after named argument during unpacking

How to reproduce

Create following test case

    public function testOtherMethod(): void
    {
        ...

        return 'PREV_TEST';
    }

    #[Depends('testOtherMethod')]
    #[DataProviderExternal(MyTestDataProvider::class, 'getSomethingData')]
    public function testSomething(bool $expected, array $data, array $previousTestData): void
    {
    }

Thrown in PHPUnit\Framework\TestCase::runTest@1173

    final protected function runTest(): mixed
    {
        $testArguments = array_merge($this->data, array_values($this->dependencyInput)); // ['expected' => true, 'data' => ['a', 'b'], 0 => 'PREV_TEST'];

        try {
            $testResult = $this->{$this->methodName}(...$testArguments);
        } catch (Throwable $exception) {

Expected behavior

Test method is called correctly

Possible solution

Do not merge arguments to one array

    final protected function runTest(): mixed
    {
        try {
            $testResult = $this->{$this->methodName}(...$this->data, ...array_values($this->dependencyInput));
        } catch (Throwable $exception) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions