DateIntervalField example


#[Package('checkout')] class DateIntervalFieldTest extends TestCase
{
    private DateIntervalField $field;

    protected function setUp(): void
    {
        $this->field = new DateIntervalField('name', 'name');
    }

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

    public function testGetSerializerWillReturnFieldSerializerInterfaceInstance(): void
    {
        $registry = $this->createMock(DefinitionInstanceRegistry::class);
        $registry
            
$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'),
            $this->createStub(EntityExistence::class),
            $data,
            $this->createMock(WriteParameterBag::class)
        );

        $dateIntervalString = $iterator->current();

        \iterator_to_array($iterator);

        static::assertIsString($dateIntervalString);
        static::assertMatchesRegularExpression(self::REGEX_DATE_INTERVAL_VALIDATION, $dateIntervalString);
        
Home | Imprint | This part of the site doesn't use cookies.