Unverified Commit a19e9935 authored by larowlan's avatar larowlan
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
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
use Drupal\Core\Entity\EntityType; use Drupal\Core\Entity\EntityType;
use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationManager;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
/** /**
...@@ -515,10 +515,7 @@ public function testIsSubClassOf() { ...@@ -515,10 +515,7 @@ public function testIsSubClassOf() {
public function testIsSerializable() { public function testIsSerializable() {
$entity_type = $this->setUpEntityType([]); $entity_type = $this->setUpEntityType([]);
$translation = $this->prophesize(TranslationInterface::class); $translation_service = new UnserializableTranslationManager();
$translation->willImplement(\Serializable::class);
$translation->serialize()->willThrow(\Exception::class);
$translation_service = $translation->reveal();
$translation_service->_serviceId = 'string_translation'; $translation_service->_serviceId = 'string_translation';
$entity_type->setStringTranslation($translation_service); $entity_type->setStringTranslation($translation_service);
...@@ -528,3 +525,23 @@ public function testIsSerializable() { ...@@ -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();
}
}
...@@ -355,12 +355,9 @@ public function testDeleteIfOwner() { ...@@ -355,12 +355,9 @@ public function testDeleteIfOwner() {
*/ */
public function testSerialization() { public function testSerialization() {
// Add an unserializable request to the request stack. If the tempstore // 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. // when we try to serialize the tempstore.
$request = $this->prophesize(Request::class); $unserializable_request = new UnserializableRequest();
$request->willImplement('\Serializable');
$request->serialize()->willThrow(new \LogicException('Oops!'));
$unserializable_request = $request->reveal();
$this->requestStack->push($unserializable_request); $this->requestStack->push($unserializable_request);
$this->requestStack->_serviceId = 'request_stack'; $this->requestStack->_serviceId = 'request_stack';
...@@ -427,3 +424,17 @@ public function testLegacyFactoryConstructor() { ...@@ -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!');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment