FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[CodeQuality] Fix MatchAssertSameExpectedTypeRector rewriting a passing assert into a failing one by MizouziE · Pull Request #771 · rectorphp/rector-phpunit · GitHub

[CodeQuality] Fix MatchAssertSameExpectedTypeRector rewriting a passing assert into a failing one - #771

Merged
TomasVotruba merged 3 commits into
rectorphp:mainfrom
MizouziE:fix-MatchAssertSameExpectedType-refactor
Aug 20, 2026
Merged

[CodeQuality] Fix MatchAssertSameExpectedTypeRector rewriting a passing assert into a failing one#771
TomasVotruba merged 3 commits into
rectorphp:mainfrom
MizouziE:fix-MatchAssertSameExpectedType-refactor

Conversation

Copy link
Copy Markdown
Contributor

MatchAssertSameExpectedTypeRector can rewrite a passing assertSame() into a failing one.

Mechanism

The rule picks the expected literal's new type from NodeTypeResolver::getNativeType(), which returns PHPStan's scope-narrowed type at that program point. A narrowed type is sound to report on, but not to rewrite a literal against: it describes the expression where the narrowing was established, while the rewrite lands elsewhere.

Given Criteria::getType(): int|string|null:

$this->assertSame('Any', $criteria->getType());  // phpstan-phpunit narrows getType() to string

$criteria->setTypeId(100);                       // mutates the receiver
$this->assertSame(100, $criteria->getType());    // rewritten to '100' and fails

Copy link
Copy Markdown
Member

Looks good, thank you 👍

TomasVotruba marked this pull request as ready for review August 20, 2026 16:01
TomasVotruba merged commit e9265f2 into rectorphp:main Aug 20, 2026
7 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

2 participants


Back | FazBrowse Home | New Git URL