Automatic Updates & Package Manager should use DependencySerializationTrait when needed

Created on 6 December 2022, over 1 year ago
Updated 23 January 2023, over 1 year ago

Problem/Motivation

While debugging #3320824-9: Fix PHP Warning: serialize() in tests on PHP 8 β†’ I discovered that Automatic Updates & Package Manager are not using DependencySerializationTrait anywhere.

Consequence: debugability of (kernel) tests is non-existent.

Steps to reproduce

Run any test whose test data eventually contains a reference to the database, for example \Drupal\Tests\package_manager\Kernel\LockFileValidatorTest::testLockFileChanged().

Without xdebug:

PHPUnit 9.5.26 by Sebastian Bergmann and contributors.

Testing /Users/wim.leers/core/modules/contrib/automatic_updates/package_manager/tests/src/Kernel
..                                                                  2 / 2 (100%)

Time: 00:04.005, Memory: 10.00 MB

OK (2 tests, 10 assertions)
Process finished with exit code 0

with xdebug on, you hit \Drupal\Core\Database\Connection::__sleep()'s exception:

  public function __sleep() {
    throw new \LogicException('The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution.');
  }

and that looks like this:

/opt/homebrew/bin/php /private/var/folders/x1/mlh998q15c70vs7_y8s1mgqm0000gp/T/ide-phpunit.php --configuration /Users/wim.leers/core/core/phpunit.xml --filter "/(Drupal\\Tests\\package_manager\\Kernel\\LockFileValidatorTest::testLockFileChanged)( .*)?$/" --test-suffix LockFileValidatorTest.php /Users/wim.leers/core/modules/contrib/automatic_updates/package_manager/tests/src/Kernel
Testing started at 11:33 AM ...
PHPUnit 9.5.26 by Sebastian Bergmann and contributors.

Testing /Users/wim.leers/core/modules/contrib/automatic_updates/package_manager/tests/src/Kernel
ER                                                                  2 / 2 (100%)E

Time: 00:15.854, Memory: 10.00 MB

There were 2 errors:

1) Drupal\Tests\package_manager\Kernel\LockFileValidatorTest::testLockFileChanged with data set "pre-require" ('Drupal\package_manager\Event\...eEvent')
PHPUnit\Framework\Exception: PHP Fatal error:  Uncaught LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution. in /Users/wim.leers/core/core/lib/Drupal/Core/Database/Connection.php:1685
Stack trace:
#0 [internal function]: Drupal\Core\Database\Connection->__sleep()
#1 Standard input code(89): serialize(Array)
#2 Standard input code(123): __phpunit_run_isolated_test()
#3 {main}
  thrown in /Users/wim.leers/core/core/lib/Drupal/Core/Database/Connection.php on line 1685
Fatal error: Uncaught LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution. in /Users/wim.leers/core/core/lib/Drupal/Core/Database/Connection.php:1685
Stack trace:
#0 [internal function]: Drupal\Core\Database\Connection->__sleep()
#1 Standard input code(89): serialize(Array)
#2 Standard input code(123): __phpunit_run_isolated_test()
#3 {main}
  thrown in /Users/wim.leers/core/core/lib/Drupal/Core/Database/Connection.php on line 1685

/Users/wim.leers/core/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php:270
/Users/wim.leers/core/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php:187
/Users/wim.leers/core/vendor/phpunit/phpunit/src/Framework/TestSuite.php:673
/Users/wim.leers/core/vendor/phpunit/phpunit/src/Framework/TestSuite.php:673
/Users/wim.leers/core/vendor/phpunit/phpunit/src/Framework/TestSuite.php:673
/Users/wim.leers/core/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:661
/Users/wim.leers/core/vendor/phpunit/phpunit/src/TextUI/Command.php:144
/Users/wim.leers/core/vendor/phpunit/phpunit/src/TextUI/Command.php:97
/Users/wim.leers/core/vendor/phpunit/phpunit/phpunit:98

2) Drupal\Tests\package_manager\Kernel\LockFileValidatorTest::testLockFileChanged with data set "pre-apply" ('Drupal\package_manager\Event\...yEvent')
PHPUnit\Framework\Exception: PHP Fatal error:  Uncaught LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution. in /Users/wim.leers/core/core/lib/Drupal/Core/Database/Connection.php:1685
Stack trace:
#0 [internal function]: Drupal\Core\Database\Connection->__sleep()
#1 Standard input code(89): serialize(Array)
#2 Standard input code(123): __phpunit_run_isolated_test()
#3 {main}
  thrown in /Users/wim.leers/core/core/lib/Drupal/Core/Database/Connection.php on line 1685
Fatal error: Uncaught LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution. in /Users/wim.leers/core/core/lib/Drupal/Core/Database/Connection.php:1685
Stack trace:
#0 [internal function]: Drupal\Core\Database\Connection->__sleep()
#1 Standard input code(89): serialize(Array)
#2 Standard input code(123): __phpunit_run_isolated_test()
#3 {main}
  thrown in /Users/wim.leers/core/core/lib/Drupal/Core/Database/Connection.php on line 1685

/Users/wim.leers/core/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php:270
/Users/wim.leers/core/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php:187
/Users/wim.leers/core/vendor/phpunit/phpunit/src/Framework/TestSuite.php:673
/Users/wim.leers/core/vendor/phpunit/phpunit/src/Framework/TestSuite.php:673
/Users/wim.leers/core/vendor/phpunit/phpunit/src/Framework/TestSuite.php:673
/Users/wim.leers/core/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:661
/Users/wim.leers/core/vendor/phpunit/phpunit/src/TextUI/Command.php:144
/Users/wim.leers/core/vendor/phpunit/phpunit/src/TextUI/Command.php:97
/Users/wim.leers/core/vendor/phpunit/phpunit/phpunit:98

Proposed resolution

Use DependencySerializationTrait where needed.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: outdated

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024