CustomerEntity example

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

        $response = $this->controller->confirmPage(new Request()$context);

        static::assertEquals(new RedirectResponse('url')$response);
    }

    public function testConfirmPageEmptyCart(): void
    {
        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getCustomer')->willReturn(new CustomerEntity());

        $response = $this->controller->confirmPage(new Request()$context);

        static::assertEquals(new RedirectResponse('url')$response);
    }

    public function testConfirmPageWithCart(): void
    {
        $cart = new Cart(Uuid::randomHex());
        $cart->add(new LineItem(Uuid::randomHex(), LineItem::PRODUCT_LINE_ITEM_TYPE));
        $context = $this->createMock(SalesChannelContext::class);
        
$this->context = new SalesChannelContext(
            new Context(new SalesChannelApiSource(Uuid::randomHex())),
            Uuid::randomHex(),
            null,
            $salesChannel,
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(1, 1.1, true),
            new CashRoundingConfig(1, 1.1, true)
        );
        $this->response = new ProductSearchRouteResponse(
            new ProductEntity()
        );

        $this->cachedRoute = new CachedProductSearchRoute(
            $this->decorated,
            $this->cache,
            $this->createMock(EntityCacheKeyGenerator::class),
            
/** * @dataProvider getMatchValues */
    public function testRuleMatching(string $operator, bool $isMatching, ?int $orderCount, int $ruleOrderCount, bool $noCustomer = false): void
    {
        $rule = new OrderCountRule();
        $rule->assign(['count' => $ruleOrderCount, 'operator' => $operator]);

        $scope = $this->createMock(CheckoutRuleScope::class);
        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $orderCollection = new OrderCollection();
        $customer = new CustomerEntity();
        $customer->setOrderCount($orderCount ?? 0);

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

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

        
public function testCustomerNotLoggedInException(): void
    {
        static::expectException(CustomerException::class);
        static::expectExceptionMessage('Customer is not logged in.');

        $this->downloadRoute->load(new Request()$this->salesChannelContext);
    }

    public function testMissingRequestParameterException(): void
    {
        $this->salesChannelContext->method('getCustomer')->willReturn(new CustomerEntity());

        static::expectException(RoutingException::class);
        $this->downloadRoute->load(new Request()$this->salesChannelContext);
    }

    public function testDownloadNotExistingThrowsException(): void
    {
        $customer = new CustomerEntity();
        $customer->setId('foobar');
        $this->salesChannelContext->method('getCustomer')->willReturn($customer);

        
/** * @internal * * @covers \Shopware\Core\Checkout\Customer\Event\DoubleOptInGuestOrderEvent */
class DoubleOptInGuestOrderEventTest extends TestCase
{
    public function testScalarValuesCorrectly(): void
    {
        $event = new DoubleOptInGuestOrderEvent(
            new CustomerEntity(),
            $this->createMock(SalesChannelContext::class),
            'my-confirm-url'
        );

        $storer = new ScalarValuesStorer();

        $stored = $storer->store($event[]);

        $flow = new StorableFlow('foo', Context::createDefaultContext()$stored);

        $storer->restore($flow);

        
$this->context = new SalesChannelContext(
            new Context(new SalesChannelApiSource(Uuid::randomHex())),
            Uuid::randomHex(),
            null,
            $salesChannel,
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(1, 1.1, true),
            new CashRoundingConfig(1, 1.1, true)
        );
        $this->response = new CountryStateRouteResponse(
            new EntitySearchResult(
                'entity',
                1,
                new CountryStateCollection(),
                null,
                new Criteria(),
                Context::createDefaultContext()
            )
public function testAccountType(): void
    {
        $systemConfigService = new StaticSystemConfigService([
            TestDefaults::SALES_CHANNEL => [
                'core.loginRegistration.showAccountTypeSelection' => true,
                'core.loginRegistration.passwordMinLength' => '8',
            ],
            'core.systemWideLoginRegistration.isCustomerBoundToSalesChannel' => true,
        ]);

        $result = $this->createMock(EntitySearchResult::class);
        $customerEntity = new CustomerEntity();
        $customerEntity->setDoubleOptInRegistration(false);
        $customerEntity->setId('customer-1');
        $customerEntity->setGuest(false);
        $result->method('first')->willReturn($customerEntity);

        $customerRepository = $this->createMock(EntityRepository::class);
        $customerRepository->method('search')->willReturn($result);
        $customerRepository
            ->expects(static::once())
            ->method('create')
            ->willReturnCallback(function Darray $create) {
                
$this->context = new SalesChannelContext(
            new Context(new SalesChannelApiSource(Uuid::randomHex())),
            Uuid::randomHex(),
            null,
            $salesChannel,
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(1, 1.1, true),
            new CashRoundingConfig(1, 1.1, true)
        );
        $this->response = new SitemapRouteResponse(
            new SitemapCollection()
        );

        $this->cachedRoute = new CachedSitemapRoute(
            $this->decorated,
            $this->cache,
            $this->createMock(EntityCacheKeyGenerator::class),
            
return new SalesChannelContext(
            Context::createDefaultContext(),
            'foo',
            'bar',
            $salesChannelEntity,
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(2, 0.01, true),
            new CashRoundingConfig(2, 0.01, true),
            []
        );
    }

    private function getCmsPage(SalesChannelProductEntity $productEntity): CmsPageEntity
    {
        $cmsPageEntity = new CmsPageEntity();

        $cmsSectionEntity = new CmsSectionEntity();
        
$this->context = new SalesChannelContext(
            new Context(new SalesChannelApiSource(Uuid::randomHex())),
            Uuid::randomHex(),
            null,
            new SalesChannelEntity(),
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(1, 1.1, true),
            new CashRoundingConfig(1, 1.1, true)
        );

        $this->cachedRoute = new CachedSalutationRoute(
            $this->decorated,
            $this->cache,
            $this->createMock(EntityCacheKeyGenerator::class),
            $this->createMock(AbstractCacheTracer::class),
            $this->eventDispatcher,
            []
        );

#[Package('business-ops')] class CustomerNumberRuleTest extends TestCase
{
    public function testExactMatch(): void
    {
        $rule = (new CustomerNumberRule())->assign(['numbers' => ['NO. 1']]);

        $cart = new Cart('test');

        $customer = new CustomerEntity();
        $customer->setCustomerNumber('NO. 1');

        $context = $this->createMock(SalesChannelContext::class);

        $context
            ->method('getCustomer')
            ->willReturn($customer);

        static::assertTrue(
            $rule->match(new CartRuleScope($cart$context))
        );
    }
$salesChannelContext = $this->createMock(SalesChannelContext::class);
        $response = $this->controller->downloadFile($request$salesChannelContext);

        static::assertInstanceOf(RedirectResponse::class$response);
    }

    public function testLoggedInResponseReturn(): void
    {
        $this->downloadRouteMock->method('load')->willReturn(new Response());

        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $salesChannelContext->expects(static::once())->method('getCustomer')->willReturn(new CustomerEntity());
        $response = $this->controller->downloadFile(new Request()$salesChannelContext);

        static::assertInstanceOf(Response::class$response);
    }
}
return new SalesChannelContext(
            Context::createDefaultContext(),
            'foo',
            'bar',
            $salesChannelEntity,
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(2, 0.01, true),
            new CashRoundingConfig(2, 0.01, true),
            []
        );
    }
}
'enabled' => true,
                'currencyId' => Defaults::CURRENCY,
                'amount' => 0,
            ],
            'vatIdPattern' => '(DE)?[0-9]{9}',
        ];

        $countryRepository->update([$data], Context::createDefaultContext());
        $country = $countryRepository->search($criteria, Context::createDefaultContext())->getEntities()->first();
        static::assertNotNull($country);

        $customer = new CustomerEntity();
        $customer->setCompany('ABC Company');
        $customer->setVatIds(['DE123123123']);

        $context->expects(static::once())->method('getShippingLocation')->willReturn(
            ShippingLocation::createFromCountry($country)
        );

        $context->expects(static::once())->method('getCustomer')->willReturn(
            $customer
        );

        
return new SalesChannelContext(
            Context::createDefaultContext(),
            'foo',
            'bar',
            new SalesChannelEntity(),
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(2, 0.01, true),
            new CashRoundingConfig(2, 0.01, true)
        );
    }
}
Home | Imprint | This part of the site doesn't use cookies.