【发布时间】:2021-04-27 10:01:42
【问题描述】:
我刚刚将phpunit 7.5.20 升级到phpunit 9.5.0,我遇到了很多错误(实际上是好的),但不能100% 确定如何解决其中的一些错误。
只是寻找一些想法来解决以下错误:
Method setDummyStuff may not return value of type NULL, its return declaration is "void"
仅当您创建 createConfiguredMock() 并将 null 方法作为参数传递时才会发生这种情况。
这是我的测试:
<?php
use Lib\IDummyCode;
class DummyTest extends PHPUnit\Framework\TestCase
{
public function setUp(): void
{
parent::setUp();
}
public function testDummyThatReturnsVoid()
{
$this->createConfiguredMock(IDummyCode::class, [
'setDummyStuff' => null
]);
}
}
这是虚拟类:
<?php
namespace Lib;
interface IDummyCode
{
public function setDummyStuff(
int $testInt,
string $testString
): void;
}
你们对如何改进这个有一些想法吗? 非常感谢!
【问题讨论】:
标签: unit-testing methods mocking phpunit