HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/tests/Benchmark/ShoppingCartBenchmark.php
<?php


namespace Tests\Benchmark;


use App\Cart\ShoppingCartInterface;
use Komma\KMS\QualityAssurance\BaseBenchMark;
use App\Cart\ShoppingCart;
use App\Categories\Models\Category;
use App\Products\Product\Product;
use App\Products\Product\Transfer\ProductColumnMapsTrait;
use App\Products\ProductComposite\ProductComposite;
use App\Products\ProductGroup\ProductGroup;
use App\Tests\Traits\WithFaker;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ShoppingCartBenchmark extends BaseBenchMark
{
    use WithFaker,
        DatabaseTransactions,
        ProductColumnMapsTrait;

    /**
     * @var ShoppingCartInterface $shoppingCart
     */
    private $shoppingCart;

    /*
    |--------------------------------------------------------------------------
    | Setup and teardown
    |--------------------------------------------------------------------------
    | We use setup and teardown methods to run respectively before and after
    | each benchmark. The time they take is not taken into account in the benchmark.
    |
    */
    /**
     * Setup the test environment before each benchmark
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();
    }


    /*
    |--------------------------------------------------------------------------
    | Benchmark subjects
    |--------------------------------------------------------------------------
    | The next methods are benchmark subjects. They test the performance of
    | a part of the application. Various measures will be done while they run.
    | The results of these measures are visible in console, or if configured in
    | XML and HTML files for example. Their names must start with the subject
    | pattern, defined in phpbench_config.json. Usually this means they must start with
    | the word "bench"
    |
    */

    /**
     * Benchmark how long it takes to put a product in the shoppingcart,
     * return a count, total with and without discounts and the product list.
     *
     * @Revs({1, 10})
     * @Iterations(1)
     * @Groups({"shoppingcart"})
     * @OutputTimeUnit("seconds")
     * @throws \Exception
     */
    public function benchShoppingCartAddProduct()
    {
        $this->shoppingCart = app(ShoppingCartInterface::class);

        $product = Product::inRandomOrder()->first();
        $this->shoppingCart->addProductable($product);
        $productCount = $this->shoppingCart->getItemsCount();
        $items = $this->shoppingCart->getItems();
        $total = $this->shoppingCart->getTotal();
        $totalWithoutDiscounts = $this->shoppingCart->getTotal(false);
    }

    /**
     * Benchmark how long it takes to put a product group in the shoppingcart,
     * return a count, total with and without discounts and the product list.
     *
     * @Revs({1, 10})
     * @Iterations(1)
     * @Groups({"shoppingcart"})
     * @OutputTimeUnit("seconds")
     * @throws \Exception
     */
    public function benchShoppingCartAddProductGroup()
    {
        $this->shoppingCart = app(ShoppingCartInterface::class);

        $group = ProductGroup::inRandomOrder()->first();
        $this->shoppingCart->addProductable($group);
        $productCount = $this->shoppingCart->getItemsCount();
        $items = $this->shoppingCart->getItems();
        $total = $this->shoppingCart->getTotal();
        $totalWithoutDiscounts = $this->shoppingCart->getTotal(false);
    }

    /**
     * Benchmark how long it takes to put a product composite in the shoppingcart,
     * return a count, total with and without discounts and the product list.
     *
     * @Revs({1, 10})
     * @Iterations(1)
     * @Groups({"shoppingcart"})
     * @OutputTimeUnit("seconds")
     * @throws \Exception
     */
    public function benchShoppingCartAddProductComposite()
    {
        $this->shoppingCart = app(ShoppingCartInterface::class);

        $composite = ProductComposite::inRandomOrder()->first();
        $this->shoppingCart->addProductable($composite);
        $productCount = $this->shoppingCart->getItemsCount();
        $items = $this->shoppingCart->getItems();
        $total = $this->shoppingCart->getTotal();
        $totalWithoutDiscounts = $this->shoppingCart->getTotal(false);
    }

    /*
    |--------------------------------------------------------------------------
    | Helper methods
    |--------------------------------------------------------------------------
    | The next methods provide useful services to other methods. They can,
    | for example provide the data for a benchmark subject.
    |
    */
    public function provideProductData()
    {
        $category = Category::inRandomOrder()->first();

        return [
            "category_id" => $category->id,
            "active" => $this->faker->boolean,
            "price" => $this->faker->randomNumber(4),
            "stock_keeping_unit" => $this->faker->ean13,
            "product_documents" => "",
            "quantity_price" => $this->faker->randomNumber(2),
            "quantity" => $this->faker->randomNumber(2),
            "name-en" => $this->faker->productName(),
            "name-de" => $this->faker->productName(),
            "name-nl" => $this->faker->productName(),
            "meta_description-en" => $this->faker->paragraph(1),
            "meta_description-de" => $this->faker->paragraph(1),
            "meta_description-nl" => $this->faker->paragraph(1),
            "description-en" => $this->faker->paragraph(3),
            "description-de" => $this->faker->paragraph(3),
            "description-nl" => $this->faker->paragraph(3),
        ];
    }
}