Skip to content

Commit

Permalink
Load winzou config conditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMilek committed Oct 16, 2024
1 parent 9952887 commit d6ccb06
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 30 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,25 @@ jobs:
node: ["20.x"]
mysql: ["8.4"]
wkhtmltopdf: ["0.12.6-1", false]
state_machine_adapter: [ "winzou_state_machine", "symfony_workflow" ]
state_machine_adapter: [ "symfony_workflow" ]

include:
-
php: "8.3"
symfony: "^7.1"
sylius: "2.0.x-dev"
node: "20.x"
mysql: "8.4"
wkhtmltopdf: "0.12.6-1"
state_machine_adapter: "winzou_state_machine"
-
php: "8.3"
symfony: "^7.1"
sylius: "2.0.x-dev"
node: "20.x"
mysql: "8.4"
wkhtmltopdf: false
state_machine_adapter: "winzou_state_machine"

env:
APP_ENV: test
Expand Down Expand Up @@ -84,7 +102,6 @@ jobs:
if: matrix.wkhtmltopdf == false
run: |
mv tests/Application/etc/sylius_invoicing_pdf_generation_disabled.yaml tests/Application/config/packages
sed -i 's/pdf_generation_disabled/pdf_generation_enabled/g' behat.yml.dist
-
name: Get Composer cache directory
Expand Down Expand Up @@ -117,6 +134,13 @@ jobs:
name: Install PHP dependencies
run: composer install --no-interaction --no-scripts

-
name: Require Winzou State Machine
if: "${{ matrix.state_machine_adapter == 'winzou_state_machine' }}"
run: |
composer require winzou/state-machine:^0.4 --no-update
composer require winzou/state-machine-bundle:^0.6 --no-update
-
name: Get Yarn cache directory
id: yarn-cache
Expand Down
33 changes: 33 additions & 0 deletions src/Resources/config/app/winzou_state_machine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use winzou\Bundle\StateMachineBundle\winzouStateMachineBundle;

return static function (ContainerConfigurator $container) {
if (class_exists(winzouStateMachineBundle::class)) {
$container->extension('winzou_state_machine', [
'sylius_payment' => [
'callbacks' => [
'after' => [
'sylius_invoicing_plugin_payment_complete_producer' => [
'on' => ['complete'],
'do' => ['@sylius_invoicing_plugin.event_producer.order_payment_paid', '__invoke'],
'args' => ['object'],
],
],
],
],
]);
}
};
10 changes: 1 addition & 9 deletions src/Resources/config/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
imports:
- { resource: "@SyliusInvoicingPlugin/Resources/config/app/winzou_state_machine.php" }
- { resource: 'app/twig_hooks/**/*.yaml' }

parameters:
Expand All @@ -20,15 +21,6 @@ knp_snappy:
pdf:
enabled: true

winzou_state_machine:
sylius_payment:
callbacks:
after:
sylius_invoicing_plugin_payment_complete_producer:
on: ['complete']
do: ['@sylius_invoicing_plugin.event_producer.order_payment_paid', '__invoke']
args: ['object']

sylius_grid:
templates:
filter:
Expand Down
1 change: 0 additions & 1 deletion tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
Sylius\Bundle\CoreBundle\SyliusCoreBundle::class => ['all' => true],
Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true],
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true],
Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true],
Knp\Bundle\GaufretteBundle\KnpGaufretteBundle::class => ['all' => true],
Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true],
Expand Down
8 changes: 0 additions & 8 deletions tests/Application/config/packages/winzou_state_machine.yaml

This file was deleted.

12 changes: 3 additions & 9 deletions tests/Behat/Context/Order/OrderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@

use Behat\Behat\Context\Context;
use Doctrine\Persistence\ObjectManager;
use SM\Factory\FactoryInterface as StateMachineFactoryInterface;
use Sylius\Abstraction\StateMachine\StateMachineInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Payment\PaymentTransitions;

final class OrderContext implements Context
{
private ObjectManager $objectManager;

private StateMachineFactoryInterface $stateMachineFactory;

public function __construct(ObjectManager $objectManager, StateMachineFactoryInterface $stateMachineFactory)
public function __construct(private ObjectManager $objectManager, private StateMachineInterface $stateMachine)
{
$this->objectManager = $objectManager;
$this->stateMachineFactory = $stateMachineFactory;
}

/**
Expand All @@ -35,7 +29,7 @@ public function orderHasJustBeenPaid(OrderInterface $order): void
private function applyPaymentTransitionOnOrder(OrderInterface $order, $transition): void
{
foreach ($order->getPayments() as $payment) {
$this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH)->apply($transition);
$this->stateMachine->apply($payment, PaymentTransitions::GRAPH, $transition);
}
}
}
2 changes: 1 addition & 1 deletion tests/Behat/Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

<service id="Tests\Sylius\InvoicingPlugin\Behat\Context\Order\OrderContext" public="true">
<argument type="service" id="doctrine.orm.entity_manager" />
<argument type="service" id="sm.factory" />
<argument type="service" id="sylius_abstraction.state_machine" />
</service>

<service id="Tests\Sylius\InvoicingPlugin\Behat\Context\Ui\Admin\ManagingChannelsContext" public="true">
Expand Down

0 comments on commit d6ccb06

Please sign in to comment.