Unverified Commit 55bab340 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3481539 by mondrake: Method getMockForAbstractClass() is deprecated -...

Issue #3481539 by mondrake: Method getMockForAbstractClass() is deprecated - replace in EntityUrlTest
parent 56186f90
Loading
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -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\\.$#',
+10 −28
Original line number Diff line number Diff line
@@ -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;
  }

}
+76 −0
Original line number Diff line number Diff line
<?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 {
  }

}