DateIntervalFieldSerializer example

public function testGetStorageName(): void
    {
        static::assertSame('name', $this->field->getStorageName());
    }

    public function testGetSerializerWillReturnFieldSerializerInterfaceInstance(): void
    {
        $registry = $this->createMock(DefinitionInstanceRegistry::class);
        $registry
            ->method('getSerializer')
            ->willReturn(
                new DateIntervalFieldSerializer(
                    $this->createMock(ValidatorInterface::class),
                    $registry
                )
            );
        $registry->method('getResolver');
        $registry->method('getAccessorBuilder');
        $this->field->compile($registry);

        static::assertInstanceOf(DateIntervalFieldSerializer::class$this->field->getSerializer());
    }
}
private DefinitionInstanceRegistry&MockObject $definitionInstanceRegistry;

    private ValidatorInterface&MockObject $validator;

    private DateIntervalFieldSerializer $dateIntervalFieldSerializer;

    protected function setUp(): void
    {
        $this->definitionInstanceRegistry = $this->createMock(DefinitionInstanceRegistry::class);
        $this->validator = $this->createMock(ValidatorInterface::class);

        $this->dateIntervalFieldSerializer = new DateIntervalFieldSerializer(
            $this->validator,
            $this->definitionInstanceRegistry
        );
    }

    public function testEncodeMethodWithCorrectDataWillReturnDateIntervalString(): void
    {
        $data = new KeyValuePair('key', new \DateInterval('P2Y5D'), false);

        $iterator = $this->dateIntervalFieldSerializer->encode(
            new DateIntervalField('fake', 'fake'),
            
Home | Imprint | This part of the site doesn't use cookies.