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/SBogers95/rentman.io/app/Komma/Shop/Tests/Benchmark/ShoppingCartBenchmark.php
<?php

namespace Tests\Benchmark;

use App\Komma\QualityAssurance\BaseBenchMark;
use App\Komma\Shop\Cart\ShoppingCartService;
use App\Komma\Shop\Categories\Models\Category;
use App\Komma\Shop\Factories\Fakers\ProductNamesFaker;
use App\Komma\Shop\Products\Product\Product;
use App\Komma\Shop\Products\Product\Transfer\ProductColumnMapsTrait;
use App\Komma\Shop\Products\ProductComposite\ProductComposite;
use App\Komma\Shop\Products\ProductGroup\ProductGroup;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithFaker;

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

    /**
     * @var ShoppingCartService
     */
    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();
        $this->faker->addProvider(ProductNamesFaker::class);
    }

    /*
    |--------------------------------------------------------------------------
    | 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 = new ShoppingCartService();

        $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 = new ShoppingCartService();

        $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 = new ShoppingCartService();

        $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' => '',
            'product_documents-data' => '',
            '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),
        ];
    }
}