diff --git a/core/modules/serialization/src/Normalizer/ListNormalizer.php b/core/modules/serialization/src/Normalizer/ListNormalizer.php index 94aca11349b..1729cfce849 100644 --- a/core/modules/serialization/src/Normalizer/ListNormalizer.php +++ b/core/modules/serialization/src/Normalizer/ListNormalizer.php @@ -26,7 +26,7 @@ class ListNormalizer extends NormalizerBase { public function normalize($object, $format = NULL, array $context = array()) { $attributes = array(); foreach ($object as $fieldItem) { - $attributes[] = $this->serializer->normalize($fieldItem, $format); + $attributes[] = $this->serializer->normalize($fieldItem, $format, $context); } return $attributes; } diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/ListNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/ListNormalizerTest.php index 170fd3ecd5a..bbc7c110309 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/ListNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/ListNormalizerTest.php @@ -7,6 +7,7 @@ use Drupal\Core\TypedData\TypedDataManagerInterface; use Drupal\Tests\UnitTestCase; use Drupal\serialization\Normalizer\ListNormalizer; use Drupal\Core\TypedData\Plugin\DataType\ItemList; +use Symfony\Component\Serializer\Serializer; /** * @coversDefaultClass \Drupal\serialization\Normalizer\ListNormalizer @@ -35,13 +36,20 @@ class ListNormalizerTest extends UnitTestCase { */ protected $expectedListValues = array('test', 'test', 'test'); + /** + * The mocked typed data. + * + * @var \PHPUnit_Framework_MockObject_MockObject|\Drupal\Core\TypedData\TypedDataInterface + */ + protected $typedData; + protected function setUp() { // Mock the TypedDataManager to return a TypedDataInterface mock. - $typed_data = $this->getMock('Drupal\Core\TypedData\TypedDataInterface'); + $this->typedData = $this->getMock('Drupal\Core\TypedData\TypedDataInterface'); $typed_data_manager = $this->getMock(TypedDataManagerInterface::class); $typed_data_manager->expects($this->any()) ->method('getPropertyInstance') - ->will($this->returnValue($typed_data)); + ->will($this->returnValue($this->typedData)); // Set up a mock container as ItemList() will call for the 'typed_data_manager' // service. @@ -73,16 +81,14 @@ class ListNormalizerTest extends UnitTestCase { * Tests the normalize() method. */ public function testNormalize() { - $serializer = $this->getMockBuilder('Symfony\Component\Serializer\Serializer') - ->setMethods(array('normalize')) - ->getMock(); - $serializer->expects($this->exactly(3)) - ->method('normalize') - ->will($this->returnValue('test')); + $serializer = $this->prophesize(Serializer::class); + $serializer->normalize($this->typedData, 'json', ['mu' => 'nu']) + ->shouldBeCalledTimes(3) + ->willReturn('test'); - $this->normalizer->setSerializer($serializer); + $this->normalizer->setSerializer($serializer->reveal()); - $normalized = $this->normalizer->normalize($this->list); + $normalized = $this->normalizer->normalize($this->list, 'json', ['mu' => 'nu']); $this->assertEquals($this->expectedListValues, $normalized); }