Issue #3361401 by Spokje, andypost: Remove remaining occurences of ::supportedInterfaceOrClass property

merge-requests/4088/head
catch 2023-05-20 09:22:49 +01:00
parent 889a6c485a
commit a45da8ddd1
3 changed files with 18 additions and 10 deletions

View File

@ -22,7 +22,7 @@ class ComplexDataNormalizer extends NormalizerBase {
*/
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
$attributes = [];
// $object will not always match $supportedInterfaceOrClass.
// $object will not always match getSupportedTypes().
// @see \Drupal\serialization\Normalizer\EntityNormalizer
// Other normalizers that extend this class may only provide $object that
// implements \Traversable.

View File

@ -118,6 +118,14 @@ class ComplexDataNormalizerTest extends UnitTestCase {
* Test normalizer with a different supported class.
*/
class TestExtendedNormalizer extends ComplexDataNormalizer {
protected $supportedInterfaceOrClass = \stdClass::class;
/**
* {@inheritdoc}
*/
public function getSupportedTypes(?string $format): array {
return [
\stdClass::class => TRUE,
];
}
}

View File

@ -25,14 +25,14 @@ class NormalizerBaseTest extends UnitTestCase {
* The expected boolean return value from supportNormalization.
* @param mixed $data
* The data passed to supportsNormalization.
* @param string $supported_interface_or_class
* @param string $supported_types
* (optional) The supported interface or class to set on the normalizer.
*/
public function testSupportsNormalization($expected_return, $data, $supported_interface_or_class = NULL) {
public function testSupportsNormalization($expected_return, $data, $supported_types = NULL) {
$normalizer_base = $this->getMockForAbstractClass('Drupal\Tests\serialization\Unit\Normalizer\TestNormalizerBase');
if (isset($supported_interface_or_class)) {
$normalizer_base->setSupportedInterfaceOrClass($supported_interface_or_class);
if (isset($supported_types)) {
$normalizer_base->setSupportedTypes($supported_types);
}
$this->assertSame($expected_return, $normalizer_base->supportsNormalization($data));
@ -76,13 +76,13 @@ abstract class TestNormalizerBase extends NormalizerBase {
protected array $supportedTypes = ['*' => FALSE];
/**
* Sets the protected supportedInterfaceOrClass property.
* Sets the supported types.
*
* @param string $supported_interface_or_class
* @param string $supported_types
* The class name to set.
*/
public function setSupportedInterfaceOrClass($supported_interface_or_class) {
$this->supportedTypes = [$supported_interface_or_class => FALSE];
public function setSupportedTypes($supported_types): void {
$this->supportedTypes = [$supported_types => FALSE];
}
/**