From ada2ee79eb9aac9436523132042aadbb5f14ee93 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Mon, 29 Jan 2024 10:12:53 +0000 Subject: [PATCH] Issue #3417559 by longwave, Spokje: Remove withConsecutive() in KeyValueEntityStorageTest --- core/phpstan-baseline.neon | 5 -- .../KeyValueEntityStorageTest.php | 67 ++++++++++++------- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon index eba9f5a22ebe..04e8de9b634b 100644 --- a/core/phpstan-baseline.neon +++ b/core/phpstan-baseline.neon @@ -3360,11 +3360,6 @@ parameters: count: 1 path: tests/Drupal/Tests/Core/Entity/EntityUrlTest.php - - - message: "#^Call to deprecated method withConsecutive\\(\\) of class PHPUnit\\\\Framework\\\\MockObject\\\\Builder\\\\InvocationMocker\\.$#" - count: 6 - path: tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php - - message: "#^Call to deprecated method withConsecutive\\(\\) of class PHPUnit\\\\Framework\\\\MockObject\\\\Builder\\\\InvocationMocker\\.$#" count: 1 diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php index 208f3cddd351..613bbddb43bd 100644 --- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -158,9 +158,12 @@ public function testCreateWithPredefinedUuid() { ->willReturn(get_class($this->getMockEntity())); $this->setUpKeyValueEntityStorage(); - $this->moduleHandler->expects($this->exactly(2)) + $hooks = ['test_entity_type_create', 'entity_create']; + $this->moduleHandler->expects($this->exactly(count($hooks))) ->method('invokeAll') - ->withConsecutive(['test_entity_type_create'], ['entity_create']); + ->with($this->callback(function (string $hook) use (&$hooks): bool { + return array_shift($hooks) === $hook; + })); $this->uuidService->expects($this->never()) ->method('generate'); @@ -181,9 +184,12 @@ public function testCreateWithoutUuidKey() { ->willReturn(get_class($this->getMockEntity())); $this->setUpKeyValueEntityStorage(NULL); - $this->moduleHandler->expects($this->exactly(2)) + $hooks = ['test_entity_type_create', 'entity_create']; + $this->moduleHandler->expects($this->exactly(count($hooks))) ->method('invokeAll') - ->withConsecutive(['test_entity_type_create'], ['entity_create']); + ->with($this->callback(function (string $hook) use (&$hooks): bool { + return array_shift($hooks) === $hook; + })); $this->uuidService->expects($this->never()) ->method('generate'); @@ -206,9 +212,12 @@ public function testCreate() { ->willReturn(get_class($entity)); $this->setUpKeyValueEntityStorage(); - $this->moduleHandler->expects($this->exactly(2)) + $hooks = ['test_entity_type_create', 'entity_create']; + $this->moduleHandler->expects($this->exactly(count($hooks))) ->method('invokeAll') - ->withConsecutive(['test_entity_type_create'], ['entity_create']); + ->with($this->callback(function (string $hook) use (&$hooks): bool { + return array_shift($hooks) === $hook; + })); $this->uuidService->expects($this->once()) ->method('generate') ->willReturn('bar'); @@ -248,14 +257,13 @@ public function testSaveInsert(EntityInterface $entity) { ->method('toArray') ->willReturn($expected); - $this->moduleHandler->expects($this->exactly(4)) + $hooks = ['test_entity_type_presave', 'entity_presave', 'test_entity_type_insert', 'entity_insert']; + $this->moduleHandler->expects($this->exactly(count($hooks))) ->method('invokeAll') - ->withConsecutive( - ['test_entity_type_presave'], - ['entity_presave'], - ['test_entity_type_insert'], - ['entity_insert'], - ); + ->with($this->callback(function (string $hook) use (&$hooks): bool { + return array_shift($hooks) === $hook; + })); + $this->keyValueStore->expects($this->once()) ->method('set') ->with('foo', $expected); @@ -292,14 +300,14 @@ public function testSaveUpdate(EntityInterface $entity) { ->willReturn([['id' => 'foo']]); $this->keyValueStore->expects($this->never()) ->method('delete'); - $this->moduleHandler->expects($this->exactly(4)) + + $hooks = ['test_entity_type_presave', 'entity_presave', 'test_entity_type_update', 'entity_update']; + $this->moduleHandler->expects($this->exactly(count($hooks))) ->method('invokeAll') - ->withConsecutive( - ['test_entity_type_presave'], - ['entity_presave'], - ['test_entity_type_update'], - ['entity_update'], - ); + ->with($this->callback(function (string $hook) use (&$hooks): bool { + return array_shift($hooks) === $hook; + })); + $this->keyValueStore->expects($this->once()) ->method('set') ->with('foo', $expected); @@ -574,12 +582,21 @@ public function testDelete() { $entities['bar'] = $this->getMockEntity(EntityBaseTest::class, [['id' => 'bar']]); $this->setUpKeyValueEntityStorage(); - $this->moduleHandler->expects($this->exactly(8)) + $hooks = [ + 'test_entity_type_predelete', + 'entity_predelete', + 'test_entity_type_predelete', + 'entity_predelete', + 'test_entity_type_delete', + 'entity_delete', + 'test_entity_type_delete', + 'entity_delete', + ]; + $this->moduleHandler->expects($this->exactly(count($hooks))) ->method('invokeAll') - ->withConsecutive( - ['test_entity_type_predelete'], - ['entity_predelete'], - ); + ->with($this->callback(function (string $hook) use (&$hooks): bool { + return array_shift($hooks) === $hook; + })); $this->keyValueStore->expects($this->once()) ->method('deleteMultiple') -- GitLab