89 lines
2.7 KiB
PHP
89 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace KupShop\WarehouseBundle\Tests;
|
|
|
|
use KupShop\CatalogBundle\Util\Product\ProductPriceWeigher;
|
|
use KupShop\WarehouseBundle\Util\StockInWorker;
|
|
use Query\Operator;
|
|
|
|
class ProductWeightedPurchasePriceTest extends \DatabaseTestCase
|
|
{
|
|
/** @var ProductPriceWeigher */
|
|
private $productPriceWeigher;
|
|
/** @var StockInWorker */
|
|
private $stockInWorker;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->productPriceWeigher = $this->createPartialMock(ProductPriceWeigher::class, ['getOldItem']);
|
|
$this->stockInWorker = $this->get(StockInWorker::class);
|
|
}
|
|
|
|
public function testAddStoreItemWithFilledPriceBuy()
|
|
{
|
|
$IDP = 3;
|
|
$this->updateSQL('products', ['in_store' => 0, 'price_buy' => 15], ['id' => $IDP]);
|
|
|
|
$this->removeModule(\Modules::PRODUCTS, \Modules::SUB_PRICE_BUY);
|
|
$this->addModule(\Modules::STOCK_IN, \Modules::SUB_WEIGHTED_PURCHASE_PRICE);
|
|
|
|
$this->addStoreItem([
|
|
'id_product' => $IDP,
|
|
'id_variation' => null,
|
|
'quantity' => 10,
|
|
'price' => 4,
|
|
'additional_costs' => 1,
|
|
]);
|
|
$this->checkWeightedPrice($IDP, 5);
|
|
|
|
$this->addStoreItem([
|
|
'id_product' => $IDP,
|
|
'id_variation' => null,
|
|
'quantity' => 10,
|
|
'price' => 6,
|
|
'additional_costs' => 1,
|
|
]);
|
|
$this->checkWeightedPrice($IDP, 6);
|
|
|
|
$this->sellItem($IDP, 15);
|
|
|
|
$this->addStoreItem([
|
|
'id_product' => $IDP,
|
|
'id_variation' => null,
|
|
'quantity' => 5,
|
|
'price' => 8,
|
|
'additional_costs' => 1,
|
|
]);
|
|
$this->checkWeightedPrice($IDP, 7.5);
|
|
|
|
$this->sellItem($IDP, 10);
|
|
$this->addStoreItem([
|
|
'id_product' => $IDP,
|
|
'id_variation' => null,
|
|
'quantity' => 4,
|
|
'price' => 7,
|
|
'additional_costs' => 1,
|
|
]);
|
|
|
|
$this->checkWeightedPrice($IDP, 8);
|
|
}
|
|
|
|
protected function addStoreItem($stockInItem)
|
|
{
|
|
$this->stockInWorker->storeIn($stockInItem, $stockInItem['quantity']);
|
|
}
|
|
|
|
protected function sellItem($id_product, $pieces)
|
|
{
|
|
sqlQuery('UPDATE products set in_store=in_store - :in_store where id = :id', ['id' => $id_product, 'in_store' => $pieces]);
|
|
}
|
|
|
|
private function checkWeightedPrice($id_product, $weighted_price_expected)
|
|
{
|
|
$weighted_price = sqlQueryBuilder()->select('price_buy')->from('products')->where(Operator::equals(['id' => $id_product]))->execute()->fetchColumn();
|
|
$this->assertEquals($weighted_price_expected, $weighted_price, 'Vazena nakupni cena nesedi!');
|
|
}
|
|
}
|