我刚刚升级到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
]);
}
}
Run Code Online (Sandbox Code Playgroud)
这是虚拟类:
<?php
namespace Lib;
interface IDummyCode
{
public function setDummyStuff(
int $testInt,
string $testString
): void;
}
Run Code Online (Sandbox Code Playgroud)
你们有关于如何改进这一点的想法吗?多谢!