You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CreateStubOverCreateMockArgRector turns a mock into a stub when the argument is stored and configured with expects() later #9966
Error: Call to undefined method TestStub_IdMapInterface_cfe43d7c::expects()
Expected Behavior
No change. The mock passed as an argument escapes into a property (or an array, or another object) and gets expectations configured later, so it has to stay a mock.
Context
Found running the composer-based PHPUnit set on Drupal core (https://www.drupal.org/i/3638148). It caused 10 unit test failures in 4 classes, with these patterns:
MigrateExecutableTest, MigrateSourceTest: $this->getMigration($this->createMock(MigrateIdMapInterface::class)) stores the argument in $this->idMap, and the test later calls $this->idMap->expects(...).
CronSuspendQueueDelayTest: 'queueManager' => $this->createMock(QueueWorkerManagerInterface::class) goes into a constructor-arguments array property, and the mock is configured from there later.
RecipeConfigStorageWrapperTest::testCreateCollection(): a second variant. The mocks are local variables, configured through a loop alias, then passed to a constructor:
Both become createStub(), because the expects() call goes through $mock, not $a/$b.
Since the rule can't see whether a mock gets expects() once it leaves the expression or goes through an alias, skipping arguments to methods of the test class itself, array items assigned to properties, and variables that appear in an array/foreach would be a safe start.
Correction on the RecipeConfigStorageWrapperTest::testCreateCollection() case: re-running with CreateStubOverCreateMockArgRector skipped, the same change comes from ExpressionCreateMockToCreateStubRector:
In the first run CreateStubOverCreateMockArgRector happened to make it first. So the loop-alias variant belongs to ExpressionCreateMockToCreateStubRector, which also misses expects() calls made through an alias like the foreach variable.
Activity
fix: skip PHPUnit CreateStubOverCreateMockArgRector in Drupal sets (#456
bbrala commentedon Nov 14, 2026
Correction on the
RecipeConfigStorageWrapperTest::testCreateCollection()case: re-running withCreateStubOverCreateMockArgRectorskipped, the same change comes fromExpressionCreateMockToCreateStubRector:In the first run
CreateStubOverCreateMockArgRectorhappened to make it first. So the loop-alias variant belongs toExpressionCreateMockToCreateStubRector, which also missesexpects()calls made through an alias like theforeachvariable.