Skip to content

Commit

Permalink
Merge pull request #5 from hdasdoria/main
Browse files Browse the repository at this point in the history
add test workflow from sylius standard
  • Loading branch information
hdasdoria authored Nov 15, 2023
2 parents bcba35d + d91e560 commit 236de7a
Show file tree
Hide file tree
Showing 94 changed files with 525 additions and 764 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ jobs:
-
name: Validate composer.json
run: composer validate --ansi --strict
-

-
name: Run ECS
run: vendor/bin/ecs check --config=ecs.php --clear-cache src tests

Expand All @@ -109,3 +109,4 @@ jobs:
-
name: Run Behat
run: vendor/bin/behat --colors -vvv --no-interaction || vendor/bin/behat --colors -vvv --no-interaction --rerun

43 changes: 0 additions & 43 deletions .github/workflows/php.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/vendor/
/node_modules/
node_modules
/.github/*
/etc/build/*
!/etc/build/.gitignore

composer.lock

/tests/Application/yarn.lock

/.phpunit.result.cache
Expand Down
55 changes: 55 additions & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
imports:
- vendor/sylius/sylius/src/Sylius/Behat/Resources/config/suites.yml
- tests/Behat/Resources/suites.yml

default:
extensions:
DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~

FriendsOfBehat\MinkDebugExtension:
directory: etc/build
clean_start: false
screenshot: true

Behat\MinkExtension:
files_path: "%paths.base%/vendor/sylius/sylius/src/Sylius/Behat/Resources/fixtures/"
base_url: "https://127.0.0.1:8080/"
default_session: symfony
javascript_session: chrome_headless
sessions:
symfony:
symfony: ~
chrome_headless:
chrome:
api_url: http://127.0.0.1:9222
validate_certificate: false
chrome:
selenium2:
browser: chrome
capabilities:
browserName: chrome
browser: chrome
version: ""
marionette: null # https://github.com/Behat/MinkExtension/pull/311
chrome:
switches:
- "start-fullscreen"
- "start-maximized"
- "no-sandbox"
extra_capabilities:
unexpectedAlertBehaviour: accept
firefox:
selenium2:
browser: firefox
show_auto: false

FriendsOfBehat\SymfonyExtension:
bootstrap: tests/Application/config/bootstrap.php
kernel:
class: Tests\Asdoria\SyliusQuickShoppingPlugin\Application\Kernel

FriendsOfBehat\VariadicExtension: ~

FriendsOfBehat\SuiteSettingsExtension:
paths:
- "features"
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"license": "MIT",
"require": {
"php": "^7.4|^8.0",
"php": "^8.0",
"sylius/sylius": "^1.12"
},
"require-dev": {
Expand All @@ -27,22 +27,20 @@
"friends-of-behat/suite-settings-extension": "^1.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev",
"phpspec/phpspec": "^7.0",
"phpspec/phpspec": "^7.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "0.12.99",
"phpstan/phpstan-doctrine": "0.12.33",
"phpstan/phpstan-strict-rules": "^0.12.0",
"phpstan/phpstan-webmozart-assert": "0.12.12",
"phpstan/phpstan": "^1.8.1",
"phpstan/phpstan-doctrine": "1.3.40",
"phpstan/phpstan-strict-rules": "^1.3.0",
"phpstan/phpstan-webmozart-assert": "^1.2.0",
"phpunit/phpunit": "^9.5",
"sensiolabs/security-checker": "^6.0",
"sylius-labs/coding-standard": "^4.0",
"symfony/browser-kit": "^4.4 || ^5.2",
"symfony/debug-bundle": "^4.4 || ^5.2",
"symfony/dotenv": "^4.4 || ^5.2",
"symfony/intl": "^4.4 || ^5.2",
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
"vimeo/psalm": "4.7.1",
"vimeo/psalm": "5.12.0",
"polishsymfonycommunity/symfony-mocker-container": "^1.0"
},
"config": {
Expand All @@ -60,7 +58,8 @@
"prefer-stable": true,
"autoload": {
"psr-4": {
"Asdoria\\SyliusQuickShoppingPlugin\\": "src/"
"Asdoria\\SyliusQuickShoppingPlugin\\": "src/",
"Tests\\Asdoria\\SyliusQuickShoppingPlugin\\": "tests/"
}
},
"autoload-dev": {
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
parameters:
level: max
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
paths:
- src
- tests/Behat

excludes_analyse:
# Makes PHPStan crash
- 'src/DependencyInjection/Configuration.php'

# Test dependencies
- 'tests/Application/app/**.php'
- 'tests/Application/src/**.php'

ignoreErrors:
- '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./'

22 changes: 22 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd"
colors="true"
bootstrap="tests/Application/config/bootstrap.php">
<testsuites>
<testsuite name="AsdoriaSyliusQuickShoppingPlugin Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<php>
<ini name="error_reporting" value="-1" />

<server name="KERNEL_CLASS_PATH" value="/tests/Application/AppKernel.php" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />

<env name="APP_ENV" value="test"/>
<env name="SHELL_VERBOSITY" value="-1" />
</php>
</phpunit>
7 changes: 7 additions & 0 deletions src/Controller/Shop/BulkAddToCartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@
namespace Asdoria\SyliusQuickShoppingPlugin\Controller\Shop;

use Doctrine\Common\Collections\ArrayCollection;
use Sylius\Bundle\OrderBundle\Controller\AddToCartCommandInterface;
use Sylius\Component\Core\Model\OrderInterface;

final class BulkAddToCartCommand implements BulkAddToCartCommandInterface
{
/**
* @param ArrayCollection<array-key,AddToCartCommandInterface> $cartItems
*/
public function __construct(public OrderInterface $cart, public ArrayCollection $cartItems)
{
}

/**
* @return ArrayCollection<array-key,AddToCartCommandInterface>
*/
public function getAddToCartCommandItems(): ArrayCollection
{
return $this->cartItems;
Expand Down
4 changes: 4 additions & 0 deletions src/Controller/Shop/BulkAddToCartCommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
namespace Asdoria\SyliusQuickShoppingPlugin\Controller\Shop;

use Doctrine\Common\Collections\ArrayCollection;
use Sylius\Bundle\OrderBundle\Controller\AddToCartCommandInterface;
use Sylius\Component\Core\Model\OrderInterface;

interface BulkAddToCartCommandInterface
{
/**
* @return ArrayCollection<array-key,AddToCartCommandInterface>
*/
public function getAddToCartCommandItems(): ArrayCollection;

public function getCart(): OrderInterface;
Expand Down
6 changes: 5 additions & 1 deletion src/Controller/Shop/QuickShoppingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

class QuickShoppingController
{
/**
* @param string[] $validationGroups
*/
public function __construct(
protected Environment $twig,
protected FormFactoryInterface $formFactory,
Expand Down Expand Up @@ -55,6 +58,7 @@ public function __invoke(Request $request): Response
$bulkAddToCartCommand = $form->getData();
$cart = $bulkAddToCartCommand->getCart();
foreach ($form->get('cartItems') as $childForm) {
/** @var AddToCartCommand $addToCartCommand */
$addToCartCommand = $childForm->getData();
$errors = $this->getCartItemErrors($addToCartCommand->getCartItem());
if (0 < count($errors)) {
Expand Down Expand Up @@ -96,7 +100,7 @@ protected function getAddToCartFormWithErrors(ConstraintViolationListInterface $
? $form->get('cartItem')
: $form->get('cartItem')->get($error->getPropertyPath());

$formSelected->addError(new FormError($error->getMessage()));
$formSelected->addError(new FormError((string) $error->getMessage()));
}

return $form;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class AsdoriaSyliusQuickShoppingExtension extends Extension
/**
* @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
$loader->load('services.yaml');
Expand Down
4 changes: 4 additions & 0 deletions src/EventListener/AbstractEntitySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use JMS\Serializer\EventDispatcher\Events;
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
use JMS\Serializer\EventDispatcher\ObjectEvent;
use JMS\Serializer\JsonSerializationVisitor;
use JMS\Serializer\Metadata\StaticPropertyMetadata;
use JMS\Serializer\Metadata\VirtualPropertyMetadata;

Expand All @@ -25,11 +26,14 @@ public static function getSubscribedEvents(): array

public function onPostSerialize(ObjectEvent $event): void
{
/** @var string $methodName */
foreach ($this->getMethodNames() as $methodName) {
/** @var JsonSerializationVisitor $visitor */
$visitor = $event->getVisitor();
$metadata = new VirtualPropertyMetadata(static::getClassName(), $methodName);

if (!$visitor->hasData($metadata->name)) {
/** @var mixed $value */
$value = $this->{$methodName}($event->getObject());
$visitor->visitProperty(
new StaticPropertyMetadata(static::getClassName(), $metadata->name, $value),
Expand Down
11 changes: 4 additions & 7 deletions src/EventListener/ProductVariantEntitySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Asdoria\SyliusQuickShoppingPlugin\EventListener;

use App\Entity\Product\ProductVariant;
use Asdoria\SyliusQuickShoppingPlugin\Helper\Model\ProductVariantHelperInterface;
use Sylius\Component\Core\Model\ProductVariant;
use Sylius\Component\Core\Model\ProductVariantInterface;

/**
Expand All @@ -23,6 +23,9 @@ protected static function getClassName(): string
return ProductVariant::class;
}

/**
* @return string[]
*/
protected function getMethodNames(): array
{
return ['getImage', 'getSlug', 'getPrice'];
Expand All @@ -33,17 +36,11 @@ public function getImage(ProductVariantInterface $productVariant): ?string
return $this->productVariantHelper->getImage($productVariant);
}

/**
* @return mixed
*/
public function getSlug(ProductVariantInterface $productVariant): string
{
return $this->productVariantHelper->getSlug($productVariant);
}

/**
* @return mixed
*/
public function getPrice(ProductVariantInterface $productVariant): string
{
return $this->productVariantHelper->getPrice($productVariant);
Expand Down
9 changes: 8 additions & 1 deletion src/Factory/BulkAddToCartCommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use Doctrine\Common\Collections\ArrayCollection;
use Sylius\Bundle\OrderBundle\Controller\AddToCartCommandInterface;
use Sylius\Bundle\OrderBundle\Factory\AddToCartCommandFactoryInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Order\Context\CartContextInterface;
use Sylius\Component\Order\Modifier\OrderItemQuantityModifierInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
Expand All @@ -28,6 +30,9 @@
*/
final class BulkAddToCartCommandFactory implements BulkAddToCartCommandFactoryInterface
{
/**
* @param FactoryInterface<OrderItemInterface> $orderItemFactory
*/
public function __construct(
protected CartContextInterface $cartContext,
protected FactoryInterface $orderItemFactory,
Expand All @@ -38,7 +43,9 @@ public function __construct(

public function createWithAddToCartItems(int $nbr): BulkAddToCartCommandInterface
{
/** @var OrderInterface $cart */
$cart = $this->cartContext->getCart();
/** @var ArrayCollection<array-key,AddToCartCommandInterface> $cartItems */
$cartItems = new ArrayCollection();
for ($i = 0; $i < $nbr; ++$i) {
$cartItems->add($this->createAddToCartCommand($cart));
Expand All @@ -47,7 +54,7 @@ public function createWithAddToCartItems(int $nbr): BulkAddToCartCommandInterfac
return new BulkAddToCartCommand($cart, $cartItems);
}

public function createAddToCartCommand($cart): AddToCartCommandInterface
public function createAddToCartCommand(OrderInterface $cart): AddToCartCommandInterface
{
$orderItem = $this->orderItemFactory->createNew();
$this->orderItemQuantityModifier->modify($orderItem, 1);
Expand Down
Loading

0 comments on commit 236de7a

Please sign in to comment.