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

merge-requests/9136/head
catch 2024-08-09 17:08:50 +09:00
parent bd4a29dada
commit 49720dc872
5 changed files with 36 additions and 28 deletions

View File

@ -2521,18 +2521,6 @@ $ignoreErrors[] = [
'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,

View File

@ -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 @@ class PluginBaseTest extends TestCase {
* @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 @@ class PluginBaseTest extends TestCase {
* @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 @@ class PluginBaseTest extends TestCase {
* @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());
}

View File

@ -6,7 +6,6 @@ namespace Drupal\Tests\Component\Plugin;
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 @@ class PluginManagerBaseTest extends TestCase {
* @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 @@ class PluginManagerBaseTest extends TestCase {
'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)));

View File

@ -0,0 +1,13 @@
<?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 {
}

View File

@ -0,0 +1,13 @@
<?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 {
}