PriceSerializer example

static::assertSame('3123412344321', $this->first($fieldSerializer->serialize($config$intField, 3123412344321)));

        static::assertEmpty($fieldSerializer->deserialize($config$intField, ''));
        static::assertSame(0, $fieldSerializer->deserialize($config$intField, '0'));
        static::assertSame(3123412344321, $fieldSerializer->deserialize($config$intField, '3123412344321'));
    }

    public function testPriceField(): void
    {
        $priceField = new PriceField('price', 'price');

        $fieldSerializer = new PriceSerializer($this->getContainer()->get('currency.repository'));
        $config = new Config([][][]);

        static::assertNull($this->first($fieldSerializer->serialize($config$priceField[])));

        $value = [
            [
                'currencyId' => Defaults::CURRENCY,
                'gross' => 11,
                'net' => 10,
            ],
        ];

        
private EntityRepository $currencyRepository;

    protected function setUp(): void
    {
        $this->currencyRepository = $this->getContainer()->get(CurrencyDefinition::ENTITY_NAME . '.repository');
    }

    public function testSerializePrice(): void
    {
        $priceField = new PriceField('price', 'price');

        $priceSerializer = new PriceSerializer($this->currencyRepository);
        $config = new Config([][][]);

        $price = new Price(Defaults::CURRENCY, 10.0, 10.0, false);

        $expectedSerialized = [
            'EUR' => [
                'currencyId' => Defaults::CURRENCY,
                'extensions' => [],
                'gross' => 10.0,
                'linked' => false,
                'listPrice' => null,
                
Home | Imprint | This part of the site doesn't use cookies.