OrderEntity example

static::assertEquals('cc', $flow->getData(MailAware::MAIL_STRUCT)->getCc());
    }

    public function testRestoreHasDataOrder(): void
    {
        $flow = new StorableFlow('test', Context::createDefaultContext()[OrderAware::ORDER_ID => Uuid::randomHex()]);
        $customer = new OrderCustomerEntity();
        $customer->setId(Uuid::randomHex());
        $customer->setFirstName('bar');
        $customer->setLastName('foo');
        $customer->setEmail('foo@bar.com');
        $order = new OrderEntity();
        $order->setOrderCustomer($customer);
        $order->setSalesChannelId(TestDefaults::SALES_CHANNEL);
        $flow->setData(OrderAware::ORDER, $order);

        $this->storer->restore($flow);

        static::assertTrue($flow->hasData(MailAware::MAIL_STRUCT));

        static::assertInstanceOf(MailRecipientStruct::class$flow->getData(MailAware::MAIL_STRUCT));
        static::assertEquals('barfoo', $flow->getData(MailAware::MAIL_STRUCT)->getRecipients()['foo@bar.com']);
        static::assertNull($flow->getData(MailAware::MAIL_STRUCT)->getBcc());
        
static::assertEquals(RuleConstraints::uuids()$constraints['stateIds']);
        static::assertEquals(RuleConstraints::uuidOperators(false)$constraints['operator']);
    }

    /** * @dataProvider getMatchingValues * * @param list<string> $selectedOrderStateIds */
    public function testOrderDeliveryStatusRuleMatching(bool $expected, string $orderStateId, array $selectedOrderStateIds, string $operator): void
    {
        $order = new OrderEntity();
        $order->setStateId($orderStateId);

        $cart = $this->createMock(Cart::class);
        $context = $this->createMock(SalesChannelContext::class);
        $scope = new FlowRuleScope($order$cart$context);

        $this->rule->assign(['stateIds' => $selectedOrderStateIds, 'operator' => $operator]);
        static::assertSame($expected$this->rule->match($scope));
    }

    public function testInvalidScopeIsFalse(): void
    {
$flow->setConfig(['value' => $value]);

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

        static::assertEquals($expectedPayload$this->updatePayload);
    }

    public static function orderProvider(): \Generator
    {
        yield 'no order found' => [null, []];

        $order = new OrderEntity();

        yield 'order without line items' => [$order[]];

        $order = new OrderEntity();

        $lineItem = new OrderLineItemEntity();
        $lineItem->setGood(true);
        $lineItem->setId(Uuid::randomHex());

        $order->setLineItems(new OrderLineItemCollection([$lineItem]));

        
/** * @covers \Shopware\Core\Framework\App\Payment\Payload\Struct\RecurringPayPayload * * @internal */
#[Package('checkout')] class RecurringPayPayloadTest extends TestCase
{
    public function testPayload(): void
    {
        $transaction = new OrderTransactionEntity();
        $order = new OrderEntity();
        $requestData = ['foo' => 'bar'];
        $recurring = new RecurringDataStruct('foo', new \DateTime());
        $source = new Source('foo', 'bar', '1.0.0');

        $payload = new RecurringPayPayload($transaction$order$requestData$recurring);
        $payload->setSource($source);

        static::assertEquals($transaction$payload->getOrderTransaction());
        static::assertSame($order$payload->getOrder());
        static::assertSame($requestData$payload->getRequestData());
        static::assertSame($recurring$payload->getRecurring());
        
$scope = $this->createMock(CheckoutRuleScope::class);
        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $orderCollection = new OrderCollection();
        $customer = new CustomerEntity();
        $customer->setReviewCount($reviewCount ?? 0);

        if ($noCustomer) {
            $customer = null;
        }

        $salesChannelContext->method('getCustomer')->willReturn($customer);
        $entity = new OrderEntity();
        $entity->setUniqueIdentifier('test');
        $orderCollection->add($entity);

        $scope->method('getSalesChannelContext')
            ->willReturn($salesChannelContext);

        static::assertSame($isMatching$rule->match($scope));
    }

    /** * @return \Traversable<string, array<string|bool|int>> */

class FlowFactoryTest extends TestCase
{
    public function testCreate(): void
    {
        $ids = new TestDataCollection();
        $order = new OrderEntity();
        $order->setId($ids->get('orderId'));

        $awareEvent = new CheckoutOrderPlacedEvent(Context::createDefaultContext(new AdminApiSource('test'))$order, TestDefaults::SALES_CHANNEL);
        $orderStorer = new OrderStorer($this->createMock(EntityRepository::class)$this->createMock(EventDispatcherInterface::class));
        $flowFactory = new FlowFactory([$orderStorer]);
        $flow = $flowFactory->create($awareEvent);

        static::assertEquals($ids->get('orderId')$flow->getStore('orderId'));
        static::assertInstanceOf(SystemSource::class$flow->getContext()->getSource());
        static::assertEquals(Context::SYSTEM_SCOPE, $flow->getContext()->getScope());
    }

    
/** * @covers \Shopware\Core\Framework\App\Payment\Payload\Struct\SyncPayPayload * * @internal */
#[Package('checkout')] class SyncPayPayloadTest extends TestCase
{
    public function testPayload(): void
    {
        $transaction = new OrderTransactionEntity();
        $order = new OrderEntity();
        $requestData = ['foo' => 'bar'];
        $recurring = new RecurringDataStruct('foo', new \DateTime());
        $source = new Source('foo', 'bar', '1.0.0');

        $payload = new SyncPayPayload($transaction$order$requestData$recurring);
        $payload->setSource($source);

        static::assertEquals($transaction$payload->getOrderTransaction());
        static::assertSame($order$payload->getOrder());
        static::assertSame($requestData$payload->getRequestData());
        static::assertSame($recurring$payload->getRecurring());
        
$stateMachineStateFailed->setTechnicalName('failed');
        $orderTransactionFailed->setStateMachineState($stateMachineStateFailed);

        $orderTransactionCollection->add($orderTransactionCancelled);
        $orderTransactionCollection->add($orderTransaction);
        $orderTransactionCollection->add($orderTransactionFailed);

        // Cart price         $cartPrice = new CartPrice(19.5, 19.5, 19.5, new CalculatedTaxCollection()new TaxRuleCollection(), CartPrice::TAX_STATE_FREE);

        // Order entity         $order = new OrderEntity();
        $order->setPrice($cartPrice);
        $order->setId(Uuid::randomHex());
        $order->setBillingAddressId('order-address-id');
        $order->setCurrencyId('order-currency-id');
        $order->setLanguageId('order-language-id');
        $order->setSalesChannelId(TestDefaults::SALES_CHANNEL);
        $order->setTotalRounding($this->cashRoundingConfig);
        $order->setItemRounding($this->cashRoundingConfig);
        $order->setRuleIds(['order-rule-id-1', 'order-rule-id-2']);
        $order->setTaxStatus(CartPrice::TAX_STATE_FREE);

        


        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getCustomer')
            ->willReturn($customer);

        return $context;
    }

    private function getOrderRouteWithValidOrder(string $orderId, ?CashRoundingConfig $itemRounding = null, ?CashRoundingConfig $totalRounding = null): OrderRoute
    {
        $order = new OrderEntity();
        $order->setId($orderId);

        if ($itemRounding instanceof CashRoundingConfig) {
            $order->setItemRounding($itemRounding);
        }

        if ($totalRounding instanceof CashRoundingConfig) {
            $order->setTotalRounding($totalRounding);
        }

        $searchResult = new EntitySearchResult(
            
public function testGetDecoratedShouldThrowException(): void
    {
        static::expectException(DecorationPatternException::class);
        $this->searchIndexer->getDecorated();
    }

    public function testGlobalData(): void
    {
        $context = Context::createDefaultContext();
        $repository = $this->createMock(EntityRepository::class);
        $order = new OrderEntity();
        $order->setUniqueIdentifier(Uuid::randomHex());
        $repository->method('search')->willReturn(
            new EntitySearchResult(
                'order',
                1,
                new EntityCollection([$order]),
                null,
                new Criteria(),
                $context
            )
        );

        
Generator::createSalesChannelContext()
        );
    }

    public function testThrowsExceptionOnNullPaymentHandler(): void
    {
        $transaction = new OrderTransactionEntity();
        $transaction->setId(Uuid::randomHex());
        $transaction->setStateId($this->ids->get('order-state'));
        $transaction->setPaymentMethodId($this->ids->get('payment'));

        $order = new OrderEntity();
        $order->setUniqueIdentifier($this->ids->get('test-order'));
        $order->setTransactions(new OrderTransactionCollection([$transaction]));

        $orderRepository = $this->createMock(EntityRepository::class);
        $orderRepository
            ->method('search')
            ->willReturn(
                new EntitySearchResult(
                    'order',
                    1,
                    new EntityCollection([$order]),
                    
static::assertEquals([new NotBlank()new Choice($operators)]$constraints['operator']);
    }

    /** * @dataProvider getMatchValues * * @param array<string>|string|null $givenIdentifier * @param array<string> $ruleIdentifiers */
    public function testRuleMatching(string $operator, bool $isMatching, array $ruleIdentifiers$givenIdentifier): void
    {
        $order = new OrderEntity();
        $tagCollection = new TagCollection();
        $orderTagIds = array_filter(\is_array($givenIdentifier) ? $givenIdentifier : [$givenIdentifier]);
        foreach ($orderTagIds as $orderTagId) {
            $tag = new TagEntity();
            $tag->setId($orderTagId);
            $tagCollection->add($tag);
        }
        $order->setTags($tagCollection);

        $scope = $this->createScope($order);
        $this->rule->assign(['identifiers' => $ruleIdentifiers, 'operator' => $operator]);

        


    public function testBuild(): void
    {
        $mockContext = $this->createMock(SalesChannelContext::class);
        $cart = new Cart('test');
        $this->orderConverter->method('assembleSalesChannelContext')->willReturn($mockContext);
        $this->orderConverter->method('convertToCart')->willReturn($cart);
        $this->deliveryBuilder->method('build')->willReturn(new DeliveryCollection());
        $this->cartDataCollector->expects(static::exactly(2))->method('collect');

        $order = new OrderEntity();
        $order->setId(Uuid::randomHex());
        $expected = new FlowRuleScope($order$cart$mockContext);
        $context = Context::createDefaultContext();

        static::assertEquals($expected$this->scopeBuilder->build($order$context));
        static::assertEquals($expected$this->scopeBuilder->build($order$context));

        $this->scopeBuilder->reset();

        static::assertEquals($expected$this->scopeBuilder->build($order$context));
    }
}
static::assertEquals([new NotBlank()new ArrayOfUuid()]$constraints['documentIds']);
        static::assertEquals([new NotBlank()new Choice($operators)]$constraints['operator']);
    }

    /** * @dataProvider getMatchingValues * * @param list<string> $selectedDocumentIds */
    public function testOrderDocumentTypeRuleMatching(bool $expected, string|null $documentId, array $selectedDocumentIds, string $operator): void
    {
        $order = new OrderEntity();
        $collection = new DocumentCollection();

        if ($documentId) {
            $document = new DocumentEntity();
            $document->setId(Uuid::randomHex());
            $document->setDocumentTypeId($documentId);
            $collection->add($document);
        }

        $order->setDocuments($collection);
        $cart = Generator::createCart();
        
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);
        $appFlowActionProvider = $this->createMock(AppFlowActionProvider::class);
        $ruleLoader = $this->createMock(AbstractRuleLoader::class);
        $scopeBuilder = $this->createMock(FlowRuleScopeBuilder::class);

        $trueCaseSequence = new Sequence();
        $trueCaseSequence->assign(['sequenceId' => 'foobar']);
        $ruleId = Uuid::randomHex();
        $ifSequence = new IfSequence();
        $ifSequence->assign(['ruleId' => $ruleId, 'trueCase' => $trueCaseSequence]);

        $order = new OrderEntity();
        $tagId = Uuid::randomHex();
        $tag = new TagEntity();
        $tag->setId($tagId);
        $order->setTags(new TagCollection([$tag]));

        $flow = new StorableFlow('bar', Context::createDefaultContext());
        $flow->setFlowState(new FlowState());
        $flow->setData(OrderAware::ORDER, $order);

        $scopeBuilder->method('build')->willReturn(
            new FlowRuleScope($ordernew Cart('test')$this->createMock(SalesChannelContext::class))
        );
Home | Imprint | This part of the site doesn't use cookies.