From 7e5d55cad51f7f76c1ba6de3e76af13b78e2b577 Mon Sep 17 00:00:00 2001 From: Marcin Michalski Date: Sat, 1 Aug 2026 14:14:31 +0200 Subject: [PATCH 1/3] docs: document Rector rule in README Closes #79 Co-Authored-By: Claude Fable 5 --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index 509d4d52..69975952 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,34 @@ lendable_phpunit: pardoned: - Foo\Bar\MyTest ``` + +## Rector + +A [Rector](https://getrector.com/) rule is provided to automate adopting strict mocking across a test suite. + +`Lendable\PHPUnitExtensions\Rector\EnforceDisableReturnValueGenerationForTestDoublesRector` adds PHPUnit's `#[DisableReturnValueGenerationForTestDoubles]` attribute to test classes that do not already have it. Abstract classes are skipped, since the attribute only has an effect when placed on the concrete test class. + +Register the rule in your Rector configuration: + +```php +use Lendable\PHPUnitExtensions\Rector\EnforceDisableReturnValueGenerationForTestDoublesRector; +use Rector\Config\RectorConfig; + +return static function (RectorConfig $rector): void { + // ... + $rector->rule(EnforceDisableReturnValueGenerationForTestDoublesRector::class); +}; +``` + +Running Rector will then add the attribute where it is missing: + +```diff + namespace Tests\Foo; + + use PHPUnit\Framework\TestCase; + ++#[\PHPUnit\Framework\Attributes\DisableReturnValueGenerationForTestDoubles] + class FooTest extends TestCase + { + } +``` From e2de68dc1ff71585684eb383a2cb0527477a75c6 Mon Sep 17 00:00:00 2001 From: Marcin Michalski Date: Sat, 1 Aug 2026 14:16:47 +0200 Subject: [PATCH 2/3] docs: drop before/after diff from Rector section Co-Authored-By: Claude Fable 5 --- README.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/README.md b/README.md index 69975952..6a4042e9 100644 --- a/README.md +++ b/README.md @@ -68,16 +68,3 @@ return static function (RectorConfig $rector): void { $rector->rule(EnforceDisableReturnValueGenerationForTestDoublesRector::class); }; ``` - -Running Rector will then add the attribute where it is missing: - -```diff - namespace Tests\Foo; - - use PHPUnit\Framework\TestCase; - -+#[\PHPUnit\Framework\Attributes\DisableReturnValueGenerationForTestDoubles] - class FooTest extends TestCase - { - } -``` From 3e6907a5ca8ca0e76e4e54e6317a1d9d2d7c4b3d Mon Sep 17 00:00:00 2001 From: Marcin Michalski Date: Sat, 1 Aug 2026 14:19:49 +0200 Subject: [PATCH 3/3] docs: show fluent Rector config style for rule registration Co-Authored-By: Claude Fable 5 --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6a4042e9..205541a3 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,9 @@ Register the rule in your Rector configuration: use Lendable\PHPUnitExtensions\Rector\EnforceDisableReturnValueGenerationForTestDoublesRector; use Rector\Config\RectorConfig; -return static function (RectorConfig $rector): void { +return RectorConfig::configure() // ... - $rector->rule(EnforceDisableReturnValueGenerationForTestDoublesRector::class); -}; + ->withRules([EnforceDisableReturnValueGenerationForTestDoublesRector::class]); ``` + +With the closure-style configuration, register it via `$rectorConfig->rule(EnforceDisableReturnValueGenerationForTestDoublesRector::class)`.