0

我有一个简单的 Count 类:

class BsCount
{
    public function __construct(
        private int $count = 0
    ) {
    }

    public function increment()
    {
        return new self($this->count + 1);
    }

    public function value()
    {
        return $this->count;
    }
}

并对其进行 PHPUnit 测试:

    public function testCountsCorrectlyIfInitialIsNotPresent(): void
    {
        $this->assertEquals(
            3,
            (new BsCount())
                ->increment()
                ->increment()
                ->increment()
                ->value()
        );
    }

如果我手动将默认$count值更改为 -1 或 1,则测试失败。但是,当 Infection 将默认值突变为 -1 或 1 时,所有测试都会通过,并且突变体在报告 (U) 中被标记为未覆盖。

这是什么原因?版本为 PHP 8.02、PHPUnit 9.5.16、Infection 0.23.0。

4

0 回答 0