Skip to content

Commit

Permalink
Sylius 1.13 support and wishlist code update (#212)
Browse files Browse the repository at this point in the history
* OP-169: Adjust code for PHP8.1 style

* OP-169: Add first batch of PHPSpec tests

* OP-169: Adjust PHP version in composer.json to 8.1

* OP-169: Misc source code improvements

* OP-169: Add additional command handler specs

* OP-169: Finish adding command handler specs, adjust code style of existing specs

* Resolve conflicts

* Fix php spec tests

* Remove php 8.0 from build

* Remove doubled service import

* Fix incorrect message bus declaration

* Add package json file for Sylius 1.13

* Fix interface

* Fix package json name for Sylius 1.13

* Try to fix tests for Sylius 1.13

* Fix bundles file for Sylius 1.13, add wait after ajax call in behat

* Fix semantic versioning in build for Sylius 1.13

* Add lchrusciel api test case package

* Add wishlist repository test

* Fix indent and add php unit tests for CI

* Add functional wishlist api tests

* Downgrade nelmio/alice package for symfony 5.4 support

* Add phpunit bridge package

* Drop support for Sylius 1.11, add support for Sylius 1.13

* Add php unit configuration file to git

* Remove configuration for Sylius 1.11

* Revert php unit bridge package

* Add prefer source for sylius package

* Split API responses between Sylius version

* Update security for Sylius 1.12 and 1.13, remove generic file

* Change deprecated twig function

* Revert "Change deprecated twig function"

This reverts commit 7cd0b32.

* Remove redundant php spec tests, add missing scenarios

* CR fixes + OS headers

---------

Co-authored-by: Marek Rzytki <rzytki7@gmail.com>
  • Loading branch information
arek31 and marekrzytki committed May 13, 2024
1 parent 8b77081 commit f02f2c1
Show file tree
Hide file tree
Showing 142 changed files with 3,881 additions and 1,045 deletions.
395 changes: 212 additions & 183 deletions .github/workflows/build.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
!/etc/build/.gitignore

/behat.yml
/phpunit.xml
24 changes: 20 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Wishlist plugin for Sylius.",
"license": "MIT",
"require": {
"php": "^8.0",
"sylius/sylius": "~1.11.0 || ~1.12.0 || ~1.13.x-dev",
"php": "^8.1",
"sylius/sylius": "~1.12.0 || ~1.13.0",
"symfony/webpack-encore-bundle": "^1.15",
"dompdf/dompdf": "^2.0"
},
Expand Down Expand Up @@ -35,7 +35,9 @@
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"league/flysystem-bundle": "2.4.0",
"sylius/mailer-bundle": "^1.8 || ^2.0@beta"
"sylius/mailer-bundle": "^1.8 || ^2.0@beta",
"lchrusciel/api-test-case": "^4.1 || ^5.0",
"nelmio/alice": "^3.10"
},
"conflict": {
"symfony/symfony": "4.1.8",
Expand All @@ -52,7 +54,12 @@
}
},
"autoload-dev": {
"classmap": ["tests/Application/Kernel.php"]
"classmap": ["tests/Application/Kernel.php"],
"psr-4": {
"BitBag\\SyliusWishlistPlugin\\": "src/",
"Tests\\BitBag\\SyliusWishlistPlugin\\": "tests/",
"Sylius\\Tests\\Api\\": ["vendor/sylius/sylius/tests/Api/"]
}
},
"config": {
"allow-plugins": {
Expand All @@ -61,6 +68,15 @@
"dealerdirect/phpcodesniffer-composer-installer": true,
"symfony/thanks": true,
"symfony/flex": true
},
"preferred-install": {
"sylius/sylius": "source"
}
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
}
}
}
2 changes: 1 addition & 1 deletion features/adding_product_to_selected_wishlist.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Feature: Adding a product to selected wishlist
And the store has a product "Jack Daniels Gentleman" priced at "$10.00"
And all store products appear under a main taxonomy
And I add "Jack Daniels Gentleman" to selected wishlist "Wishlist2"
And I should have "Jack Daniels Gentleman" in selected wishlists "Wishlist2"
And I should have "Jack Daniels Gentleman" in selected wishlists "Wishlist2"
4 changes: 4 additions & 0 deletions features/assigning_wishlist_to_user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ Feature: Assigning a wishlist to a user
@ui @javascript
Scenario: Assigning a wishlist to a user and logout
When I go to "/"
And I go to "/wishlists"
And I should have 0 wishlists
And I log in as "jdeer@sylius.pl"
And I go to "/wishlists"
And I should have 2 wishlists
And I press "wishlist-edit-button-Wishlist1"
And I fill in "edit_wishlist_name" with "Wishlist-assigned"
And I press "edit_wishlist_save"
And I should wait for one second
And I log out
And I go to "/wishlists"
Then I should have 0 wishlists
Expand Down
29 changes: 29 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/Application/config/bootstrap.php"
>
<php>
<ini name="error_reporting" value="-1" />

<env name="APP_SECRET" value="''" />
<env name="APP_ENV" value="test"/>
<env name="APP_DEBUG" value="0"/>
<env name="SHELL_VERBOSITY" value="-1" />

<server name="KERNEL_CLASS" value="Tests\BitBag\SyliusWishlistPlugin\Application\Kernel" />
<server name="KERNEL_CLASS_PATH" value="/tests/Application/Kernel.php" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true"/>
<server name="SHELL_VERBOSITY" value="-1" />
<server name="ESCAPE_JSON" value="true" />
</php>

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
1 change: 0 additions & 1 deletion spec/Checker/ProductProcessingCheckerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
final class ProductProcessingCheckerSpec extends ObjectBehavior
{
public function let(

ProductQuantityCheckerInterface $productQuantityChecker
): void {
$this->beConstructedWith(
Expand Down
38 changes: 38 additions & 0 deletions spec/Checker/WishlistNameCheckerSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusWishlistPlugin\Checker;

use BitBag\SyliusWishlistPlugin\Checker\WishlistNameChecker;
use PhpSpec\ObjectBehavior;

final class WishlistNameCheckerSpec extends ObjectBehavior
{
public function it_is_initializable(): void
{
$this->shouldHaveType(WishlistNameChecker::class);
}

public function it_returns_true_if_names_are_equal(): void
{
$existingWishlistName = 'test1';
$wishlistToCreate = 'test1';

$this->check($existingWishlistName, $wishlistToCreate)->shouldReturn(true);
}

public function it_returns_false_if_names_are_not_equal(): void
{
$existingWishlistName = 'test1';
$wishlistToCreate = 'test2';

$this->check($existingWishlistName, $wishlistToCreate)->shouldReturn(false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist;

use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddProductToSelectedWishlist;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddProductToSelectedWishlistInterface;
use BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist\AddProductToSelectedWishlistHandler;
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface;
use BitBag\SyliusWishlistPlugin\Entity\WishlistProductInterface;
use BitBag\SyliusWishlistPlugin\Factory\WishlistProductFactoryInterface;
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\ProductInterface;

final class AddProductToSelectedWishlistHandlerSpec extends ObjectBehavior
{
public function let(
WishlistProductFactoryInterface $wishlistProductFactory,
WishlistRepositoryInterface $wishlistRepository
): void {
$this->beConstructedWith(
$wishlistProductFactory,
$wishlistRepository
);
}

public function it_is_initializable(): void
{
$this->shouldHaveType(AddProductToSelectedWishlistHandler::class);
}

public function it_adds_product_to_wishlist_if_product_is_found(
AddProductToSelectedWishlistInterface $addProductToSelectedWishlist,
ProductInterface $product,
WishlistInterface $wishlist,
WishlistProductFactoryInterface $wishlistProductFactory,
WishlistProductInterface $wishlistProduct,
WishlistRepositoryInterface $wishlistRepository
): void
{
$addProductToSelectedWishlist->getProduct()->willReturn($product);
$addProductToSelectedWishlist->getWishlist()->willReturn($wishlist);

$wishlistProductFactory->createForWishlistAndProduct($wishlist, $product)->willReturn($wishlistProduct);

$wishlist->addWishlistProduct($wishlistProduct)->shouldBeCalled();
$wishlistRepository->add($wishlist)->shouldBeCalled();

$this->__invoke($addProductToSelectedWishlist);
}
}
93 changes: 93 additions & 0 deletions spec/CommandHandler/Wishlist/AddProductToWishlistHandlerSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist;

use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddProductToWishlist;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistTokenValueAwareInterface;
use BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist\AddProductToWishlistHandler;
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface;
use BitBag\SyliusWishlistPlugin\Entity\WishlistProductInterface;
use BitBag\SyliusWishlistPlugin\Exception\ProductNotFoundException;
use BitBag\SyliusWishlistPlugin\Exception\WishlistNotFoundException;
use BitBag\SyliusWishlistPlugin\Factory\WishlistProductFactoryInterface;
use Doctrine\Persistence\ObjectManager;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;

final class AddProductToWishlistHandlerSpec extends ObjectBehavior
{
public function let(
WishlistProductFactoryInterface $wishlistProductFactory,
ProductRepositoryInterface $productRepository,
ObjectManager $wishlistManager
): void {
$this->beConstructedWith(
$wishlistProductFactory,
$productRepository,
$wishlistManager
);
}

public function it_is_initializable(): void
{
$this->shouldHaveType(AddProductToWishlistHandler::class);
}

public function it_adds_product_to_wishlist(
ProductInterface $product,
WishlistInterface $wishlist,
ProductRepositoryInterface $productRepository,
WishlistProductFactoryInterface $wishlistProductFactory,
WishlistProductInterface $wishlistProduct,
ObjectManager $wishlistManager
): void
{
$productRepository->find(1)->willReturn($product);

$wishlistProductFactory->createForWishlistAndProduct($wishlist, $product)->willReturn($wishlistProduct);
$wishlist->addWishlistProduct($wishlistProduct)->shouldBeCalled();

$wishlistManager->persist($wishlistProduct)->shouldBeCalled();
$wishlistManager->flush()->shouldBeCalled();

$addProductToWishlist = new AddProductToWishlist(1);
$addProductToWishlist->setWishlist($wishlist->getWrappedObject());

$this->__invoke($addProductToWishlist);
}

public function it_doesnt_add_product_to_wishlist_if_product_isnt_found(
ProductInterface $product,
WishlistInterface $wishlist,
ProductRepositoryInterface $productRepository,
WishlistProductFactoryInterface $wishlistProductFactory,
WishlistProductInterface $wishlistProduct,
ObjectManager $wishlistManager
): void
{
$productRepository->find(1)->willReturn(null);

$wishlistProductFactory->createForWishlistAndProduct($wishlist, $product)->shouldNotBeCalled();
$wishlist->addWishlistProduct($wishlistProduct)->shouldNotBeCalled();

$wishlistManager->persist($wishlistProduct)->shouldNotBeCalled();
$wishlistManager->flush()->shouldNotBeCalled();

$addProductToWishlist = new AddProductToWishlist(1);
$addProductToWishlist->setWishlist($wishlist->getWrappedObject());

$this
->shouldThrow(ProductNotFoundException::class)
->during('__invoke', [$addProductToWishlist])
;
}
}
Loading

0 comments on commit f02f2c1

Please sign in to comment.