Issue #3240888 by andypost, alexpott: Using Prophecy to implement Serializable will cause deprecations on PHP 8.1

merge-requests/950/merge
Lee Rowlands 2021-10-06 13:35:53 +10:00
parent c9bcb2c8d6
commit a19e99354e
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
2 changed files with 38 additions and 10 deletions

View File

@ -7,7 +7,7 @@ use Drupal\Core\Entity\Entity\EntityFormMode;
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 @@ class EntityTypeTest extends UnitTestCase {
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 @@ class EntityTypeTest extends UnitTestCase {
}
}
/**
* Test class.
*/
class UnserializableTranslationManager extends TranslationManager {
/**
* Constructs a UnserializableTranslationManager object.
*/
public function __construct() {
}
/**
* @return array
*/
public function __serialize(): array {
throw new \Exception();
}
}

View File

@ -355,12 +355,9 @@ class SharedTempStoreTest extends UnitTestCase {
*/
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 @@ class SharedTempStoreTest extends UnitTestCase {
}
}
/**
* A class for testing.
*/
class UnserializableRequest extends Request {
/**
* @return array
*/
public function __serialize(): array {
throw new \LogicException('Oops!');
}
}