Repository navigation
[PHPUnit120] Skip mocks configured through an alias in ExpressionCreateMockToCreateStubRector - #823
Merged
Conversation
Member
|
Well done, thank you 👍 |
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes rectorphp/rector#9967.
ExpressionCreateMockToCreateStubRectorturned mocks into stubs when their expectations are configured through another variable, e.g.After the change the test fails with
Call to undefined method TestStub_...::expects().Cause
MockObjectExprDetector::isUsedForMocking()only treats a variable as a mock when a method is called on it directly, or when it is passed to aMockObject-typed parameter. Anexpects()call on an alias is not connected back to the original variable.Change
New
MockObjectExprDetector::isEscapingToAlias(), used byExpressionCreateMockToCreateStubRectoronly. It treats the variable as possibly mocked when it is:foreachexpression,$alias = $a,$x[] = $a,$mocks = [$a],$this->mocks = [$a],=&),use (&$a)).An array literal passed directly as a call or
newargument is not treated as an alias, which keeps the behaviour consistent withCreateStubOverCreateMockArgRector(itshandle_assigned_variable*fixtures convert that case). I kept the check out ofisUsedForMocking()for the same reason: changing it there would break those fixtures.Tests
New fixtures that fail without the change:
skip_foreach_alias,skip_array_assigned_to_variable,skip_assigned_alias,skip_closure_by_reference.put_in_array_argumentdocuments that an array passed as an argument is still converted.Full suite passes (699 tests), plus ECS, class-leak and Rector.
Context
Found running the composer-based PHPUnit set on Drupal core (https://www.drupal.org/i/3638148), in
RecipeConfigStorageWrapperTest::testCreateCollection(). With this branch that file is no longer changed.CreateStubOverCreateMockArgRectorhas related escape cases (rectorphp/rector#9966); this PR doesn't change that rule.