0

I am new to Magento 2. I am testing a class with PhpUnit.

When I run the test I obtain this error:

ArgumentCountError : Too few arguments to function Magenio\Todo\Test\Unit\Service\TaskRepositoryTest::testGetList(), 0 passed in /opt/project/vendor/phpunit/phpunit/src/Framework/TestCase.php on line 1414 and exactly 1 expected

I checked the TestCase.php file and the line 1414 and related lines are those:

protected function runTest()
{
    if (\trim($this->name) === '') {
        throw new Exception(
            'PHPUnit\Framework\TestCase::$name must be a non-blank string.'
        );
    }

    $testArguments = \array_merge($this->data, $this->dependencyInput);

    $this->registerMockObjectsFromTestArguments($testArguments);

    try {
        $testResult = $this->{$this->name}(...\array_values($testArguments));
    } catch (\Throwable $exception) {
        if (!$this->checkExceptionExpectations($exception)) {
            throw $exception;
        }

I didn't understand the syntax in this line:

$testResult = $this->{$this->name}(...\array_values($testArguments));

Can anyone explain me what the previous line means, please?


I forgot to ask another thing: what does mean ...\ before array_values?

hakre
  • 193,403
  • 52
  • 435
  • 836
  • `$this->{$this->name}` means that, let's say `$this->name = 'john';`, so it will try to do `$this->john`. It is a way of dynamically accessing a property. – matiaslauriti Jun 21 '22 at 16:11
  • Compare: [What is the difference between `$this->name` and `$this->$name`?](https://stackoverflow.com/q/2205213/367456) and please see the reference Q&A: [Reference — What does this symbol mean in PHP?](https://stackoverflow.com/q/3737139/367456) – hakre Jun 21 '22 at 20:18

0 Answers0