Issue #3240888 by andypost, alexpott: Using Prophecy to implement Serializable will cause deprecations on PHP 8.1
parent
c9bcb2c8d6
commit
a19e99354e
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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!');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue