From 20083922a479d0cd4c1df365d62046d054b43c4d Mon Sep 17 00:00:00 2001 From: Lee Rowlands <lee.rowlands@previousnext.com.au> Date: Fri, 3 Jan 2025 12:34:58 +1000 Subject: [PATCH] Issue #3496087 by mondrake, smustgrave: Fix PHPStan missingType.generics for ObjectProphecy not specifying its type --- core/.phpstan-baseline.php | 84 ------------------- .../tests/src/Unit/MigrateExecutableTest.php | 5 +- .../src/Kernel/ComposerInspectorTest.php | 2 +- .../tests/src/Traits/JsonSchemaTestTrait.php | 2 + .../TimestampItemNormalizerTest.php | 5 +- .../tests/src/Unit/Plugin/query/SqlTest.php | 5 +- .../Context/IsFrontPathCacheContextTest.php | 5 +- .../Tests/Core/Entity/EntityFormTest.php | 5 +- .../Routing/DefaultHtmlRouteProviderTest.php | 4 +- 9 files changed, 20 insertions(+), 97 deletions(-) diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index aa2be3f4acca..0d897d182157 100644 --- a/core/.phpstan-baseline.php +++ b/core/.phpstan-baseline.php @@ -22465,12 +22465,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiTopLevelResourceNormalizerTest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\jsonapi\\\\Kernel\\\\Normalizer\\\\JsonApiTopLevelResourceNormalizerTest\\:\\:doProphesize\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiTopLevelResourceNormalizerTest.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\jsonapi\\\\Kernel\\\\Normalizer\\\\LinkCollectionNormalizerTest\\:\\:getNormalizer\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', @@ -28255,12 +28249,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/migrate/tests/src/Unit/Exception/RequirementsExceptionTest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\migrate\\\\Unit\\\\MigrateExecutableTest\\:\\:getTestRollbackIdMap\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/modules/migrate/tests/src/Unit/MigrateExecutableTest.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\migrate\\\\Unit\\\\MigrateLookupTest\\:\\:providerExceptionOnMigrationNotFound\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', @@ -31243,12 +31231,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/options/tests/src/Kernel/Views/OptionsTestBase.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\package_manager\\\\Kernel\\\\ComposerInspectorTest\\:\\:mockComposerRunner\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/modules/package_manager/tests/src/Kernel/ComposerInspectorTest.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\page_cache\\\\Hook\\\\PageCacheHooks\\:\\:help\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', @@ -33637,72 +33619,30 @@ 'count' => 1, 'path' => __DIR__ . '/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\serialization\\\\Unit\\\\Normalizer\\\\DateTimeIso8601NormalizerTest\\:\\:doProphesize\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\serialization\\\\Unit\\\\Normalizer\\\\DateTimeIso8601NormalizerTestDrupalDateTime\\:\\:setTimezone\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, 'path' => __DIR__ . '/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\serialization\\\\Unit\\\\Normalizer\\\\DateTimeNormalizerTest\\:\\:doProphesize\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\serialization\\\\Unit\\\\Normalizer\\\\DateTimeNormalizerTestDrupalDateTime\\:\\:setTimezone\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, 'path' => __DIR__ . '/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\serialization\\\\Unit\\\\Normalizer\\\\MarkupNormalizerTest\\:\\:doProphesize\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/modules/serialization/tests/src/Unit/Normalizer/MarkupNormalizerTest.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\serialization\\\\Unit\\\\Normalizer\\\\TestNormalizerBase\\:\\:normalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#', 'identifier' => 'missingType.generics', 'count' => 1, 'path' => __DIR__ . '/modules/serialization/tests/src/Unit/Normalizer/NormalizerBaseTest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\serialization\\\\Unit\\\\Normalizer\\\\NullNormalizerTest\\:\\:doProphesize\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/modules/serialization/tests/src/Unit/Normalizer/NullNormalizerTest.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\serialization\\\\Unit\\\\Normalizer\\\\PrimitiveDataNormalizerTest\\:\\:dataProviderPrimitiveData\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, 'path' => __DIR__ . '/modules/serialization/tests/src/Unit/Normalizer/PrimitiveDataNormalizerTest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\serialization\\\\Unit\\\\Normalizer\\\\PrimitiveDataNormalizerTest\\:\\:doProphesize\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/modules/serialization/tests/src/Unit/Normalizer/PrimitiveDataNormalizerTest.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\serialization\\\\Unit\\\\Normalizer\\\\TimestampItemNormalizerTest\\:\\:createTimestampItemProphecy\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\serialization\\\\Unit\\\\Normalizer\\\\TimestampNormalizerTest\\:\\:doProphesize\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/modules/serialization/tests/src/Unit/Normalizer/TimestampNormalizerTest.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\serialization\\\\Unit\\\\Normalizer\\\\TimestampNormalizerTestDrupalDateTime\\:\\:setTimezone\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', @@ -52131,12 +52071,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/views/tests/src/Unit/Plugin/pager/PagerPluginBaseTest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\views\\\\Unit\\\\Plugin\\\\query\\\\SqlTest\\:\\:setupEntityTypes\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/modules/views/tests/src/Unit/Plugin/query/SqlTest.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\views\\\\Unit\\\\Plugin\\\\views\\\\query\\\\MysqlDateSqlTest\\:\\:providerTestGetDateFormat\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', @@ -59338,12 +59272,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/Drupal/Tests/Core/Cache/Context/HeadersCacheContextTest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\Core\\\\Cache\\\\Context\\\\IsFrontPathCacheContextTest\\:\\:createPathMatcher\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/tests/Drupal/Tests/Core/Cache/Context/IsFrontPathCacheContextTest.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\Core\\\\Cache\\\\Context\\\\PathParentCacheContextTest\\:\\:providerTestGetContext\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', @@ -59746,12 +59674,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/Drupal/Tests/Core/Entity/EntityFormTest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\Core\\\\Entity\\\\EntityFormTest\\:\\:setUpStorage\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/tests/Drupal/Tests/Core/Entity/EntityFormTest.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\Core\\\\Entity\\\\EntityLinkTest\\:\\:providerTestLink\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', @@ -59932,12 +59854,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\Tests\\\\Core\\\\Entity\\\\Routing\\\\DefaultHtmlRouteProviderTest\\:\\:getEntityType\\(\\) return type with generic class Prophecy\\\\Prophecy\\\\ObjectProphecy does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\Core\\\\Entity\\\\Routing\\\\DefaultHtmlRouteProviderTest\\:\\:providerTestGetAddFormRoute\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', diff --git a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php index b924f4325347..edb40aa52b23 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php @@ -12,6 +12,7 @@ use Drupal\migrate\MigrateException; use Drupal\migrate\Row; use Prophecy\Argument; +use Prophecy\Prophecy\ObjectProphecy; /** * @coversDefaultClass \Drupal\migrate\MigrateExecutable @@ -557,10 +558,10 @@ public static function providerTestRollback() { /** * Returns an ID map object prophecy used in ::testRollback. * - * @return \Prophecy\Prophecy\ObjectProphecy + * @return \Prophecy\Prophecy\ObjectProphecy<\Drupal\migrate\Plugin\MigrateIdMapInterface> * An ID map object prophecy. */ - public function getTestRollbackIdMap(array $items, array $source_id_keys, array $destination_id_keys) { + public function getTestRollbackIdMap(array $items, array $source_id_keys, array $destination_id_keys): ObjectProphecy { static::$idMapRecords = array_map(function (array $item) { return $item + [ 'source_row_status' => '0', diff --git a/core/modules/package_manager/tests/src/Kernel/ComposerInspectorTest.php b/core/modules/package_manager/tests/src/Kernel/ComposerInspectorTest.php index aa3e4943278f..0411978a175c 100644 --- a/core/modules/package_manager/tests/src/Kernel/ComposerInspectorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/ComposerInspectorTest.php @@ -528,7 +528,7 @@ public function testAllowedPlugins(array $config, bool|array $expected_value): v * @param string|null $reported_version * The version number that `composer --format=json` should return. * - * @return \Prophecy\Prophecy\ObjectProphecy + * @return \Prophecy\Prophecy\ObjectProphecy<\PhpTuf\ComposerStager\API\Process\Service\ComposerProcessRunnerInterface> * The configurator for the mocked Composer runner. */ private function mockComposerRunner(?string $reported_version): ObjectProphecy { diff --git a/core/modules/serialization/tests/src/Traits/JsonSchemaTestTrait.php b/core/modules/serialization/tests/src/Traits/JsonSchemaTestTrait.php index a9c5020025b6..2a08c3214cca 100644 --- a/core/modules/serialization/tests/src/Traits/JsonSchemaTestTrait.php +++ b/core/modules/serialization/tests/src/Traits/JsonSchemaTestTrait.php @@ -34,6 +34,8 @@ abstract public static function jsonSchemaDataProvider(): array; /** * Method to make prophecy public for use in data provider closures. + * + * @return \Prophecy\Prophecy\ObjectProphecy<object> */ public function doProphesize(?string $classOrInterface = NULL): ObjectProphecy { return $this->prophesize($classOrInterface); diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php index 931fbe1aa012..c0cd1374ff6a 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php @@ -14,6 +14,7 @@ use Drupal\Core\TypedData\Plugin\DataType\Timestamp; use Drupal\serialization\Normalizer\TimestampItemNormalizer; use Drupal\Tests\UnitTestCase; +use Prophecy\Prophecy\ObjectProphecy; use Symfony\Component\Serializer\Serializer; /** @@ -171,9 +172,9 @@ public function testDenormalize(): void { /** * Creates a TimestampItem prophecy. * - * @return \Prophecy\Prophecy\ObjectProphecy|\Drupal\Core\Field\Plugin\Field\FieldType\TimestampItem + * @return \Prophecy\Prophecy\ObjectProphecy<\Drupal\Core\Field\Plugin\Field\FieldType\TimestampItem> */ - protected function createTimestampItemProphecy() { + protected function createTimestampItemProphecy(): ObjectProphecy { $timestamp_item = $this->prophesize(TimestampItem::class); $timestamp_item->getParent() ->willReturn(TRUE); diff --git a/core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php b/core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php index 868bfda31c4e..031ac4e63657 100644 --- a/core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php @@ -17,6 +17,7 @@ use Drupal\views\ViewEntityInterface; use Drupal\views\ViewExecutable; use Drupal\views\ViewsData; +use Prophecy\Prophecy\ObjectProphecy; use Symfony\Component\DependencyInjection\ContainerBuilder; /** @@ -149,9 +150,9 @@ protected function setupEntityTypeManager(EntityTypeManagerInterface $entity_typ * @param \Drupal\Core\Entity\EntityInterface[][] $entity_revisions_by_type * Test entities keyed by entity type and revision ID. * - * @return \Prophecy\Prophecy\ObjectProphecy + * @return \Prophecy\Prophecy\ObjectProphecy<\Drupal\Core\Entity\EntityTypeManagerInterface> */ - protected function setupEntityTypes($entities_by_type = [], $entity_revisions_by_type = []) { + protected function setupEntityTypes($entities_by_type = [], $entity_revisions_by_type = []): ObjectProphecy { $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class); $entity_type0 = new EntityType([ 'label' => 'First', diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/IsFrontPathCacheContextTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/IsFrontPathCacheContextTest.php index b54554dae0f5..5d4084b5b605 100644 --- a/core/tests/Drupal/Tests/Core/Cache/Context/IsFrontPathCacheContextTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/Context/IsFrontPathCacheContextTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Cache\Context\IsFrontPathCacheContext; use Drupal\Core\Path\PathMatcherInterface; use Drupal\Tests\UnitTestCase; +use Prophecy\Prophecy\ObjectProphecy; /** * @coversDefaultClass \Drupal\Core\Cache\Context\IsFrontPathCacheContext @@ -36,9 +37,9 @@ public function testGetContextNotFront(): void { * @param bool $is_front * Whether the page is the front page. * - * @return \Prophecy\Prophecy\ObjectProphecy + * @return \Prophecy\Prophecy\ObjectProphecy<\Drupal\Core\Path\PathMatcherInterface> */ - protected function createPathMatcher($is_front) { + protected function createPathMatcher($is_front): ObjectProphecy { $path_matcher = $this->prophesize(PathMatcherInterface::class); $path_matcher->isFrontPage() ->willReturn($is_front); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php index d91d63341507..e08b8702ce10 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php @@ -12,6 +12,7 @@ use Drupal\Core\Form\FormState; use Drupal\Core\Routing\RouteMatch; use Drupal\Tests\UnitTestCase; +use Prophecy\Prophecy\ObjectProphecy; use Symfony\Component\Routing\Route; /** @@ -244,10 +245,10 @@ public function testGetEntityFromRouteMatchAddEntity(): void { /** * Sets up the storage accessed via the entity type manager in the form. * - * @return \Prophecy\Prophecy\ObjectProphecy + * @return \Prophecy\Prophecy\ObjectProphecy<\Drupal\Core\Entity\EntityStorageInterface> * The storage prophecy. */ - protected function setUpStorage() { + protected function setUpStorage(): ObjectProphecy { $storage = $this->prophesize(EntityStorageInterface::class); $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class); diff --git a/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php b/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php index 053c05ebd97e..82593d4aa6b2 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php @@ -382,9 +382,9 @@ public function testGetEntityTypeIdKeyTypeNotFieldable(): void { * @param \Prophecy\Prophecy\ObjectProphecy|null $base_entity_type * (optional) The prophesize base entity type. * - * @return \Prophecy\Prophecy\ObjectProphecy + * @return \Prophecy\Prophecy\ObjectProphecy<\Drupal\Core\Entity\EntityTypeInterface> */ - protected static function getEntityType(?ObjectProphecy $base_entity_type = NULL) { + protected static function getEntityType(?ObjectProphecy $base_entity_type = NULL): ObjectProphecy { $entity_type = (new Prophet())->prophesize(EntityTypeInterface::class); if ($base_entity_type) { foreach ($base_entity_type->getMethodProphecies() as $prophecies) { -- GitLab