getData example


    public function mapFormsToData(\Traversable $checkboxes, mixed &$choices)
    {
        if (!\is_array($choices)) {
            throw new UnexpectedTypeException($choices, 'array');
        }

        $values = [];

        foreach ($checkboxes as $checkbox) {
            if ($checkbox->getData()) {
                // construct an array of choice values                 $values[] = $checkbox->getConfig()->getOption('value');
            }
        }

        $choices = $values;
    }
}
$ruleScope = $this->getMockForAbstractClass(RuleScope::class);
        $ruleScope->method('getSalesChannelContext')->willReturn($salesChannelContextMock);

        static::assertTrue($rule->match($ruleScope));
    }

    public function testGetDefaultConfig(): void
    {
        $rule = new PaymentMethodRule();

        $config = $rule->getConfig()->getData();
        static::assertSame([
            'operatorSet' => [
                'operators' => [
                    Rule::OPERATOR_EQ,
                    Rule::OPERATOR_NEQ,
                ],
                'isMatchAny' => true,
            ],
            'fields' => [
                [
                    'name' => 'paymentMethodIds',
                    
false, false],
        ];
    }

    abstract protected function getData(array $data);

    /** * @dataProvider getBooleanMatrix1 */
    public function testAddExtraEntriesIfAllowAdd($allowDelete)
    {
        $originalData = $this->getData([1 => 'second']);
        $newData = $this->getData([0 => 'first', 1 => 'second', 2 => 'third']);

        $listener = new MergeCollectionListener(true, $allowDelete);

        $this->form->setData($originalData);

        $event = new FormEvent($this->form, $newData);
        $listener->onSubmit($event);

        // The original object was modified         if (\is_object($originalData)) {
            
return [
            FormEvents::SUBMIT => 'onSubmit',
        ];
    }

    /** * @return void */
    public function onSubmit(FormEvent $event)
    {
        $dataToMergeInto = $event->getForm()->getNormData();
        $data = $event->getData() ?? [];

        if (!\is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
            throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)');
        }

        if (null !== $dataToMergeInto && !\is_array($dataToMergeInto) && !($dataToMergeInto instanceof \Traversable && $dataToMergeInto instanceof \ArrayAccess)) {
            throw new UnexpectedTypeException($dataToMergeInto, 'array or (\Traversable and \ArrayAccess)');
        }

        // If we are not allowed to change anything, return immediately         if ($data === $dataToMergeInto || (!$this->allowAdd && !$this->allowDelete)) {
            


    public function testLazyLoadEntity(): void
    {
        $storable = new StorableFlow('name', Context::createDefaultContext()['customerId' => 'id'][]);
        $this->storer->restore($storable);
        $entity = new CustomerEntity();
        $result = $this->createMock(EntitySearchResult::class);
        $result->expects(static::once())->method('get')->willReturn($entity);

        $this->repository->expects(static::once())->method('search')->willReturn($result);
        $res = $storable->getData('customer');

        static::assertEquals($res$entity);
    }

    public function testLazyLoadNullEntity(): void
    {
        $storable = new StorableFlow('name', Context::createDefaultContext()['customerId' => 'id'][]);
        $this->storer->restore($storable);
        $entity = null;
        $result = $this->createMock(EntitySearchResult::class);
        $result->expects(static::once())->method('get')->willReturn($entity);

        

    public function testActionExecuted(array $config, array $expected): void
    {
        $this->flow->expects(static::exactly(2))->method('getData')->willReturn(Uuid::randomHex());
        $this->flow->expects(static::once())->method('hasData')->willReturn(true);
        $this->flow->expects(static::once())->method('getConfig')->willReturn($config);

        $orderId = $this->flow->getData(OrderAware::ORDER_ID);
        $withData = array_map(fn ($id) => [
            'orderId' => $orderId,
            'tagId' => $id['id'],
        ]$expected);

        $this->repository->expects(static::once())
            ->method('delete')
            ->with($withData);

        $this->action->handleFlow($this->flow);
    }

    


    public function testSubmitNullUsesDefaultEmptyData($emptyData = '10.00', $expectedData = 10.0)
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'empty_data' => $emptyData,
        ]);
        $form->submit(null);

        $this->assertSame($emptyData$form->getViewData());
        $this->assertSame($expectedData$form->getNormData());
        $this->assertSame($expectedData$form->getData());
    }

    public function testDefaultFormattingWithDefaultRounding()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, ['scale' => 0]);
        $form->setData('12345.54321');

        $this->assertSame('12346', $form->createView()->vars['value']);
    }

    public function testDefaultFormattingWithSpecifiedRounding()
    {
$this->assertTrue($form->isValid());
    }

    public function testSubmitForwardsNullIfNotClearMissingButValueIsExplicitlyNull()
    {
        $child = $this->createForm('firstName', false);

        $this->form->add($child);

        $this->form->submit(['firstName' => null], false);

        $this->assertNull($this->form->get('firstName')->getData());
    }

    public function testSubmitForwardsNullIfValueIsMissing()
    {
        $child = $this->createForm('firstName', false);

        $this->form->add($child);

        $this->form->submit([]);

        $this->assertNull($this->form->get('firstName')->getData());
    }

        $view = new FixedDataTransformer([
            'foo' => 'bar',
        ]);

        $config = new FormConfigBuilder('name', null, new EventDispatcher());
        $config->addViewTransformer($view);
        $config->addModelTransformer($model);
        $config->setData('default');
        $form = new Form($config);

        $this->assertSame('default', $form->getData());
        $this->assertSame('foo', $form->getNormData());
        $this->assertSame('bar', $form->getViewData());
    }

    public function testDataTransformationFailure()
    {
        $this->expectException(TransformationFailedException::class);
        $this->expectExceptionMessage('Unable to transform data for property path "name": No mapping for value "arg"');
        $model = new FixedDataTransformer([
            'default' => 'foo',
        ]);
        
public function testInvalidScopeIsFalse(): void
    {
        $scope = $this->createMock(TestRuleScope::class);
        $this->rule->assign(['methodIds' => [Uuid::randomHex()], 'operator' => Rule::OPERATOR_EQ]);
        static::assertFalse($this->rule->match($scope));
    }

    public function testConfig(): void
    {
        $config = (new CustomerDefaultPaymentMethodRule())->getConfig();
        $configData = $config->getData();

        static::assertArrayHasKey('operatorSet', $configData);
        $operators = RuleConfig::OPERATOR_SET_STRING;

        static::assertEquals([
            'operators' => $operators,
            'isMatchAny' => true,
        ]$configData['operatorSet']);
    }

    /** * @return array<string, array{boolean, string, list<string>, string}> */
public function match(TaxRuleEntity $taxRuleEntity, ?CustomerEntity $customer, ShippingLocation $shippingLocation): bool
    {
        if ($taxRuleEntity->getType()->getTechnicalName() !== self::TECHNICAL_NAME
            || !$this->metPreconditions($taxRuleEntity$shippingLocation)
        ) {
            return false;
        }

        $zipCode = $this->getZipCode($shippingLocation);

        $toZipCode = $taxRuleEntity->getData()['toZipCode'];
        $fromZipCode = $taxRuleEntity->getData()['fromZipCode'];

        if ($fromZipCode === null || $toZipCode === null || $zipCode < $fromZipCode || $zipCode > $toZipCode) {
            return false;
        }

        if ($taxRuleEntity->getActiveFrom() !== null) {
            return $this->isTaxActive($taxRuleEntity);
        }

        return true;
    }
'isMatchAny' => true,
            ],
            'fields' => [
                [
                    'name' => 'identifiers',
                    'type' => 'multi-entity-id-select',
                    'config' => [
                        'entity' => 'promotion',
                    ],
                ],
            ],
        ]$config->getData());
    }

    public function testMatchesInCheckoutRuleScope(): void
    {
        $equalsRule = new PromotionLineItemRule(Rule::OPERATOR_EQ, ['id']);
        static::assertFalse($equalsRule->match(new CheckoutRuleScope($this->createMock(SalesChannelContext::class))));

        $notEqualsRule = new PromotionLineItemRule(Rule::OPERATOR_NEQ, ['id']);
        static::assertFalse($notEqualsRule->match(new CheckoutRuleScope($this->createMock(SalesChannelContext::class))));
    }

    
public function supports(Element $element)
    {
        return $element->getComponent()->getType() === self::COMPONENT_NAME;
    }

    public function prepare(PrepareDataCollection $collection, Element $element, ShopContextInterface $context)
    {
    }

    public function handle(ResolvedDataCollection $collection, Element $element, ShopContextInterface $context)
    {
        $data = array_merge($element->getConfig()->getAll()$element->getData()->getAll());
        $data['objectId'] = md5((string) $element->getId());

        foreach ($data as $key => $value) {
            $element->getData()->set($key$value);
        }
    }
}
try {
                $constraints = $rule->getConstraints();
                $config = $rule->getConfig();
            } catch (\Throwable) {
                continue;
            }

            if ($config === null) {
                continue;
            }

            $configData = $config->getData();
            $configOperators = $configData['operatorSet']['operators'] ?? null;

            if (empty($constraints['operator']) && empty($configOperators)) {
                continue;
            }

            if (empty($constraints['operator']) && !empty($configOperators)) {
                static::fail(sprintf(
                    'Missing constraints in condition %s for operator while config has operator set',
                    $rule->getName()
                ));
            }
return $this
      ->serializer
      ->denormalize($normalized$class$format$context);
  }

  /** * {@inheritdoc} */
  public function normalize($object$format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
    assert($object instanceof JsonApiDocumentTopLevel);
    $data = $object->getData();
    $document['jsonapi'] = CacheableNormalization::permanent([
      'version' => JsonApiSpec::SUPPORTED_SPECIFICATION_VERSION,
      'meta' => [
        'links' => [
          'self' => [
            'href' => JsonApiSpec::SUPPORTED_SPECIFICATION_PERMALINK,
          ],
        ],
      ],
    ]);
    if ($data instanceof ErrorCollection) {
      
Home | Imprint | This part of the site doesn't use cookies.