From e392072d124f2516a0c15b0512e531c313e1a590 Mon Sep 17 00:00:00 2001 From: Caleb White Date: Thu, 26 Oct 2023 06:33:16 -0500 Subject: [PATCH] Add Test attribute --- src/Test/Attributes/Test.php | 6 ++++++ src/Test/TestParser.php | 5 ++++- tests/architecture/ConfigurationTest.php | 7 +++++-- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 src/Test/Attributes/Test.php diff --git a/src/Test/Attributes/Test.php b/src/Test/Attributes/Test.php new file mode 100644 index 00000000..ff1819da --- /dev/null +++ b/src/Test/Attributes/Test.php @@ -0,0 +1,6 @@ +getNativeReflection(); foreach ($reflected->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { - if (preg_match('/^(test)[A-Za-z0-9_\x80-\xff]*/', $method->getName()) + if ( + !empty($method->getAttributes(Test::class)) + || preg_match('/^(test)[A-Za-z0-9_\x80-\xff]*/', $method->getName()) ) { $methods[] = $method->getName(); } diff --git a/tests/architecture/ConfigurationTest.php b/tests/architecture/ConfigurationTest.php index fd5e44c6..ddb844c8 100644 --- a/tests/architecture/ConfigurationTest.php +++ b/tests/architecture/ConfigurationTest.php @@ -4,12 +4,14 @@ use PHPat\Configuration; use PHPat\Selector\Selector; +use PHPat\Test\Attributes\Test; use PHPat\Test\Builder\Rule; use PHPat\Test\PHPat; final class ConfigurationTest { - public function test_configuration_does_not_have_dependencies(): Rule + #[Test] + public function configuration_does_not_have_dependencies(): Rule { return PHPat::rule() ->classes(Selector::classname(Configuration::class)) @@ -18,7 +20,8 @@ public function test_configuration_does_not_have_dependencies(): Rule ; } - public function test_configuration_is_final(): Rule + #[Test] + public function configuration_is_final(): Rule { return PHPat::rule() ->classes(Selector::classname(Configuration::class))