You are here

public function XmlEncoderTest::testDefaultEncoderHasSerializer in Drupal 8

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

@covers ::getBaseEncoder

File

core/modules/serialization/tests/src/Unit/Encoder/XmlEncoderTest.php, line 85

Class

XmlEncoderTest
@coversDefaultClass \Drupal\serialization\Encoder\XmlEncoder @group serialization

Namespace

Drupal\Tests\serialization\Unit\Encoder

Code

public function testDefaultEncoderHasSerializer() {

  // The serializer should be set on the Drupal encoder, which should then
  // set it on our default encoder.
  $encoder = new XmlEncoder();
  $serialzer = new Serializer([
    new GetSetMethodNormalizer(),
  ]);
  $encoder
    ->setSerializer($serialzer);
  $base_encoder = $encoder
    ->getBaseEncoder();
  $this
    ->assertInstanceOf(BaseXmlEncoder::class, $base_encoder);

  // Test the encoder.
  $base_encoder
    ->encode([
    'a' => new TestObject(),
  ], 'xml');
}