[META] Serialization issues in Migration tests

Created on 15 January 2021, almost 4 years ago
Updated 9 November 2023, about 1 year ago

Problem/Motivation

When running migration Kernel tests, i.e. MigrateNodeComleteTest.php, an error in the source plugin query results in fatal errors from PHPUnit and not a helpful SQL error as expected. The only way to see a useful error message is to use the debugger/

There were 2 errors:

1) Was moved into πŸ› Exception trace cannot be serialized because of closure Needs work .
2)

Drupal\Tests\taxonomy\Kernel\Migrate\d7\MigrateTaxonomyTermTest::testTaxonomyTermEntityTranslations
PHPUnit\Framework\Exception: PHP Fatal error:  Uncaught Exception: Serialization of 'Closure' is not allowed in Standard input code:80
Stack trace:
#0 Standard input code(80): serialize(Array)
#1 Standard input code(112): __phpunit_run_isolated_test()
#2 {main}
  thrown in Standard input code on line 80
Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed in Standard input code:80
Stack trace:
#0 Standard input code(80): serialize(Array)
#1 Standard input code(112): __phpunit_run_isolated_test()
#2 {main}
  thrown in Standard input code on line 80

/var/www/html/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php:254
/var/www/html/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php:171
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php:601
/var/www/html/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:633
/var/www/html/vendor/phpunit/phpunit/src/TextUI/Command.php:204
/var/www/html/vendor/phpunit/phpunit/src/TextUI/Command.php:163

--

🌱 Plan
Status

Active

Version

11.0 πŸ”₯

Component
MigrationΒ  β†’

Last updated about 7 hours ago

Created by

πŸ‡³πŸ‡ΏNew Zealand quietone

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.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Just ran into this at πŸ› The migration tests are currently not running Postponed

  • πŸ‡ΊπŸ‡¦Ukraine pingwin4eg Zaporizhia πŸ‡ΊπŸ‡¦

    I also encountered the "container was serialized" issue with a migration test in Style Switcher module with D 9.5.11, PHP 8.1, PHPUnits 8.5.31 (local) and 9.5.28 (DrupalCI):

    1) Drupal\Tests\styleswitcher\Kernel\Migrate\d7\MigrateVariablesTest::testVariablesMigration
    PHPUnit\Framework\Exception: PHP Fatal error:  Uncaught AssertionError: The container was serialized. in /var/www/html/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php:99
    Stack trace:
    #0 /var/www/html/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php(99): assert(false, 'The container w...')
    #1 [internal function]: Drupal\Core\DependencyInjection\ContainerBuilder->__sleep()
    #2 Standard input code(89): serialize(Array)
    #3 Standard input code(123): __phpunit_run_isolated_test()
    #4 {main}
      thrown in /var/www/html/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php on line 99
    

    When I switched PHP to 7.3 locally I saw the actual error:

    1) Drupal\Tests\styleswitcher\Kernel\Migrate\d7\MigrateVariablesTest::testVariablesMigration
    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 /app/core/lib/Drupal/Core/Database/Connection.php:2042
    Stack trace:
    #0 [internal function]: Drupal\Core\Database\Connection->__sleep()
    #1 Standard input code(80): serialize(Array)
    #2 Standard input code(112): __phpunit_run_isolated_test()
    #3 {main}
      thrown in /app/core/lib/Drupal/Core/Database/Connection.php on line 2042
    

    The workaround was to call $this->startCollectingMessages(); before $this->executeMigrations(...).

  • πŸ‡³πŸ‡±Netherlands johnv

    Relating to another meta issue [33400483]

Production build 0.71.5 2024