function ComplexDataNormalizerTest::testNormalizeNonComplex
Tests normalize() where $object does not implement ComplexDataInterface.
Normalizers extending ComplexDataNormalizer may have a different supported class.
@covers ::normalize
      
    
File
- 
              core/modules/ serialization/ tests/ src/ Unit/ Normalizer/ ComplexDataNormalizerTest.php, line 90 
Class
- ComplexDataNormalizerTest
- @coversDefaultClass \Drupal\serialization\Normalizer\ComplexDataNormalizer[[api-linebreak]] @group serialization
Namespace
Drupal\Tests\serialization\Unit\NormalizerCode
public function testNormalizeNonComplex() {
  $normalizer = new TestExtendedNormalizer();
  $serialization_context = [
    'test' => 'test',
  ];
  $serializer_prophecy = $this->prophesize(Serializer::class);
  $serializer_prophecy->normalize('A', static::TEST_FORMAT, $serialization_context)
    ->willReturn('A-normalized')
    ->shouldBeCalled();
  $serializer_prophecy->normalize('B', static::TEST_FORMAT, $serialization_context)
    ->willReturn('B-normalized')
    ->shouldBeCalled();
  $normalizer->setSerializer($serializer_prophecy->reveal());
  $stdClass = new \stdClass();
  $stdClass->a = 'A';
  $stdClass->b = 'B';
  $normalized = $normalizer->normalize($stdClass, static::TEST_FORMAT, $serialization_context);
  $this->assertEquals([
    'a' => 'A-normalized',
    'b' => 'B-normalized',
  ], $normalized);
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
