Unverified Commit a19e9935 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3240888 by andypost, alexpott: Using Prophecy to implement Serializable...

Issue #3240888 by andypost, alexpott: Using Prophecy to implement Serializable will cause deprecations on PHP 8.1
parent c9bcb2c8
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
use Drupal\Core\Entity\EntityType;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\StringTranslation\TranslationManager;
use Drupal\Tests\UnitTestCase;

/**
@@ -515,10 +515,7 @@ public function testIsSubClassOf() {
  public function testIsSerializable() {
    $entity_type = $this->setUpEntityType([]);

    $translation = $this->prophesize(TranslationInterface::class);
    $translation->willImplement(\Serializable::class);
    $translation->serialize()->willThrow(\Exception::class);
    $translation_service = $translation->reveal();
    $translation_service = new UnserializableTranslationManager();
    $translation_service->_serviceId = 'string_translation';

    $entity_type->setStringTranslation($translation_service);
@@ -528,3 +525,23 @@ public function testIsSerializable() {
  }

}

/**
 * Test class.
 */
class UnserializableTranslationManager extends TranslationManager {

  /**
   * Constructs a UnserializableTranslationManager object.
   */
  public function __construct() {
  }

  /**
   * @return array
   */
  public function __serialize(): array {
    throw new \Exception();
  }

}
+16 −5
Original line number Diff line number Diff line
@@ -355,12 +355,9 @@ public function testDeleteIfOwner() {
   */
  public function testSerialization() {
    // Add an unserializable request to the request stack. If the tempstore
    // didn't use DependencySerializationTrait, the exception would be thrown
    // didn't use DependencySerializationTrait, an exception would be thrown
    // when we try to serialize the tempstore.
    $request = $this->prophesize(Request::class);
    $request->willImplement('\Serializable');
    $request->serialize()->willThrow(new \LogicException('Oops!'));
    $unserializable_request = $request->reveal();
    $unserializable_request = new UnserializableRequest();

    $this->requestStack->push($unserializable_request);
    $this->requestStack->_serviceId = 'request_stack';
@@ -427,3 +424,17 @@ public function testLegacyFactoryConstructor() {
  }

}

/**
 * A class for testing.
 */
class UnserializableRequest extends Request {

  /**
   * @return array
   */
  public function __serialize(): array {
    throw new \LogicException('Oops!');
  }

}