From 66a4c78b453be62c644f7a438dd4c5190b027c59 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Thu, 1 Feb 2024 04:20:34 +0000 Subject: [PATCH] Issue #3418178 by longwave: Remove withConsecutive() in CronQueueTest --- .../tests/src/Kernel/System/CronQueueTest.php | 68 +++++++++---------- core/phpstan-baseline.neon | 5 -- 2 files changed, 31 insertions(+), 42 deletions(-) diff --git a/core/modules/system/tests/src/Kernel/System/CronQueueTest.php b/core/modules/system/tests/src/Kernel/System/CronQueueTest.php index abedf8b4b57a..e450e3a3837e 100644 --- a/core/modules/system/tests/src/Kernel/System/CronQueueTest.php +++ b/core/modules/system/tests/src/Kernel/System/CronQueueTest.php @@ -57,7 +57,7 @@ class CronQueueTest extends KernelTestBase { /** * A logger for testing. * - * @var \PHPUnit\Framework\MockObject\MockObject|\Psr\Log\LoggerInterface + * @var \Prophecy\Prophecy\ObjectProphecy|\Psr\Log\LoggerInterface */ protected $logger; @@ -66,7 +66,7 @@ class CronQueueTest extends KernelTestBase { */ protected function setUp(): void { // Setup logger before register() is called. - $this->logger = $this->createMock(LoggerInterface::class); + $this->logger = $this->prophesize(LoggerInterface::class); parent::setUp(); $this->connection = Database::getConnection(); @@ -173,23 +173,20 @@ public function testLeaseTime() { * @see \Drupal\cron_queue_test\Plugin\QueueWorker\CronQueueTestException */ public function testUncaughtExceptions() { - $this->logger->expects($this->atLeast(2)) - ->method('log') - ->withConsecutive( - [ - $this->equalTo(RfcLogLevel::ERROR), - $this->equalTo('%type: @message in %function (line %line of %file).'), - $this->callback(function ($args) { - return $args['@message'] === 'That is not supposed to happen.' && - $args['exception'] instanceof \Exception; - }), - ], - [ - $this->equalTo(RfcLogLevel::INFO), - $this->equalTo('Cron run completed.'), - $this->anything(), - ], - ); + $this->logger->log( + RfcLogLevel::ERROR, + '%type: @message in %function (line %line of %file).', + Argument::that(function ($args) { + return $args['@message'] === 'That is not supposed to happen.' + && $args['exception'] instanceof \Exception; + }) + )->shouldBeCalled(); + + $this->logger->log( + RfcLogLevel::INFO, + 'Cron run completed.', + Argument::cetera() + )->shouldBeCalled(); // Get the queue to test the normal Exception. $queue = $this->container->get('queue')->get(CronQueueTestException::PLUGIN_ID); @@ -226,22 +223,19 @@ public function testUncaughtExceptions() { * @covers \Drupal\Core\Queue\SuspendQueueException */ public function testSuspendQueueException(): void { - $this->logger->expects($this->atLeast(2)) - ->method('log') - ->withConsecutive( - [ - $this->equalTo(RfcLogLevel::DEBUG), - $this->equalTo('A worker for @queue queue suspended further processing of the queue.'), - $this->callback(function ($args) { - return $args['@queue'] === CronQueueTestSuspendQueue::PLUGIN_ID; - }), - ], - [ - $this->equalTo(RfcLogLevel::INFO), - $this->equalTo('Cron run completed.'), - $this->anything(), - ], - ); + $this->logger->log( + RfcLogLevel::DEBUG, + 'A worker for @queue queue suspended further processing of the queue.', + Argument::that(function ($args) { + return $args['@queue'] === CronQueueTestSuspendQueue::PLUGIN_ID; + }) + )->shouldBeCalled(); + + $this->logger->log( + RfcLogLevel::INFO, + 'Cron run completed.', + Argument::cetera() + )->shouldBeCalled(); // Get the queue to test the specific SuspendQueueException. $queue = \Drupal::queue(CronQueueTestSuspendQueue::PLUGIN_ID); @@ -348,9 +342,9 @@ public function testQueueWorkerDeriver(): void { */ public function register(ContainerBuilder $container) { parent::register($container); - $container->register('test_logger', get_class($this->logger)) + $container->register('test_logger', get_class($this->logger->reveal())) ->addTag('logger'); - $container->set('test_logger', $this->logger); + $container->set('test_logger', $this->logger->reveal()); } } diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon index e3790ef21ab8..5fcb52890e51 100644 --- a/core/phpstan-baseline.neon +++ b/core/phpstan-baseline.neon @@ -2298,11 +2298,6 @@ parameters: count: 2 path: modules/system/tests/src/Functional/Theme/ThemeUiTest.php - - - message: "#^Call to deprecated method withConsecutive\\(\\) of class PHPUnit\\\\Framework\\\\MockObject\\\\Builder\\\\InvocationMocker\\.$#" - count: 2 - path: modules/system/tests/src/Kernel/System/CronQueueTest.php - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" count: 1 -- GitLab