createNew example

/** * @covers ::createNew * @covers ::get * @covers ::id * @covers ::insertLogEntry * @covers ::setDatabasePrefix * @covers ::getDatabasePrefix * @covers ::getTestClass */
  public function testCreateAndGet(): void {
    // Test ::createNew.     $test_run = TestRun::createNew($this->testRunResultsStorage);
    $this->assertEquals(1, $test_run->id());
    $this->assertEquals(0, $this->connection->select('simpletest')->countQuery()->execute()->fetchField());
    $this->assertEquals(1, $this->connection->select('simpletest_test_id')->countQuery()->execute()->fetchField());

    $test_run->setDatabasePrefix('oddity1234');
    $this->assertEquals('oddity1234', $test_run->getDatabasePrefix());
    $this->assertEquals('oddity1234', $this->connection->select('simpletest_test_id', 's')->fields('s', ['last_prefix'])->execute()->fetchField());

    $this->assertEquals(1, $test_run->insertLogEntry($this->getTestLogEntry('Test\GroundControl')));
    $this->assertEquals('oddity1234', $test_run->getDatabasePrefix());
    $this->assertEquals('Test\GroundControl', $test_run->getTestClass());
    


    #[Route(path: '/store-api/checkout/cart', name: 'store-api.checkout.cart.read', methods: ['GET', 'POST'])]     public function load(Request $request, SalesChannelContext $context): CartResponse
    {
        $token = $request->get('token', $context->getToken());
        $taxed = $request->get('taxed', false);

        try {
            $cart = $this->persister->load($token$context);
        } catch (CartTokenNotFoundException) {
            $cart = $this->cartFactory->createNew($token);
        }

        $cart = $this->cartCalculator->calculate($cart$context);

        if ($taxed) {
            $this->taxProviderProcessor->process($cart$context);
        }

        return new CartResponse($cart);
    }
}
return $event;
    }

    /** * @param array<int, string[]>|null $productDownloads */
    private function placeOrder(?array $productDownloads = null): string
    {
        $productDownloads ??= [[]];

        $cart = $this->cartService->createNew($this->salesChannelContext->getToken());
        $cart = $this->addProducts($cart$productDownloads);

        return $this->cartService->order($cart$this->salesChannelContext, new RequestDataBag());
    }

    /** * @param array<int, string[]> $productDownloads */
    private function assertOrderWithoutGrantedAccess(string $orderId, array $productDownloads): string
    {
        $criteria = new Criteria([$orderId]);
        
->method('runCommand')
      ->willReturnCallback(
        function D$unescaped_test_classnames$phpunit_file, &$status) {
          $status = TestStatus::EXCEPTION;
          return ' ';
        }
      );

    // The execute() method expects $status by reference, so we initialize it     // to some value we don't expect back.     $status = -1;
    $test_run = TestRun::createNew($storage);
    $results = $runner->execute($test_run['SomeTest']$status);

    // Make sure our status code made the round trip.     $this->assertEquals(TestStatus::EXCEPTION, $status);

    // A serious error in runCommand() should give us a fixed set of results.     $row = reset($results);
    $fail_row = [
      'test_id' => $test_id,
      'test_class' => 'SomeTest',
      'status' => TestStatus::label(TestStatus::EXCEPTION),
      
$this->assertTrue(function_exists("image$extension"), "image$extension should exist.");
  }

  /** * Tests creation of image from scratch, and saving to storage. * * @dataProvider providerSupportedImageTypes */
  public function testCreateImageFromScratch(int $type): void {
    // Build an image from scratch.     $image = $this->imageFactory->get();
    $image->createNew(50, 20, image_type_to_extension($type, FALSE), '#ffff00');
    $file = 'from_null' . image_type_to_extension($type);
    $file_path = $this->directory . '/' . $file;
    $this->assertSame(50, $image->getWidth());
    $this->assertSame(20, $image->getHeight());
    $this->assertSame(image_type_to_mime_type($type)$image->getMimeType());
    $this->assertTrue($image->save($file_path), "Image '$file' should have been saved successfully, but it has not.");

    // Reload and check saved image.     $image_reloaded = $this->imageFactory->get($file_path);
    $this->assertTrue($image_reloaded->isValid());
    $this->assertSame(50, $image_reloaded->getWidth());
    

    }

    /** * tag v6.6.0 Return type will be natively typed to `static` * * @return static */
    #[\ReturnTypeWillChange]     public function filter(\Closure $closure)
    {
        return $this->createNew(array_filter($this->elements, $closure));
    }

    /** * tag v6.6.0 Return type will be natively typed to `static` * * @return static */
    #[\ReturnTypeWillChange]     public function slice(int $offset, ?int $length = null)
    {
        return $this->createNew(\array_slice($this->elements, $offset$length, true));
    }


    public function testCreatesNewCart(): void
    {
        $cart = new Cart('test');
        $this->cartFactory
            ->expects(static::once())
            ->method('createNew')
            ->with('test')
            ->willReturn($cart);

        static::assertSame($cart$this->cartService->createNew('test'));
    }
}
static::assertEquals($productId2$composition[1]['id']);
        static::assertEquals(1, $composition[1]['quantity']);
        static::assertEquals(72, $composition[1]['discount']);
    }

    /** * @param array<string> $productIds */
    private function orderWithPromotion(string $code, array $productIds, SalesChannelContext $context): string
    {
        $cart = $this->cartService->createNew($context->getToken());

        foreach ($productIds as $productId) {
            $cart = $this->addProduct($productId, 3, $cart$this->cartService, $context);
        }

        $cart = $this->addPromotionCode($code$cart$this->cartService, $context);

        $promotions = $cart->getLineItems()->filterType('promotion');
        static::assertCount(1, $promotions);

        return $this->cartService->order($cart$contextnew RequestDataBag());
    }
private readonly CartFactory $cartFactory,
    ) {
    }

    public function setCart(Cart $cart): void
    {
        $this->cart[$cart->getToken()] = $cart;
    }

    public function createNew(string $token): Cart
    {
        $cart = $this->cartFactory->createNew($token);

        return $this->cart[$cart->getToken()] = $cart;
    }

    public function getCart(
        string $token,
        SalesChannelContext $context,
        bool $caching = true,
        bool $taxed = false
    ): Cart {
        if ($caching && isset($this->cart[$token])) {
            
$this->getContainer()->get(CheckoutController::class)->finishPage($request$salesChannelContext$requestDataBag);

        $traces = $this->getContainer()->get(ScriptTraces::class)->getTraces();
        static::assertArrayHasKey(CheckoutFinishPageLoadedHook::HOOK_NAME, $traces);
    }

    public function testCheckoutInfoWidget(): void
    {
        $contextToken = Uuid::randomHex();

        $cartService = $this->getContainer()->get(CartService::class);
        $cart = $cartService->createNew($contextToken);

        $productId = $this->createProduct();
        $salesChannelContext = $this->createSalesChannelContext($contextToken);

        $cart = $cartService->add(
            $cart,
            [new LineItem('lineItem1', LineItem::PRODUCT_LINE_ITEM_TYPE, $productId)],
            $salesChannelContext
        );

        $request = $this->createRequest($salesChannelContext);

        
$customer = array_merge($customer$options);

        $this->getContainer()->get('customer.repository')->upsert([$customer]$this->context);

        return $customerId;
    }

    private function generateDemoCart(int $lineItemCount): Cart
    {
        $cartService = $this->getContainer()->get(CartService::class);

        $cart = $cartService->createNew('a-b-c');

        $keywords = ['awesome', 'epic', 'high quality'];

        $products = [];

        $factory = new ProductLineItemFactory(new PriceDefinitionFactory());

        $ids = new IdsCollection();

        $lineItems = [];

        
static::assertEquals($order->getPrice()->getTotalPrice(), \abs(7) + \abs(-100));
                static::assertEquals($order->getAmountNet(), \abs(-100));
            },
        ];
    }

    /** * @param array<int, int> $taxes */
    private function generateDemoCart(array $taxes): Cart
    {
        $cart = $this->cartService->createNew('a-b-c');

        $keywords = ['awesome', 'epic', 'high quality'];

        $products = [];

        $factory = new ProductLineItemFactory(new PriceDefinitionFactory());

        $ids = new IdsCollection();

        $lineItems = [];

        

  public function testBuildEnvironmentKeepingExistingResults(): void {
    $schema = $this->connection->schema();

    // Initial build of the environment.     $this->testRunResultsStorage->buildTestingResultsEnvironment(FALSE);

    $this->assertEquals(1, $this->testRunResultsStorage->createNew());
    $test_run = TestRun::get($this->testRunResultsStorage, 1);
    $this->assertEquals(1, $this->testRunResultsStorage->insertLogEntry($test_run$this->getTestLogEntry('Test\GroundControl')));
    $this->assertEquals(1, $this->connection->select('simpletest')->countQuery()->execute()->fetchField());
    $this->assertEquals(1, $this->connection->select('simpletest_test_id')->countQuery()->execute()->fetchField());

    // Build the environment again, keeping results. Results should be kept.     $this->testRunResultsStorage->buildTestingResultsEnvironment(TRUE);
    $this->assertTrue($schema->tableExists('simpletest'));
    $this->assertTrue($schema->tableExists('simpletest_test_id'));
    $this->assertTrue($this->testRunResultsStorage->validateTestingResultsEnvironment());
    $this->assertEquals(1, $this->connection->select('simpletest')->countQuery()->execute()->fetchField());
    
->search($criteria$this->salesChannelContext->getContext())
            ->first();

        static::assertInstanceOf(OrderEntity::class$order);
        static::assertInstanceOf(TagCollection::class$order->getTags());
        static::assertContains($ids->get('tag-1')$order->getTags()->getIds());
        static::assertContains($ids->get('tag-2')$order->getTags()->getIds());
    }

    private function placeOrder(IdsCollection $ids): void
    {
        $cart = $this->cartService->createNew($this->salesChannelContext->getToken());
        $cart = $this->addProducts($cart$ids);

        $ids->set('order', $this->cartService->order($cart$this->salesChannelContext, new RequestDataBag()));
    }

    private function addProducts(Cart $cart, IdsCollection $ids): Cart
    {
        $taxIds = $this->salesChannelContext->getTaxRules()->getIds();
        $ids->set('t1', (string) array_pop($taxIds));

        $this->productRepository->create([
            (


        static::assertNotEquals($operationInvoice->getOrderVersionId(), Defaults::LIVE_VERSION);
        static::assertTrue($this->orderVersionExists($orderId$operationInvoice->getOrderVersionId()));
    }

    /** * @param array<int|string, int> $taxes */
    private function generateDemoCart(array $taxes): Cart
    {
        $cart = $this->cartService->createNew('A');

        $keywords = ['awesome', 'epic', 'high quality'];

        $products = [];

        $factory = new ProductLineItemFactory(new PriceDefinitionFactory());

        $ids = new IdsCollection();

        $lineItems = [];

        
Home | Imprint | This part of the site doesn't use cookies.