Skip to content

Commit

Permalink
clean filler tests and add test case for condition check
Browse files Browse the repository at this point in the history
  • Loading branch information
zuk3975 committed Oct 25, 2022
1 parent 5e0e8f2 commit 07e2bd8
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 13 deletions.
Expand Up @@ -30,13 +30,34 @@
use PrestaShop\PrestaShop\Adapter\Product\Update\Filler\BasicInformationFiller;
use PrestaShop\PrestaShop\Adapter\Product\Update\Filler\ProductFillerInterface;
use PrestaShop\PrestaShop\Adapter\Tools;
use PrestaShop\PrestaShop\Core\Domain\Product\Command\UpdateProductCommand;
use Product;

class BasicInformationFillerTest extends ProductFillerTestCase
{
/**
* @dataProvider getDataForTestFillsUpdatableProperties
*
* @param UpdateProductCommand $command
* @param array $expectedUpdatableProperties
* @param Product $expectedProduct
*/
public function testFillsUpdatableProperties(
UpdateProductCommand $command,
array $expectedUpdatableProperties,
Product $expectedProduct
): void {
$this->fillUpdatableProperties(
$command,
$expectedUpdatableProperties,
$expectedProduct
);
}

/**
* @return ProductFillerInterface
*/
public function getFiller(): ProductFillerInterface
protected function getFiller(): ProductFillerInterface
{
return new BasicInformationFiller(
self::DEFAULT_LANG_ID,
Expand Down
30 changes: 30 additions & 0 deletions tests/Unit/Adapter/Product/Update/Filler/OptionsFillerTest.php
Expand Up @@ -36,6 +36,25 @@

class OptionsFillerTest extends ProductFillerTestCase
{
/**
* @dataProvider getDataForTestFillsUpdatableProperties
*
* @param UpdateProductCommand $command
* @param array $expectedUpdatableProperties
* @param Product $expectedProduct
*/
public function testFillsUpdatableProperties(
UpdateProductCommand $command,
array $expectedUpdatableProperties,
Product $expectedProduct
): void {
$this->fillUpdatableProperties(
$command,
$expectedUpdatableProperties,
$expectedProduct
);
}

/**
* @dataProvider getDataForTestShowPriceAndAvailableForOrderProperties
*
Expand All @@ -59,6 +78,9 @@ public function testFillsShowPriceAndAvailableForOrderProperties(
}

/**
* This provider Provides the initial product and the expected one,
* because there are some cases that depends on previous and new values
*
* @return iterable
*/
public function getDataForTestShowPriceAndAvailableForOrderProperties(): iterable
Expand All @@ -73,6 +95,10 @@ public function getDataForTestShowPriceAndAvailableForOrderProperties(): iterabl
;

$expectedProduct = $this->mockDefaultProduct();
// default product properties already has these values,
// but we still set them just to be more explicit about the expected change
$expectedProduct->show_price = true;
$expectedProduct->available_for_order = true;

yield [
$product,
Expand All @@ -85,6 +111,7 @@ public function getDataForTestShowPriceAndAvailableForOrderProperties(): iterabl
];

$product = $this->mockDefaultProduct();
$product->available_for_order = true;
$product->show_price = false;

$command = $this
Expand Down Expand Up @@ -130,6 +157,9 @@ public function getDataForTestShowPriceAndAvailableForOrderProperties(): iterabl
];
}

/**
* @return iterable
*/
public function getDataForTestFillsUpdatableProperties(): iterable
{
$command = $this->getEmptyCommand();
Expand Down
16 changes: 5 additions & 11 deletions tests/Unit/Adapter/Product/Update/Filler/ProductFillerTestCase.php
Expand Up @@ -43,36 +43,30 @@ abstract class ProductFillerTestCase extends TestCase
protected const PRODUCT_ID = 3;

/**
* @dataProvider getDataForTestFillsUpdatableProperties
*
* @param UpdateProductCommand $command
* @param array<int|string, string|int[]> $expectedUpdatableProperties
* @param array $expectedUpdatableProperties
* @param Product $expectedProduct
*/
public function testFillsUpdatableProperties(
protected function fillUpdatableProperties(
UpdateProductCommand $command,
array $expectedUpdatableProperties,
Product $expectedProduct
): void {
) {
$product = $this->mockDefaultProduct();

$this->assertSame(
$expectedUpdatableProperties,
$this->getFiller()->fillUpdatableProperties($product, $command)
);

// make sure the product properties were filled as expected.
$this->assertEquals($expectedProduct, $product);
}

/**
* @return iterable
*/
abstract public function getDataForTestFillsUpdatableProperties(): iterable;

/**
* @return ProductFillerInterface
*/
abstract public function getFiller(): ProductFillerInterface;
abstract protected function getFiller(): ProductFillerInterface;

/**
* This method mocks product into its default state.
Expand Down
Expand Up @@ -49,8 +49,20 @@ public function testBuildCommand(array $formData, array $expectedCommands)
$this->assertEquals($expectedCommands, $builtCommands);
}

public function getExpectedCommands()
/**
* @return iterable
*/
public function getExpectedCommands(): iterable
{
yield [
[
'specifications' => [
'condition' => null,
],
],
[],
];

yield [
[
'no_data' => ['useless value'],
Expand Down

0 comments on commit 07e2bd8

Please sign in to comment.