Commit b1987186 authored by catch's avatar catch
Browse files

Issue #3464213 by mondrake: Method getMockForAbstractClass() of class...

Issue #3464213 by mondrake: Method getMockForAbstractClass() of class PHPUnit\Framework\TestCase is deprecated in PHPUnit 10 - replace in Plugin component tests

(cherry picked from commit 49720dc8)
parent b3f2f8de
Loading
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -2552,18 +2552,6 @@
	'count' => 1,
	'path' => __DIR__ . '/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php',
];
$ignoreErrors[] = [
	// identifier: method.deprecated
	'message' => '#^Call to deprecated method getMockForAbstractClass\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\.$#',
	'count' => 4,
	'path' => __DIR__ . '/tests/Drupal/Tests/Component/Plugin/PluginBaseTest.php',
];
$ignoreErrors[] = [
	// identifier: method.deprecated
	'message' => '#^Call to deprecated method getMockForAbstractClass\\(\\) of class PHPUnit\\\\Framework\\\\MockObject\\\\MockBuilder\\.$#',
	'count' => 2,
	'path' => __DIR__ . '/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Missing cache backend declaration for performance\\.$#',
	'count' => 1,
+8 −10
Original line number Diff line number Diff line
@@ -17,11 +17,11 @@ class PluginBaseTest extends TestCase {
   * @covers ::getPluginId
   */
  public function testGetPluginId($plugin_id, $expected): void {
    $plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
    $plugin_base = new StubPluginBase(
      [],
      $plugin_id,
      [],
    ]);
    );

    $this->assertEquals($expected, $plugin_base->getPluginId());
  }
@@ -43,12 +43,11 @@ public static function providerTestGetPluginId() {
   * @coves ::getBaseId
   */
  public function testGetBaseId($plugin_id, $expected): void {
    /** @var \Drupal\Component\Plugin\PluginBase|\PHPUnit\Framework\MockObject\MockObject $plugin_base */
    $plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
    $plugin_base = new StubPluginBase(
      [],
      $plugin_id,
      [],
    ]);
    );

    $this->assertEquals($expected, $plugin_base->getBaseId());
  }
@@ -70,12 +69,11 @@ public static function providerTestGetBaseId() {
   * @covers ::getDerivativeId
   */
  public function testGetDerivativeId($plugin_id = NULL, $expected = NULL): void {
    /** @var \Drupal\Component\Plugin\PluginBase|\PHPUnit\Framework\MockObject\MockObject $plugin_base */
    $plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
    $plugin_base = new StubPluginBase(
      [],
      $plugin_id,
      [],
    ]);
    );

    $this->assertEquals($expected, $plugin_base->getDerivativeId());
  }
@@ -96,11 +94,11 @@ public static function providerTestGetDerivativeId() {
   * @covers ::getPluginDefinition
   */
  public function testGetPluginDefinition(): void {
    $plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
    $plugin_base = new StubPluginBase(
      [],
      'plugin_id',
      ['value', ['key' => 'value']],
    ]);
    );

    $this->assertEquals(['value', ['key' => 'value']], $plugin_base->getPluginDefinition());
  }
+2 −6
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@

use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Component\Plugin\Mapper\MapperInterface;
use Drupal\Component\Plugin\PluginManagerBase;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

@@ -51,8 +50,7 @@ public function getMockFactoryInterface($expects_count) {
   * @covers ::createInstance
   */
  public function testCreateInstance(): void {
    $manager = $this->getMockBuilder('Drupal\Component\Plugin\PluginManagerBase')
      ->getMockForAbstractClass();
    $manager = new StubPluginManagerBase();
    // PluginManagerBase::createInstance() looks for a factory object and then
    // calls createInstance() on it. So we have to mock a factory object.
    $factory_ref = new \ReflectionProperty($manager, 'factory');
@@ -118,9 +116,7 @@ public function testGetInstanceWithoutMapperShouldThrowException(): void {
      'foo' => 'F00',
      'bar' => 'bAr',
    ];
    /** @var \Drupal\Component\Plugin\PluginManagerBase $manager */
    $manager = $this->getMockBuilder(PluginManagerBase::class)
      ->getMockForAbstractClass();
    $manager = new StubPluginManagerBase();
    // Set the expected exception thrown by ::getInstance.
    $this->expectException(\BadMethodCallException::class);
    $this->expectExceptionMessage(sprintf('%s does not support this method unless %s::$mapper is set.', get_class($manager), get_class($manager)));
+13 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\Component\Plugin;

use Drupal\Component\Plugin\PluginBase;

/**
 * A class extending PluginBase for testing purposes.
 */
class StubPluginBase extends PluginBase {
}
+13 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\Component\Plugin;

use Drupal\Component\Plugin\PluginManagerBase;

/**
 * A class extending PluginManagerBase for testing purposes.
 */
class StubPluginManagerBase extends PluginManagerBase {
}