Skip to content

Commit

Permalink
Merge pull request #45 from BitBagCommerce/OP-165/plugin_update
Browse files Browse the repository at this point in the history
[OP-165] Upgrade code quality
  • Loading branch information
senghe authored Nov 12, 2023
2 parents b419196 + 0be02bd commit 093c6d1
Show file tree
Hide file tree
Showing 45 changed files with 498 additions and 293 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
php: [8.0]
symfony: [^5.4, ^6.0]
sylius: [~1.11.0, ~1.12.0]
node: [14.x]
node: [14.17.x]
mysql: [5.7, 8.0]

exclude:
Expand Down Expand Up @@ -124,6 +124,11 @@ jobs:
restore-keys: |
${{ runner.os }}-node-${{ matrix.node }}-yarn-
-
name: Copy package.json.dist to package.json
if: matrix.sylius != ''
run: (cd tests/Application && cp package.json.\${{ matrix.sylius }}.dist package.json)

-
name: Install JS dependencies
run: (cd tests/Application && yarn install)
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

/tests/Application/yarn.lock

/.phpunit.result.cache
/behat.yml
/phpspec.yml
/phpunit.xml
/.phpunit.result.cache
.phpunit.result.cache

# Symfony CLI https://symfony.com/doc/current/setup/symfony_server.html#different-php-settings-per-project
/.php-version
/php.ini
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"license": "MIT",
"require": {
"php": "^8.0",
"sylius/sylius": "~1.11.0 || ~1.12.0"
"sylius/sylius": "~1.11.0 || ~1.12.0",
"symfony/webpack-encore-bundle": "^1.12"
},
"require-dev": {
"ext-json": "*",
"symfony/webpack-encore-bundle": "^1.15",
"behat/behat": "^3.6.1",
"behat/mink-selenium2-driver": "^1.4",
"dmore/behat-chrome-extension": "^1.3",
Expand Down Expand Up @@ -41,7 +41,8 @@
"friendsofphp/php-cs-fixer": "^3.0",
"bitbag/coding-standard": "^1.0",
"lchrusciel/api-test-case": "^5.1",
"polishsymfonycommunity/symfony-mocker-container": "^1.0"
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"php-http/message-factory": "^1.1"
},
"conflict": {
"symfony/symfony": "4.1.8",
Expand Down
34 changes: 34 additions & 0 deletions features/creating_bundled_product.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@bundled_product
Feature: Creating a product in store which is a bundle of other products
I want to be able to add bundled product to cart

Background:
Given the store operates on a single channel in "United States"
And I am logged in as an administrator
And the store has a product "Jack Daniels Gentleman" priced at "$10.00"
And the store has a product "Johny Walker Black" priced at "$10.00"
And the store has a product "Jim Beam Double Oak" priced at "$10.00"

@ui @javascript
Scenario: Creating a bundled product
When I want to create a new bundled product
And I specify its code as "WHISKEY_PACK"
And I name it "Whiskey double pack" in "English (United States)"
And I set its slug to "whiskey-double-pack" in "English (United States)"
And I set its price to "$10.00" for "United States" channel
And I set its original price to "$20.00" for "United States" channel
And I add product "Johny Walker Black" and "Jack Daniels Gentleman" to the bundle
And I add it
Then I should be notified that it has been successfully created

@ui @javascript
Scenario: Creating a bundled product with more products
When I want to create a new bundled product
And I specify its code as "WHISKEY_BIG_PACK"
And I name it "Whiskey triple pack" in "English (United States)"
And I set its slug to "whiskey-triple-pack" in "English (United States)"
And I set its price to "$10.00" for "United States" channel
And I set its original price to "$20.00" for "United States" channel
And I add product "Johny Walker Black" and "Jack Daniels Gentleman" and "Jim Beam Double Oak" to the bundle
And I add it
Then I should be notified that it has been successfully created
30 changes: 26 additions & 4 deletions features/having_bundled_product_in_store.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,37 @@ Feature: Having a product in store which is a bundle of other products

Background:
Given the store operates on a single channel in "United States"
And the store has locale en_US
And I am a logged in customer
And the store ships everywhere for Free
And the store allows paying Offline

@ui
Scenario: Adding a product to cart
Given I am a logged in customer
And the store has a product "Jack Daniels Gentleman" priced at "$10.00"
Scenario: Adding a product bundle to the cart
Given the store has a product "Jack Daniels Gentleman" priced at "$10.00"
And the store has a product "Johny Walker Black" priced at "$10.00"
And the store has bundled product "Whiskey double pack" priced at "$18.00" which contains "Jack Daniels Gentleman" and "Johny Walker Black"
And all store products appear under a main taxonomy
Then I added product "Whiskey double pack" to the cart
And I should be on my cart summary page
And there should be one item in my cart

@ui
Scenario: Adding a few product bundles to the cart
Given the store has a product "Jim Beam" priced at "$10.00"
And the store has a product "Jim Beam Double Oak" priced at "$10.00"
And the store has bundled product "Jim Beam double pack" priced at "$18.00" which contains "Jim Beam" and "Jim Beam Double Oak"
And all store products appear under a main taxonomy
Then I added product "Jim Beam double pack" to the cart
And I change product "Jim Beam double pack" quantity to 5 in my cart
And I should see "Jim Beam double pack" with quantity 5 in my cart

@ui
Scenario: Placing an order for a bundled product
Given the store has a product "Jim Beam" priced at "$10.00"
And the store has a product "Jim Beam Double Oak" priced at "$10.00"
And the store has bundled product "Jim Beam double pack" priced at "$18.00" which contains "Jim Beam" and "Jim Beam Double Oak"
Given I have product "Jim Beam double pack" in the cart
And I specified the billing address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
And I proceed with "Free" shipping method and "Offline" payment
And I confirm my order
Then I should see the thank you page
17 changes: 5 additions & 12 deletions src/Command/AddProductBundleItemToCartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,11 @@

final class AddProductBundleItemToCartCommand
{
/** @var ProductBundleItemInterface */
private $productBundleItem;

/** @var ProductVariantInterface|null */
private $productVariant;

/** @var int|null */
private $quantity;

public function __construct(ProductBundleItemInterface $productBundleItem)
{
$this->productBundleItem = $productBundleItem;
public function __construct(
private ProductBundleItemInterface $productBundleItem,
private ?ProductVariantInterface $productVariant = null,
private ?int $quantity = null
) {
$this->productVariant = $productBundleItem->getProductVariant();
$this->quantity = $productBundleItem->getQuantity();
}
Expand Down
18 changes: 3 additions & 15 deletions src/Command/AddProductBundleToCartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,11 @@

final class AddProductBundleToCartCommand implements OrderIdentityAwareInterface, ProductCodeAwareInterface
{
/** @var int */
private $orderId;

/** @var string */
private $productCode;

/** @var int */
private $quantity;

public function __construct(
int $orderId,
string $productCode,
int $quantity = 1
private int $orderId,
private string $productCode,
private int $quantity = 1
) {
$this->orderId = $orderId;
$this->productCode = $productCode;
$this->quantity = $quantity;
}

public function getOrderId(): int
Expand Down
25 changes: 4 additions & 21 deletions src/Controller/OrderItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@

class OrderItemController extends BaseOrderItemController
{
/** @var MessageBusInterface */
protected $messageBus;

/** @var OrderRepositoryInterface */
protected $orderRepository;

/** @var AddProductBundleToCartDtoFactoryInterface */
private $addProductBundleToCartDtoFactory;

/** @var AddProductBundleToCartCommandFactoryInterface */
private $addProductBundleToCartCommandFactory;

public function __construct(
MetadataInterface $metadata,
Controller\RequestConfigurationFactoryInterface $requestConfigurationFactory,
Expand All @@ -62,10 +50,10 @@ public function __construct(
Controller\StateMachineInterface $stateMachine,
Controller\ResourceUpdateHandlerInterface $resourceUpdateHandler,
Controller\ResourceDeleteHandlerInterface $resourceDeleteHandler,
MessageBusInterface $messageBus,
OrderRepositoryInterface $orderRepository,
AddProductBundleToCartDtoFactoryInterface $addProductBundleToCartDtoFactory,
AddProductBundleToCartCommandFactoryInterface $addProductBundleToCartCommandFactory
private MessageBusInterface $messageBus,
private OrderRepositoryInterface $orderRepository,
private AddProductBundleToCartDtoFactoryInterface $addProductBundleToCartDtoFactory,
private AddProductBundleToCartCommandFactoryInterface $addProductBundleToCartCommandFactory
) {
parent::__construct(
$metadata,
Expand All @@ -86,11 +74,6 @@ public function __construct(
$resourceUpdateHandler,
$resourceDeleteHandler
);

$this->messageBus = $messageBus;
$this->orderRepository = $orderRepository;
$this->addProductBundleToCartDtoFactory = $addProductBundleToCartDtoFactory;
$this->addProductBundleToCartCommandFactory = $addProductBundleToCartCommandFactory;
}

public function addProductBundleAction(Request $request): ?Response
Expand Down
25 changes: 4 additions & 21 deletions src/Dto/AddProductBundleToCartDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace BitBag\SyliusProductBundlePlugin\Dto;

use BitBag\SyliusProductBundlePlugin\Command\AddProductBundleItemToCartCommand;
use BitBag\SyliusProductBundlePlugin\Command\ProductCodeAwareInterface;
use BitBag\SyliusProductBundlePlugin\Entity\ProductInterface;
use Doctrine\Common\Collections\ArrayCollection;
Expand All @@ -19,30 +18,14 @@

final class AddProductBundleToCartDto implements AddProductBundleToCartDtoInterface, ProductCodeAwareInterface
{
/** @var OrderInterface */
private $cart;
private ArrayCollection $productBundleItems;

/** @var OrderItemInterface */
private $cartItem;

/** @var ProductInterface */
private $product;

/** @var ArrayCollection */
private $productBundleItems;

/**
* @param AddProductBundleItemToCartCommand[] $productBundleItems
*/
public function __construct(
OrderInterface $cart,
OrderItemInterface $cartItem,
ProductInterface $product,
private OrderInterface $cart,
private OrderItemInterface $cartItem,
private ProductInterface $product,
array $productBundleItems
) {
$this->cart = $cart;
$this->cartItem = $cartItem;
$this->product = $product;
$this->productBundleItems = new ArrayCollection($productBundleItems);
}

Expand Down
18 changes: 5 additions & 13 deletions src/Dto/Api/AddProductBundleToCartDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,11 @@

final class AddProductBundleToCartDto implements OrderTokenValueAwareInterface
{
/** @var string|null */
private $orderTokenValue;

/** @var string */
private $productCode;

/** @var int */
private $quantity;

public function __construct(string $productCode, int $quantity = 1)
{
$this->productCode = $productCode;
$this->quantity = $quantity;
public function __construct(
private string $productCode,
private int $quantity = 1,
private ?string $orderTokenValue = null
) {
}

public function getOrderTokenValue(): ?string
Expand Down
9 changes: 3 additions & 6 deletions src/Factory/AddProductBundleToCartDtoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@

final class AddProductBundleToCartDtoFactory implements AddProductBundleToCartDtoFactoryInterface
{
/** @var AddProductBundleItemToCartCommandFactoryInterface */
private $addProductBundleItemToCartCommandFactory;

public function __construct(AddProductBundleItemToCartCommandFactoryInterface $addProductBundleItemToCartCommandFactory)
{
$this->addProductBundleItemToCartCommandFactory = $addProductBundleItemToCartCommandFactory;
public function __construct(
private AddProductBundleItemToCartCommandFactoryInterface $addProductBundleItemToCartCommandFactory
) {
}

public function createNew(
Expand Down
9 changes: 3 additions & 6 deletions src/Factory/OrderItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@

final class OrderItemFactory implements OrderItemFactoryInterface
{
/** @var CartItemFactoryInterface */
private $decoratedFactory;

public function __construct(CartItemFactoryInterface $decoratedFactory)
{
$this->decoratedFactory = $decoratedFactory;
public function __construct(
private CartItemFactoryInterface $decoratedFactory
) {
}

public function createNew(): OrderItemInterface
Expand Down
9 changes: 3 additions & 6 deletions src/Factory/ProductBundleOrderItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

final class ProductBundleOrderItemFactory implements ProductBundleOrderItemFactoryInterface
{
/** @var FactoryInterface */
private $decoratedFactory;

public function __construct(FactoryInterface $decoratedFactory)
{
$this->decoratedFactory = $decoratedFactory;
public function __construct(
private FactoryInterface $decoratedFactory
) {
}

public function createNew(): ProductBundleOrderItemInterface
Expand Down
14 changes: 4 additions & 10 deletions src/Factory/ProductFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@

final class ProductFactory implements ProductFactoryInterface
{
/** @var DecoratedProductFactoryInterface */
private $decoratedFactory;

/** @var FactoryInterface */
private $productBundleFactory;

public function __construct(DecoratedProductFactoryInterface $decoratedFactory, FactoryInterface $productBundleFactory)
{
$this->decoratedFactory = $decoratedFactory;
$this->productBundleFactory = $productBundleFactory;
public function __construct(
private DecoratedProductFactoryInterface $decoratedFactory,
private FactoryInterface $productBundleFactory
) {
}

public function createWithVariantAndBundle(): BaseProductInterface
Expand Down
18 changes: 3 additions & 15 deletions src/Handler/AddProductBundleToCartHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,11 @@

final class AddProductBundleToCartHandler implements MessageHandlerInterface
{
/** @var OrderRepositoryInterface */
private $orderRepository;

/** @var ProductRepositoryInterface */
private $productRepository;

/** @var CartProcessorInterface */
private $cartProcessor;

public function __construct(
OrderRepositoryInterface $orderRepository,
ProductRepositoryInterface $productRepository,
CartProcessorInterface $cartItemProcessor
private OrderRepositoryInterface $orderRepository,
private ProductRepositoryInterface $productRepository,
private CartProcessorInterface $cartProcessor
) {
$this->orderRepository = $orderRepository;
$this->productRepository = $productRepository;
$this->cartProcessor = $cartItemProcessor;
}

public function __invoke(AddProductBundleToCartCommand $addProductBundleToCartCommand): void
Expand Down
Loading

0 comments on commit 093c6d1

Please sign in to comment.