I’m using the RequiresFunction
attribute in a few of my tests. I want to pass arguments to phpunit
that will run the tests with that attribute and the name of the required function (if possible).
Tests look something like this:
use PHPUnitFrameworkAttributesRequiresFunction;
use PHPUnitFrameworkAttributesTest;
use TestsTestCase;
class MyCustomFunctionTest extends TestCase
{
#[Test]
#[RequiresFunction('some_function_name')
public function some_function_name_destroys_the_planet(): void
{
$this->assertTrue(true);
}
}
2
Answers
If you want to run tests that require a specific function (like some_function_name), you can use PHPUnit’s
--filter
option. However, the--filter
option works with the names of the test methods or classes, not directly with attributes like RequiresFunction.This command will run all tests whose names include
some_function_name
.If you have multiple tests for different functions and you want more control, you can use the
@group
annotation in your test methods and then run PHPUnit with the--group
option.PHP:
Bash: