TestObject example


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

}

class TestObject {

  public function getA() {
    return 'A';
  }

}
Home | Imprint | This part of the site doesn't use cookies.