Skip to content

Released Rector 2.5.7

Latest

Choose a tag to compare

@TomasVotruba TomasVotruba released this 13 Jul 15:26

This release sharpens the PHPUnit code-quality sets, adds a focused narrow asserts set, deprecates two blurry Symfony web-test rules, and fixes a handful of docblock false-positives in dead-code removal.

New Features 🎉

PHPUnit: PHPUNIT_NARROW_ASSERTS set

A new set focused on narrowing broad asserts to their specific, more descriptive method — e.g. assertTrue(isset($a['b']))assertArrayHasKey('b', $a). (rector-phpunit #716)

use Rector\PHPUnit\Set\PHPUnitSetList;

return RectorConfig::configure()
    ->withSets([PHPUnitSetList::PHPUNIT_NARROW_ASSERTS]);

withPreparedSets() gains phpunitNarrowAsserts + phpunitMockToStub

The 2 PHPUnit sets are now toggleable like any other prepared set. (#8178)

return RectorConfig::configure()
    ->withPreparedSets(
        phpunitNarrowAsserts: true,
        phpunitMockToStub: true,
    );

PHPUnit: flip with($this->callback(...)) on void methods to willReturnCallback()

VoidMethodWithCallbackToWillReturnCallbackRector (renamed + refocused) drops the pointless return value and types the closure as void, matching the mocked void method. (rector-phpunit #724)

 $this->createMock(SomeClass::class)
     ->method('run')
-    ->with($this->callback(function ($arg) {
-        echo $arg;
-
-        return true;
-    }));
+    ->willReturnCallback(function ($arg): void {
+        echo $arg;
+    });

Console: -v as alias for --version

Since the verbose option was removed, -v now prints the version. (#8177)

vendor/bin/rector -v
# Rector 2.x.x

Improvements 🔧

  • [StaticTypeMapper] Map phpstan-special scalar types (literal-string, numeric-string, …) to their real PHPStan types instead of a bogus ObjectType, so precise docblocks survive dead-code cleanup (#8176)
  • [PHPUnit CodeQuality] Verify assert method name exists on the Assert class via reflection before transforming (rector-phpunit #720)
  • [PHPUnit CodeQuality] Simplify single-statement void callback in CallbackSingleAssertToSimplerRector (rector-phpunit #722)
  • [PHPUnit CodeQuality] Collapse all instanceof asserts for multiple nullable instances in a single run (rector-phpunit #721)
  • [PHPUnit CodeQuality] Use atLeast() instead of exactly() in DecorateWillReturnMapWithExpectsMockRector (rector-phpunit #719)

Bug Fixes 🐛

  • [DeadCode] Preserve generic @return tags in RemoveReturnTagIncompatibleWithNativeTypeRector (#8183)
  • [DeadCode] Skip templated type in RemoveReturnTagIncompatibleWithNativeTypeRector (#8180)
  • [DeadCode] Skip PHPStan type alias in RemoveReturnTagIncompatibleWithNativeTypeRector (#8179)
  • [CodeQuality] Skip abstract class in CompleteDynamicPropertiesRector (#8182)
  • [Php71] Skip magic @method in RemoveExtraParametersRector (#8181)
  • [PHPUnit] Skip with() multiple arguments in VoidMethodWithCallbackToWillReturnCallbackRector (rector-phpunit #725)
  • [PHPUnit] Skip new object instances in NarrowIdenticalWithConsecutiveRector — each new is a fresh instance, collapsing them changes intent (rector-phpunit #726)
  • [PHPUnit] Skip mock property removal when used in a trait (rector-phpunit #723)
  • [PHPUnit] Skip nested value compare in CallbackSingleAssertToSimplerRector (rector-phpunit #718)
  • [PHPUnit] Skip union types in AssertEqualsToSameRector to preserve loose comparison (rector-phpunit #717)

Deprecations 💀

Symfony: WebTestCaseAssertIsSuccessfulRector + WebTestCaseAssertResponseCodeRector

Both rules hide the asserted behavior and force a different assert method per status code, splitting one clear assertion into several implicit ones. Asserting the HTTP status code directly is clearer and uniform. (rector-symfony #958)