我在使用控制台时遇到了 PHPUnit 的参数。
如何使用它以及使用名为 --uses 的参数做什么?
为了具体说明我的意思,文档的链接:
如果您能帮助揭示其中的要点,我将非常感谢您。
我在https://manpages.debian.org/testing/phpunit/phpunit.1.en.html
找到了它它说:
Only runs tests annotated with "@uses <name>"
所以,假设你的名字是Monkey。在这种情况下,您可以使用
注释测试/**
* @covers \BankAccount
* @uses \Money
*/
public function testMoneyCanBeDepositedInAccount(): void
{
// ...
}
@uses 注释指定将由测试执行的代码,但不打算被测试覆盖。一个很好的例子是测试代码单元所必需的值对象。
<?php declare(strict_types=1);
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(Invoice::class)]
#[UsesClass(Money::class)]
final class InvoiceTest extends TestCase
{
public function testAmountInitiallyIsEmpty(): void
{
$this->assertEquals(new Money, (new Invoice)->amount());
}
}