Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sylius 1.13 support and wishlist code update #212

Merged
merged 35 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
545b9b4
OP-169: Adjust code for PHP8.1 style
arek31 Jul 4, 2023
9b5b0e6
OP-169: Add first batch of PHPSpec tests
arek31 Jul 4, 2023
d2cb898
OP-169: Adjust PHP version in composer.json to 8.1
arek31 Jul 4, 2023
c931b7b
OP-169: Misc source code improvements
arek31 Jul 5, 2023
f66016d
OP-169: Add additional command handler specs
arek31 Jul 5, 2023
dd7c4e8
OP-169: Finish adding command handler specs, adjust code style of exi…
arek31 Jul 18, 2023
3b03bf6
Merge remote-tracking branch 'origin/master' into OP-169-wishlist-cod…
marekrzytki Apr 11, 2024
24eb2c0
Resolve conflicts
marekrzytki Apr 11, 2024
b56ff7d
Fix php spec tests
marekrzytki Apr 11, 2024
1488d11
Remove php 8.0 from build
marekrzytki Apr 11, 2024
7afc297
Remove doubled service import
marekrzytki Apr 11, 2024
2371ef2
Fix incorrect message bus declaration
marekrzytki Apr 11, 2024
17243d6
Add package json file for Sylius 1.13
marekrzytki Apr 11, 2024
f6cbb01
Fix interface
marekrzytki Apr 11, 2024
cfb4787
Fix package json name for Sylius 1.13
marekrzytki Apr 11, 2024
581fd42
Try to fix tests for Sylius 1.13
marekrzytki Apr 12, 2024
dab6d96
Fix bundles file for Sylius 1.13, add wait after ajax call in behat
marekrzytki Apr 12, 2024
6d859ee
Fix semantic versioning in build for Sylius 1.13
marekrzytki Apr 12, 2024
770bb4a
Add lchrusciel api test case package
marekrzytki Apr 16, 2024
12ec451
Add wishlist repository test
marekrzytki Apr 16, 2024
d729666
Fix indent and add php unit tests for CI
marekrzytki Apr 16, 2024
283efed
Add functional wishlist api tests
marekrzytki Apr 17, 2024
6065307
Downgrade nelmio/alice package for symfony 5.4 support
marekrzytki Apr 17, 2024
d5d0ccc
Add phpunit bridge package
marekrzytki Apr 22, 2024
8982c3d
Drop support for Sylius 1.11, add support for Sylius 1.13
marekrzytki Apr 24, 2024
f76111f
Add php unit configuration file to git
marekrzytki Apr 24, 2024
07fa90c
Remove configuration for Sylius 1.11
marekrzytki Apr 24, 2024
e295552
Revert php unit bridge package
marekrzytki Apr 24, 2024
862e17d
Add prefer source for sylius package
marekrzytki Apr 24, 2024
4a65164
Split API responses between Sylius version
marekrzytki Apr 24, 2024
776a0f0
Update security for Sylius 1.12 and 1.13, remove generic file
marekrzytki May 6, 2024
7cd0b32
Change deprecated twig function
marekrzytki May 6, 2024
ad6ae2e
Revert "Change deprecated twig function"
marekrzytki May 6, 2024
bbb5066
Remove redundant php spec tests, add missing scenarios
marekrzytki May 13, 2024
5269e16
CR fixes + OS headers
marekrzytki May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading