function XmlEncoderTest::testDefaultEncoderHasSerializer

Same name in other branches
  1. 8.9.x 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()
  3. 11.x 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 88

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();
    $serializer = new Serializer([
        new GetSetMethodNormalizer(),
    ]);
    $encoder->setSerializer($serializer);
    $base_encoder = $encoder->getBaseEncoder();
    $this->assertInstanceOf(BaseXmlEncoder::class, $base_encoder);
    // Test the encoder.
    $base_encoder->encode([
        'a' => new TestObject(),
    ], 'xml');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.