TestDenormalizer example

public function testNormalizeGivesPriorityToInterfaceOverTraversable()
    {
        $serializer = new Serializer([new CustomNormalizer()]['json' => new JsonEncoder()]);
        $result = $serializer->serialize(new NormalizableTraversableDummy(), 'json');
        $this->assertEquals('{"foo":"normalizedFoo","bar":"normalizedBar"}', $result);
    }

    public function testNormalizeOnDenormalizer()
    {
        $this->expectException(UnexpectedValueException::class);
        $serializer = new Serializer([new TestDenormalizer()][]);
        $this->assertTrue($serializer->normalize(new \stdClass(), 'json'));
    }

    public function testDenormalizeNoMatch()
    {
        $this->expectException(UnexpectedValueException::class);
        $serializer = new Serializer([$this->createMock(CustomNormalizer::class)]);
        $serializer->denormalize('foo', 'stdClass');
    }

    public function testDenormalizeOnObjectThatOnlySupportsDenormalization()
    {
Home | Imprint | This part of the site doesn't use cookies.