Skip to content

Commit

Permalink
Add Test attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Oct 26, 2023
1 parent 80004c0 commit ad0e7e6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/Test/Attributes/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);

namespace PHPat\Test\Attributes;

use Attribute;

#[Attribute(Attribute::TARGET_METHOD)]
final class Test
{
}
5 changes: 4 additions & 1 deletion src/Test/TestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPat\Test;

use PHPat\Test\Attributes\Test;
use PHPat\Test\Builder\Rule as RuleBuilder;

class TestParser
Expand Down Expand Up @@ -41,7 +42,9 @@ private function parse(): array
$methods = [];
$reflected = $test->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();
}
Expand Down
7 changes: 5 additions & 2 deletions tests/architecture/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down

0 comments on commit ad0e7e6

Please sign in to comment.