Problem/Motivation

Running core/modules/migrate/tests/src/Unit/process/MakeUniqueEntityFieldTest.php and core/modules/migrate/tests/src/Unit/MigrateSqlIdMapEnsureTablesTest.php on PHP 8.1 triggers deprecations.

MigrateSqlIdMapEnsureTablesTest is due to the database prefix method returning a NULL.
MakeUniqueEntityFieldTest is due to $start being NULL and passed to mb_substr().

Steps to reproduce

Run the tests on PHP 8.1

Proposed resolution

Fix the tests.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 3241130-2.patch1.98 KBalexpott
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Title: \Drupal\Tests\migrate\Unit\MigrateSqlIdMapEnsureTablesTest triggers a deprecation on PHP 8.1 » Migrate units test trigger deprecations on PHP 8.1
Issue summary: View changes
Status: Active » Needs review
FileSize
1.98 KB
alexpott’s picture

Issue summary: View changes
daffie’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.
The third parameter of mb_substr() is allowed to be NULL. Therefor no change needed for the variable $length.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapEnsureTablesTest.php
@@ -200,6 +200,9 @@ protected function runEnsureTablesTest($schema) {
+    $database->expects($this->any())
+      ->method('tablePrefix')
+      ->willReturn('');

Is this change required?

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

@larowlan yes. That method shoudl return a string but our mock returns a NULL so we need to fix that. See \Drupal\Core\Database\Connection::setPrefix() and \Drupal\Core\Database\Connection::tablePrefix(). The method will always return a string in reality because $this->prefixes[$table]; or $this->prefixes['default']; is always set.

  • larowlan committed 8ce8eb9 on 9.3.x
    Issue #3241130 by alexpott: Migrate units test trigger deprecations on...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the explanation @alexpott

Committed 8ce8eb9 and pushed to 9.3.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.