You are here

public function ComplexDataNormalizerTest::testNormalizeNonComplex in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/serialization/tests/src/Unit/Normalizer/ComplexDataNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ComplexDataNormalizerTest::testNormalizeNonComplex()
  2. 10 core/modules/serialization/tests/src/Unit/Normalizer/ComplexDataNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ComplexDataNormalizerTest::testNormalizeNonComplex()

Test 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
Contains \Drupal\Tests\serialization\Unit\Normalizer\ComplexDataNormalizerTest.

Class

ComplexDataNormalizerTest
@coversDefaultClass \Drupal\serialization\Normalizer\ComplexDataNormalizer @group serialization

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

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);
}