Skip to content

[phpunit] WithConsecutiveRector should be removed from PHPUnitSetList::PHPUNIT_90 #9366

@dczech

Description

@dczech

Processing file with this rule ends up in the not valid code (at least on PHPUnit v 9.6.23)

Sample change

1) tests/SampleTest.php:79

    ---------- begin diff ----------
@@ @@
        $eventDispatcher = $this->getMockBuilder(EventDispatcherInterface::class)
            ->disableOriginalConstructor()
            ->onlyMethods(['dispatch'])
             ->getMock()
         ;
+        /* @phpstan-ignore-next-line method.deprecated (no alternative?) */
+        $matcher = self::exactly(2);

         /* @phpstan-ignore-next-line method.deprecated (no alternative?) */
-        $eventDispatcher->expects(self::exactly(2))
-            ->method('dispatch')
-            ->withConsecutive(
-                [self::isInstanceOf(SubscribedEvent::class)],
-                [self::isInstanceOf(UnsubscribedEvent::class)]
-            )
+        $eventDispatcher->expects($matcher)
+            ->method('dispatch')->willReturnCallback(function (...$parameters) use ($matcher): void {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame(self::isInstanceOf(SubscribedEvent::class), $parameters[0]);
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame(self::isInstanceOf(UnsubscribedEvent::class), $parameters[0]);
+            }
+        })

Error: Call to undefined method PHPUnit\Framework\MockObject\Rule\InvokedCount::numberOfInvocations()

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions