From ae750411d1d3d14771de25dda3b955cf708e0de9 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Mon, 29 Jan 2024 10:46:02 +0000 Subject: [PATCH] Issue #3417557 by longwave: Remove withConsecutive() in CronSuspendQueueDelayTest --- core/phpstan-baseline.neon | 5 -- .../Core/Cron/CronSuspendQueueDelayTest.php | 63 ++++++++++--------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon index 7c6cda9769ca..dd4da94b3789 100644 --- a/core/phpstan-baseline.neon +++ b/core/phpstan-baseline.neon @@ -3296,11 +3296,6 @@ parameters: count: 1 path: tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php - - - message: "#^Call to deprecated method withConsecutive\\(\\) of class PHPUnit\\\\Framework\\\\MockObject\\\\Builder\\\\InvocationMocker\\.$#" - count: 3 - path: tests/Drupal/Tests/Core/Cron/CronSuspendQueueDelayTest.php - - message: """ #^Call to deprecated method expectError\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\: diff --git a/core/tests/Drupal/Tests/Core/Cron/CronSuspendQueueDelayTest.php b/core/tests/Drupal/Tests/Core/Cron/CronSuspendQueueDelayTest.php index dc8af98f93a2..2738682e9954 100644 --- a/core/tests/Drupal/Tests/Core/Cron/CronSuspendQueueDelayTest.php +++ b/core/tests/Drupal/Tests/Core/Cron/CronSuspendQueueDelayTest.php @@ -135,12 +135,12 @@ public function testSuspendQueue(): void { ->setConstructorArgs($this->cronConstructorArguments) ->getMock(); - $cron->expects($this->exactly(2)) + $delays = [2000000, 3000000]; + $cron->expects($this->exactly(count($delays))) ->method('usleep') - ->withConsecutive( - [$this->equalTo(2000000)], - [$this->equalTo(3000000)], - ); + ->with($this->callback(function (int $delay) use (&$delays): bool { + return array_shift($delays) === $delay; + })); $queueManager->expects($this->once()) ->method('getDefinitions') @@ -391,19 +391,22 @@ public function testSuspendQueueOrder(): void { ['test_worker_d', [], $this->workerA], ]); - $this->workerA->expects($this->exactly(6)) + $queues = [ + // All queues are executed in sequence of definition: + 'test_data_from_queue_a', + 'test_data_from_queue_b', + 'test_data_from_queue_c', + 'test_data_from_queue_d', + // Queue C is executed again, and before queue B. + 'test_data_from_queue_c', + // Queue B is executed again, after queue C since its delay was longer. + 'test_data_from_queue_b', + ]; + $this->workerA->expects($this->exactly(count($queues))) ->method('processItem') - ->withConsecutive( - // All queues are executed in sequence of definition: - [$this->equalTo('test_data_from_queue_a')], - [$this->equalTo('test_data_from_queue_b')], - [$this->equalTo('test_data_from_queue_c')], - [$this->equalTo('test_data_from_queue_d')], - // Queue C is executed again, and before queue B. - [$this->equalTo('test_data_from_queue_c')], - // Queue B is executed again, after queue C since its delay was longer. - [$this->equalTo('test_data_from_queue_b')], - ) + ->with($this->callback(function ($queue) use (&$queues): bool { + return array_shift($queues) === $queue; + })) ->willReturnOnConsecutiveCalls( NULL, $this->throwException(new SuspendQueueException('', 0, NULL, 16.0)), @@ -425,21 +428,19 @@ public function testSuspendQueueOrder(): void { return (float) $currentTime; }); - $cron->expects($this->exactly(2)) + $delays = [ + // Expect to wait for 8 seconds, then accelerate time by 4 seconds. + 4, 8000000, + // SuspendQueueException requests to delay by 16 seconds, but 4 seconds + // have passed above, so there are just 12 seconds remaining: + 0, 12000000, + ]; + $cron->expects($this->exactly(count($delays) / 2)) ->method('usleep') - ->withConsecutive( - // Expect to wait for 8 seconds. - [ - $this->callback(function (int $microseconds) use (&$currentTime) { - // Accelerate time by 4 seconds. - $currentTime += 4; - return $microseconds === 8000000; - }), - ], - // SuspendQueueException requests to delay by 16 seconds, but 4 seconds - // have passed above, so there are just 12 seconds remaining: - [$this->equalTo(12000000)], - ); + ->with($this->callback(function (int $delay) use (&$currentTime, &$delays): bool { + $currentTime += array_shift($delays); + return array_shift($delays) === $delay; + })); $cron->run(); } -- GitLab