diff --git a/ci/psalm.xml b/ci/psalm.xml
index a575f85d..16cf8729 100644
--- a/ci/psalm.xml
+++ b/ci/psalm.xml
@@ -45,6 +45,12 @@
+
+
+
+
+
+
diff --git a/docs/documentation/rules.md b/docs/documentation/rules.md
index ea3c8db4..88f1ed13 100644
--- a/docs/documentation/rules.md
+++ b/docs/documentation/rules.md
@@ -86,3 +86,35 @@ final class UserDomainTest extends AbstractDomainTest
```
Note that you would only need to register the `UserDomainTest` class as a PHPat test in the PHPStan config file.
+
+## Dynamic Rule Sets
+It is possible to dynamically create rules by returning an iterable of Rules from your method:
+
+```php
+namespace App\Tests\Architecture;
+
+use PHPat\Selector\Selector;
+use PHPat\Test\Builder\Rule;
+use PHPat\Test\PHPat;
+
+final class ConfigurationTest
+{
+ private const DOMAINS = [
+ 'App\Domain1',
+ 'App\Domain2',
+ ];
+
+ /**
+ * @return iterable
+ */
+ public function test_domain_independence(): iterable
+ {
+ foreach(self::DOMAINS as $domain) {
+ yield $domain => PHPat::rule()
+ ->classes(Selector::inNamespace($domain))
+ ->canOnlyDependOn()
+ ->classes(Selector::inNamespace($domain));
+ }
+ }
+}
+```
diff --git a/src/Test/RuleValidator.php b/src/Test/RuleValidator.php
index 61026b55..a2214bf0 100644
--- a/src/Test/RuleValidator.php
+++ b/src/Test/RuleValidator.php
@@ -4,11 +4,8 @@
use PHPat\Rule\Assertion\Relation\RelationAssertion;
-final class RuleValidator
+final class RuleValidator implements RuleValidatorInterface
{
- /**
- * @throws \Exception
- */
public function validate(Rule $rule): void
{
if ($rule->getSubjects() === []) {
diff --git a/src/Test/RuleValidatorInterface.php b/src/Test/RuleValidatorInterface.php
new file mode 100644
index 00000000..cf80e09e
--- /dev/null
+++ b/src/Test/RuleValidatorInterface.php
@@ -0,0 +1,11 @@
+reflectionProvider = $reflectionProvider;
}
- /**
- * @return iterable
- */
public function __invoke(): iterable
{
foreach ($this->container->getServicesByTag(self::TEST_TAG) as $test) {
@@ -38,14 +34,15 @@ public function __invoke(): iterable
}
/**
- * @param class-string $test
+ * @param class-string $test
+ * @return null|\ReflectionClass