Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Test attribute #243

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Test/Attributes/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php declare(strict_types=1);

namespace PHPat\Test\Attributes;

#[\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
Loading