什么意思是以下PHP语法:`$ this-> {$ this-> name}`?

发布于 2025-02-09 08:08:31 字数 1171 浏览 1 评论 0原文

我是Magento 2的新手。我正在与Phpunit一起测试一堂课。

当我运行测试时,我会获得此错误:

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

我检查了testcase.php文件和行1414和相关行是:

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;
        }

我不理解此行中的语法:

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

任何人都可以向我解释我什么上一行意味着?


我忘了问另一件事:在array_values之前是什么意思... \?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文