diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index b7f50366bded0c9390b37be80551f47a43d335e9..c77e49e08ca8cb667d8ba66d4b86d44b8f83c3a4 100644 --- a/core/.phpstan-baseline.php +++ b/core/.phpstan-baseline.php @@ -67989,12 +67989,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php', ]; -$ignoreErrors[] = [ - // identifier: method.deprecated - 'message' => '#^Call to deprecated method getMockForAbstractClass\\(\\) of class PHPUnit\\\\Framework\\\\MockObject\\\\MockBuilder\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\Tests\\\\Core\\\\Entity\\\\FieldDefinitionTest\\:\\:factoryTypeProvider\\(\\) has no return type specified\\.$#', diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php index 271af88f2ceede945b52351647ddc2b153f5413e..40ffea78bd74ced904a4f3e2cc99128a669adeaf 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php @@ -9,11 +9,11 @@ use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException; -use Drupal\Core\Entity\RevisionableInterface; use Drupal\Core\GeneratedUrl; use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Url; use Drupal\Tests\UnitTestCase; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; /** @@ -215,8 +215,8 @@ public static function providerTestToUrlLinkTemplates() { */ public function testToUrlLinkTemplateRevision(bool $is_default_revision, string $link_template, string $expected_route_name, array $expected_route_parameters): void { $values = ['id' => static::ENTITY_ID, 'langcode' => $this->langcode]; - $entity = $this->getEntity(RevisionableEntity::class, $values, ['getRevisionId', 'isDefaultRevision']); - assert($entity instanceof RevisionableEntity); + $entity = $this->getEntity(StubRevisionableEntity::class, $values, ['getRevisionId', 'isDefaultRevision']); + assert($entity instanceof StubRevisionableEntity); $entity->method('getRevisionId')->willReturn(static::REVISION_ID); $entity->method('isDefaultRevision')->willReturn($is_default_revision); $this->registerLinkTemplate($link_template); @@ -462,18 +462,18 @@ public function testUriRelationships(): void { /** * Returns a mock entity for testing. * - * @param string $class + * @param class-string<\Drupal\Tests\Core\Entity\StubEntityBase> $class * The class name to mock. Should be \Drupal\Tests\Core\Entity\StubEntityBase * or a subclass. - * @param array $values + * @param array<string,int|string> $values * An array of entity values to construct the mock entity with. - * @param array $methods - * (optional) An array of additional methods to mock on the entity object. + * @param list<string> $methods + * (optional) A list of additional methods to mock on the entity object. * The getEntityType() and entityTypeBundleInfo() methods are always mocked. * - * @return \Drupal\Tests\Core\Entity\StubEntityBase|\PHPUnit\Framework\MockObject\MockObject + * @return \Drupal\Tests\Core\Entity\StubEntityBase&\PHPUnit\Framework\MockObject\MockObject */ - protected function getEntity($class, array $values, array $methods = []) { + protected function getEntity(string $class, array $values, array $methods = []): StubEntityBase&MockObject { $methods = array_merge($methods, ['getEntityType', 'entityTypeBundleInfo']); // Prophecy does not allow prophesizing abstract classes while actually @@ -482,7 +482,7 @@ protected function getEntity($class, array $values, array $methods = []) { $entity = $this->getMockBuilder($class) ->setConstructorArgs([$values, static::ENTITY_TYPE_ID]) ->onlyMethods($methods) - ->getMockForAbstractClass(); + ->getMock(); $this->entityType = $this->prophesize(EntityTypeInterface::class); $this->entityType->getLinkTemplates()->willReturn([]); @@ -552,21 +552,3 @@ protected function registerBundleInfo($bundle_info): void { } } - -abstract class RevisionableEntity extends StubEntityBase implements RevisionableInterface { - - /** - * {@inheritdoc} - */ - public function getRevisionId(): int|string|NULL { - return NULL; - } - - /** - * {@inheritdoc} - */ - public function isDefaultRevision($new_value = NULL): bool { - return FALSE; - } - -} diff --git a/core/tests/Drupal/Tests/Core/Entity/StubRevisionableEntity.php b/core/tests/Drupal/Tests/Core/Entity/StubRevisionableEntity.php new file mode 100644 index 0000000000000000000000000000000000000000..6a054c613fe9991e114f117ed85f23506d5a8dea --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Entity/StubRevisionableEntity.php @@ -0,0 +1,76 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\Tests\Core\Entity; + +use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\RevisionableInterface; + +/** + * A stub revisionable entity for testing purposes. + */ +class StubRevisionableEntity extends StubEntityBase implements RevisionableInterface { + + /** + * {@inheritdoc} + */ + public function isNewRevision(): bool { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function setNewRevision($value = TRUE): void { + } + + /** + * {@inheritdoc} + */ + public function getRevisionId(): int|string|NULL { + return NULL; + } + + /** + * {@inheritdoc} + */ + public function getLoadedRevisionId(): ?int { + return NULL; + } + + /** + * {@inheritdoc} + */ + public function updateLoadedRevisionId(): static { + return $this; + } + + /** + * {@inheritdoc} + */ + public function isDefaultRevision($new_value = NULL): bool { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function wasDefaultRevision(): bool { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function isLatestRevision(): bool { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record): void { + } + +}