【问题标题】:PHP unit 9: Test Dependencies does not work for mePHP 单元 9:测试依赖项对我不起作用
【发布时间】:2021-03-16 08:01:42
【问题描述】:

以下 PHPUnit 代码取自他们自己的网站,它对我不起作用,即使文档说它可以工作。

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

我收到以下错误:

  1. MultipleDependencyTest::testConsumer ArgumentCountError:函数 MultipleDependencyTest::testConsumer() 的参数太少,通过了 0 个,预期正好 2 个`

【问题讨论】:

  • 现在用 PHPUnit v9.5.4PHP 7.3.24 测试,它可以工作。你能给我们你安装的 PHPUnit 版本吗?在 composer.lockcomposer show 中搜索(如果您只想显示版本:composer show phpunit/phpunit | grep versions)。
  • 正如@AymDev 所问,你运行的是什么 PHP 版本和 PHPUnit 版本?

标签: php phpunit


【解决方案1】:

升级/降级 PHPUnit 和 PHP 版本可以解决问题。按照@AymDev 在 cmets 中的建议尝试设置。

【讨论】:

    猜你喜欢
    • 2020-06-15
    • 1970-01-01
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多