我在一些测试中使用了
RequiresFunction
属性。我想将参数传递给 phpunit
,它将使用该属性和所需函数的名称(如果可能)运行测试。
测试看起来像这样:
use PHPUnit\Framework\Attributes\RequiresFunction;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class MyCustomFunctionTest extends TestCase
{
#[Test]
#[RequiresFunction('some_function_name')
public function some_function_name_destroys_the_planet(): void
{
$this->assertTrue(true);
}
}
如果您想运行需要特定函数(如 some_function_name)的测试,您可以使用 PHPUnit 的
--filter
选项。但是, --filter
选项适用于测试方法或类的名称,而不是直接适用于 RequiresFunction 等属性。
此命令将运行名称包含
some_function_name
的所有测试。
phpunit --filter '/some_function_name/'