5

The following PHPUnit code has taken from their own website and it does not work for me, even though the documentation says it is working.

<?php declare(strict_types=1);

use PHPUnit\Framework\TestCase;

final class MultipleDependenciesTest extends TestCase
{
    public function testProducerFirst(): string
    {
        $this->assertTrue(true);
        return 'first';
    }
    
    public function testProducerSecond(): string
    {
        $this->assertTrue(true);
        return 'second';
    }
    
    /**
     * @depends testProducerFirst
     * @depends testProducerSecond
     */
    public function testConsumer(string $a, string $b): void
    {
        $this->assertSame('first', $a);
        $this->assertSame('second', $b);
    }
}

I get the following error:

  1. MultipleDependencyTest::testConsumer ArgumentCountError: Too few arguments to function MultipleDependencyTest::testConsumer(), 0 passed and exactly 2 expected`
2
  • 3
    Tested right now with PHPUnit v9.5.4 and PHP 7.3.24, it works. Can you give us the PHPUnit version you installed ? Search in the composer.lock or with composer show (and if you only want to display the version: composer show phpunit/phpunit | grep versions).
    – AymDev
    Commented Apr 13, 2021 at 16:17
  • As @AymDev asked, what PHP version and PHPUnit versions are you running? Commented Apr 14, 2021 at 17:56

1 Answer 1

0

Upgrading/downgrading PHPUnit and PHP versions will do the trick. Try the setup as suggested by @AymDev in the comments.

Not the answer you're looking for? Browse other questions tagged or ask your own question.