Skip to content

[Config] Add phpunitNarrowAsserts and phpunitMockToStub to withPreparedSets()#8178

Merged
TomasVotruba merged 2 commits into
mainfrom
phpunit-narrow-asserts-mock-to-stub-prepared-sets
Jul 12, 2026
Merged

[Config] Add phpunitNarrowAsserts and phpunitMockToStub to withPreparedSets()#8178
TomasVotruba merged 2 commits into
mainfrom
phpunit-narrow-asserts-mock-to-stub-prepared-sets

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Wires two existing rector-phpunit sets into withPreparedSets() so they can be toggled like the other prepared sets.

  • PHPUnitSetList::PHPUNIT_NARROW_ASSERTSphpunitNarrowAsserts: true
  • PHPUnitSetList::PHPUNIT_MOCK_TO_STUBphpunitMockToStub: true

Usage

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

phpunitNarrowAsserts narrows generic asserts to specific methods, e.g.:

-$this->assertEquals(10, $value);
+$this->assertSame(10, $value);

phpunitMockToStub swaps mocks with no expectations for stubs:

-$mock = $this->createMock(SomeType::class);
+$stub = $this->createStub(SomeType::class);

@TomasVotruba TomasVotruba merged commit 0e269a0 into main Jul 12, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the phpunit-narrow-asserts-mock-to-stub-prepared-sets branch July 12, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant