Problem/Motivation

Using Prophecy to implement Serializable will cause deprecations on PHP 8.1.

Steps to reproduce

Run core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php on PHP 8.1
Run core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php on PHP 8.1

Proposed resolution

Add objects the implement __serialize() to the test's namespace

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

andypost created an issue. See original summary.

andypost’s picture

Status: Active » Needs review
StatusFileSize
new1.42 KB
Other deprecation notices (1)

  1x: Double\Symfony\Component\HttpFoundation\Request\P1 implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary)
    1x in SharedTempStoreTest::testSerialization from Drupal\Tests\Core\TempStore

using patch from https://git.drupalcode.org/project/drupal/-/commit/46579a8cd9a1af5280882...

andypost’s picture

StatusFileSize
new2.18 KB
new3.8 KB

And the remains of commit

andypost’s picture

StatusFileSize
new1.42 KB

Re-upload #2 as DeprecationListenerTrait already has no such changes

alexpott’s picture

Title: \Drupal\Tests\Core\TempStore\SharedTempStoreTest::testSerialization() causes deprecations on PHP 8.1 » Using Prophecy to implement Serializable will cause deprecations on PHP 8.1
Issue summary: View changes
StatusFileSize
new1.3 KB
new2.79 KB

I wrote this code on the metas issue #3220021: [meta] Ensure compatibility of Drupal 9 with PHP 8.1 (as it evolves).

Let's also do core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php here too as it fails for the same reason.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Great catch, confirm fix

Other deprecation notices (1)

  1x: Double\TranslationInterface\Serializable\P1 implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary)
    1x in EntityTypeTest::testIsSerializable from Drupal\Tests\Core\Entity
larowlan’s picture

Status: Reviewed & tested by the community » Needs review
  1. +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
    @@ -7,7 +7,7 @@
    +use Drupal\Core\StringTranslation\TranslationManager;
    

    unused?

  2. +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
    @@ -515,9 +515,8 @@ public function testIsSubClassOf() {
    +    $translation = $this->prophesize(UnserializableTranslationManager::class);
    +    $translation->__serialize()->willThrow(\Exception::class);
    
    @@ -528,3 +527,17 @@ public function testIsSerializable() {
    + * Test class.
    + */
    +class UnserializableTranslationManager extends TranslationManager {
    +
    +  /**
    +   * @return array
    +   */
    +  public function __serialize(): array {
    +    throw new \Exception();
    +  }
    +
    

    do we need to prophesize if we've got a test dummy?

andypost’s picture

StatusFileSize
new1.15 KB
new2.89 KB

Re #7

1) it's used in extends UnserializableTranslationManager extends TranslationManager
2) yes, no need, the magic happens because $translation_service->_serviceId = 'string_translation';

alexpott’s picture

StatusFileSize
new1.23 KB
new2.89 KB

Let's decouple from the constructor too.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Checked test locally - works perfect and a bit cleaner, bot should be green. thank you

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: 3240888-9.patch, failed testing. View results

andypost’s picture

andypost’s picture

Status: Needs work » Needs review
andypost’s picture

Status: Needs review » Reviewed & tested by the community

back to RTBC

  • larowlan committed a19e993 on 9.3.x
    Issue #3240888 by andypost, alexpott: Using Prophecy to implement...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed a19e993 and pushed to 9.3.x. Merci beaucoup!

Status: Fixed » Closed (fixed)

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