Skip to content

[13.x] testsuite#59702

Merged
taylorotwell merged 2 commits intolaravel:13.xfrom
lucasmichot:13.x-testsuite
Apr 15, 2026
Merged

[13.x] testsuite#59702
taylorotwell merged 2 commits intolaravel:13.xfrom
lucasmichot:13.x-testsuite

Conversation

@lucasmichot
Copy link
Copy Markdown
Contributor

@lucasmichot lucasmichot commented Apr 15, 2026

Description

This PR applies a set of PHPUnit-specific Rector rules to the framework's test suite (tests/) to modernise assertions, clean up mock usage, and align test structure with current PHPUnit best practices.

A dedicated $testsuiteRules group has been added to rector.php and spread into ->withRules() alongside the existing rules.

Changes

New Rector rules ($testsuiteRules)

Assertions

  • AssertFuncCallToPHPUnitAssertRector — converts bare assert*() function calls to $this->assert*() PHPUnit methods
  • SimplifyForeachInstanceOfRector — simplifies foreach + assertInstanceOf patterns

Test structure

  • ConstructClassMethodToSetUpTestCaseRector — moves constructor logic to setUp()
  • NarrowUnusedSetUpDefinedPropertyRector — removes properties defined in setUp() that are never used
  • PreferPHPUnitThisCallRector — enforces $this->... over static self::... calls where appropriate
  • RemoveEmptyTestMethodRector — removes test methods with no body
  • ReplaceTestAnnotationWithPrefixedFunctionRector — replaces @test docblock annotations with test_ prefixed method names

Mock quality

  • DirectInstanceOverMockArgRector — passes direct instances instead of mock wrappers where the mock isn't needed
  • EntityDocumentCreateMockToDirectNewRector — replaces createMock() with direct instantiation for plain value objects
  • GetMockBuilderGetMockToCreateMockRector — replaces verbose getMockBuilder()->getMock() chains with createMock()
  • InlineStubPropertyToCreateStubMethodCallRector — inlines stub properties directly into createStub() calls
  • MergeWithCallableAndWillReturnRector — merges separate with() and willReturn() calls where possible
  • NarrowIdenticalWithConsecutiveRector — tightens withConsecutive() argument matching
  • NarrowSingleWillReturnCallbackRector — simplifies single-call willReturnCallback() to willReturn()
  • RemoveExpectAnyFromMockRector — drops redundant ->expects($this->any()) calls
  • RemoveNeverUsedMockPropertyRector — removes mock properties that are never referenced
  • RemoveStandaloneCreateMockRector — removes createMock() calls whose result is never used
  • ReplaceAtMethodWithDesiredMatcherRector — replaces deprecated $this->at() matcher with the appropriate specific matcher
  • SimplerWithIsInstanceOfRector — simplifies with($this->isInstanceOf(...)) to the dedicated helper
  • SingleWithConsecutiveToWithRector — converts single-element withConsecutive() to a plain with()
  • UseSpecificWillMethodRector — replaces generic will(new ReturnStub(...)) with the dedicated willReturn*() shorthand
  • UseSpecificWithMethodRector — replaces generic with($this->equalTo(...)) with type-specific constraint methods

Notes

  • No production source code is modified; all changes are scoped to tests/.
  • The $testsuiteRules variable is intentionally kept separate from the general rules for clarity and future maintainability.
  • All other existing skip rules and PHP 8.3 target remain unchanged.

@github-actions
Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@lucasmichot lucasmichot marked this pull request as ready for review April 15, 2026 11:23
@taylorotwell taylorotwell merged commit 0c22f7b into laravel:13.x Apr 15, 2026
52 checks passed
@lucasmichot lucasmichot deleted the 13.x-testsuite branch April 16, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants