From d665aecf8c8c0bbe5445a812d1a815026ed47253 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Fri, 26 Jul 2024 00:32:06 +0530 Subject: [PATCH] Fixing remaining phpstan warnings. --- phpstan.neon | 2 ++ .../Entity/Fields/Image/ImageDerivative.php | 6 ++++- tests/src/Kernel/AlterableSchemaTest.php | 2 +- .../DataProducer/EntityReferenceTest.php | 25 +------------------ tests/src/Traits/MockingTrait.php | 10 ++++---- 5 files changed, 14 insertions(+), 31 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 68a4e9b28..34c02b706 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,6 +9,8 @@ parameters: - identifier: missingType.iterableValue # new static() is a best practice in Drupal, so we cannot fix that. - "#^Unsafe usage of new static\\(\\)\\.$#" + # Soft deprecated by phpunit10 and removed in phpunit 12. + - "#^Call to deprecated method getMockForAbstractClass\\(\\)\\.$#" # We forgot to use return type hints on some interfaces, cannot be changed # in stable 4.0. # @todo use return type hints everywhere for 5.0. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php b/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php index 43ae72580..9d616edad 100644 --- a/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php +++ b/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php @@ -98,9 +98,13 @@ public function resolve(FileInterface $entity = NULL, $style, RefinableCacheable $metadata->addCacheableDependency($access); if ($access->isAllowed() && $image_style = ImageStyle::load($style)) { + // @phpstan-ignore-next-line $width = $entity->width; + // @phpstan-ignore-next-line $height = $entity->height; - if (!isset($width) || !isset($height)) { + + // @phpstan-ignore-next-line + if (empty($width) || empty($height)) { /** @var \Drupal\Core\Image\ImageInterface $image */ $image = \Drupal::service('image.factory')->get($entity->getFileUri()); if ($image->isValid()) { diff --git a/tests/src/Kernel/AlterableSchemaTest.php b/tests/src/Kernel/AlterableSchemaTest.php index 9a005e22a..19f6a4f82 100644 --- a/tests/src/Kernel/AlterableSchemaTest.php +++ b/tests/src/Kernel/AlterableSchemaTest.php @@ -184,7 +184,7 @@ protected function mockSchema($id, $schema, array $extensions = []): void { $this->container->get('event_dispatcher'), ]) ->onlyMethods(['getSchemaDefinition', 'getResolverRegistry']) - ->getMockForAbstractClass(); + ->getMock(); $this->schema->expects(static::any()) ->method('getSchemaDefinition') diff --git a/tests/src/Kernel/DataProducer/EntityReferenceTest.php b/tests/src/Kernel/DataProducer/EntityReferenceTest.php index bfe0c78b4..3b7700eff 100644 --- a/tests/src/Kernel/DataProducer/EntityReferenceTest.php +++ b/tests/src/Kernel/DataProducer/EntityReferenceTest.php @@ -6,31 +6,8 @@ use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\Tests\graphql\Kernel\GraphQLTestBase; +use Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait; -// @todo Drupal 10.1 compatibility: use the deprecated trait for Drupal 10.1. -if (strpos(\Drupal::VERSION, '10.1') === 0) { - - /** - * Helper trait for compatibility with Drupal 9. - * - * @phpcs:disable Drupal.Classes.ClassFileName.NoMatch - */ - trait EntityReferenceFieldCreationTrait { - // @phpstan-ignore-next-line - use \Drupal\Tests\field\Traits\EntityReferenceTestTrait; - - } -} -else { - - /** - * Helper trait for compatibility with Drupal 10. - */ - trait EntityReferenceFieldCreationTrait { - use \Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait; - - } -} /** * Tests the entity_reference data producers. diff --git a/tests/src/Traits/MockingTrait.php b/tests/src/Traits/MockingTrait.php index 4b8dd2b83..9eb74d4b5 100644 --- a/tests/src/Traits/MockingTrait.php +++ b/tests/src/Traits/MockingTrait.php @@ -53,7 +53,7 @@ trait MockingTrait { * The return callback promise. */ protected function toPromise($value) { - return $this->returnCallback(is_callable($value) ? $value : function () use ($value) { + return $this->willReturnCallback(is_callable($value) ? $value : function () use ($value) { yield $value; }); } @@ -89,7 +89,7 @@ protected function setUpSchema($schema, $id = 'test', array $values = []): void $this->schemaPluginManager->method('createInstance') ->with($this->equalTo($id)) - ->will($this->returnValue($this->schema)); + ->willReturn($this->schema); $this->container->set('plugin.manager.graphql.schema', $this->schemaPluginManager); } @@ -145,7 +145,7 @@ protected function mockSchema($id, $schema, array $extensions = []): void { ['development' => FALSE], ]) ->onlyMethods(['getSchemaDefinition', 'getResolverRegistry']) - ->getMockForAbstractClass(); + ->getMock(); $this->schema->expects(static::any()) ->method('getSchemaDefinition') @@ -169,14 +169,14 @@ protected function mockSchemaPluginManager($id): void { $this->schemaPluginManager->expects($this->any()) ->method('getDefinitions') - ->will($this->returnValue([ + ->willReturn([ $id => [ 'id' => $id, 'name' => 'Test schema', 'provider' => 'graphql', 'class' => '\Drupal\graphql\Plugin\GraphQL\Schema\SdlSchemaPluginBase', ], - ])); + ]); } /**