From 2c6c1ae6f7c0b55b65e628de80b54de9dae0ba05 Mon Sep 17 00:00:00 2001 From: catch <6915-catch@users.noreply.drupalcode.org> Date: Fri, 13 Sep 2024 16:26:39 +0100 Subject: [PATCH] Issue #3471456 by mondrake: Method getMockForAbstractClass() of class PHPUnit\Framework\TestCase is deprecated in PHPUnit 10 - replace in class class MigrateExecutableTest --- core/.phpstan-baseline.php | 6 -- .../tests/src/Unit/MigrateExecutableTest.php | 11 +--- .../tests/src/Unit/MigrateSourceTest.php | 58 ++----------------- .../tests/src/Unit/StubSourcePlugin.php | 53 +++++++++++++++++ 4 files changed, 58 insertions(+), 70 deletions(-) create mode 100644 core/modules/migrate/tests/src/Unit/StubSourcePlugin.php diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index 2cd5515acb71..75b67460e629 100644 --- a/core/.phpstan-baseline.php +++ b/core/.phpstan-baseline.php @@ -1298,12 +1298,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/migrate/tests/src/Kernel/MigrateTestBase.php', ]; -$ignoreErrors[] = [ - // identifier: method.deprecated - 'message' => '#^Call to deprecated method getMockForAbstractClass\\(\\) of class PHPUnit\\\\Framework\\\\MockObject\\\\MockBuilder\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/migrate/tests/src/Unit/MigrateExecutableTest.php', -]; $ignoreErrors[] = [ // identifier: variable.undefined 'message' => '#^Variable \\$sub_process_plugins might not be defined\\.$#', diff --git a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php index 05114d778b5f..8325f96bb6e5 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php @@ -440,18 +440,9 @@ public function testProcessRowEmptyDestination(): void { * The mocked migration source. */ protected function getMockSource() { - $this->createMock('\Iterator'); - - $class = 'Drupal\migrate\Plugin\migrate\source\SourcePluginBase'; - $source = $this->getMockBuilder($class) - ->disableOriginalConstructor() - ->onlyMethods(get_class_methods($class)) - ->getMockForAbstractClass(); + $source = $this->createMock(StubSourcePlugin::class); $source->expects($this->once()) ->method('rewind'); - $source->expects($this->any()) - ->method('initializeIterator') - ->willReturn([]); $source->expects($this->any()) ->method('valid') ->willReturn(TRUE, FALSE); diff --git a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php index e853f974203c..2f0b85ffbc47 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php @@ -450,51 +450,6 @@ protected function getMigrateExecutable($migration) { } -/** - * Stubbed source plugin for testing base class implementations. - */ -class StubSourcePlugin extends SourcePluginBase { - - /** - * Helper for setting internal module handler implementation. - * - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. - */ - public function setModuleHandler(ModuleHandlerInterface $module_handler) { - $this->moduleHandler = $module_handler; - } - - /** - * {@inheritdoc} - */ - public function fields() { - return []; - } - - /** - * {@inheritdoc} - */ - public function __toString() { - return ''; - } - - /** - * {@inheritdoc} - */ - public function getIds() { - return []; - } - - /** - * {@inheritdoc} - */ - protected function initializeIterator() { - return []; - } - -} - /** * Defines a stubbed source plugin with a generator as iterator. * @@ -542,15 +497,10 @@ public function getTrackChanges() { /** * {@inheritdoc} */ - protected function initializeIterator() { - $data = [ - ['title' => 'foo'], - ['title' => 'bar'], - ['title' => 'iggy'], - ]; - foreach ($data as $row) { - yield $row; - } + protected function initializeIterator(): \Generator { + yield 'foo'; + yield 'bar'; + yield 'iggy'; } } diff --git a/core/modules/migrate/tests/src/Unit/StubSourcePlugin.php b/core/modules/migrate/tests/src/Unit/StubSourcePlugin.php new file mode 100644 index 000000000000..b7a52d926e1f --- /dev/null +++ b/core/modules/migrate/tests/src/Unit/StubSourcePlugin.php @@ -0,0 +1,53 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\Tests\migrate\Unit; + +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\migrate\Plugin\migrate\source\SourcePluginBase; + +/** + * Stubbed source plugin for testing base class implementations. + */ +class StubSourcePlugin extends SourcePluginBase { + + /** + * Helper for setting internal module handler implementation. + * + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. + */ + public function setModuleHandler(ModuleHandlerInterface $module_handler): void { + $this->moduleHandler = $module_handler; + } + + /** + * {@inheritdoc} + */ + public function fields(): array { + return []; + } + + /** + * {@inheritdoc} + */ + public function __toString(): string { + return ''; + } + + /** + * {@inheritdoc} + */ + public function getIds(): array { + return []; + } + + /** + * {@inheritdoc} + */ + protected function initializeIterator(): \Iterator { + return []; + } + +} -- GitLab