57 lines
1.9 KiB
PHP
57 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\ReservationBundle\Tests;
|
|
|
|
use KupShop\ProductReservationBundle\Util\ProductReservationUtil;
|
|
use KupShop\ReservationBundle\Entity\Reservation;
|
|
use KupShop\ReservationBundle\Util\ReservationUtil;
|
|
|
|
trait ReservationTestTrait
|
|
{
|
|
private ReservationUtil $reservationUtil;
|
|
private ProductReservationUtil $productReservationUtil;
|
|
|
|
protected function createTestReservation(int $productId, ?int $variationId, bool $productReservationAsserts = true): Reservation
|
|
{
|
|
$inStore = $this->getProductInStoreQuantity($productId, $variationId);
|
|
$reservedQuantity = $this->productReservationUtil->getProductReservedQuantity($productId, $variationId);
|
|
|
|
$reservation = $this->reservationUtil->createReservation(
|
|
[
|
|
'email' => 'test@wpj.cz',
|
|
'name' => 'Wpj',
|
|
'surname' => 'Wpj',
|
|
'phone' => '+420123456789',
|
|
],
|
|
$productId,
|
|
$variationId,
|
|
[
|
|
'sellerId' => 1,
|
|
]
|
|
);
|
|
|
|
$this->assertInstanceOf(Reservation::class, $reservation, 'Zkontrolovat, ze se vytvorila rezervace');
|
|
|
|
if ($productReservationAsserts) {
|
|
$this->assertEquals(
|
|
$reservedQuantity + 1,
|
|
$this->productReservationUtil->getProductReservedQuantity($productId, $variationId),
|
|
'Skladova rezervace musi byt vytvorena'
|
|
);
|
|
$this->assertEquals($inStore - 1, $this->getProductInStoreQuantity($productId, $variationId), 'Webovy sklad musi byt odecteny');
|
|
}
|
|
|
|
return $reservation;
|
|
}
|
|
|
|
private function getProductInStoreQuantity(int $productId, ?int $variationId = null): float
|
|
{
|
|
$object = \Variation::createProductOrVariation($productId, $variationId);
|
|
$object->createFromDB();
|
|
|
|
return (float) $object->inStore;
|
|
}
|
|
}
|