Skip to content

Commit

Permalink
PR review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Jun 19, 2024
1 parent 5e4bfcd commit e4fbb72
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 63 deletions.
4 changes: 2 additions & 2 deletions src/Checker/PostUpdateChangesChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Setono\SyliusOrderEditPlugin\Checker;

use Setono\SyliusOrderEditPlugin\Entity\InitialTotalAwareOrderInterface;
use Setono\SyliusOrderEditPlugin\Entity\EditableOrderInterface;
use Setono\SyliusOrderEditPlugin\Exception\NewOrderWrongTotalException;
use Sylius\Component\Core\Model\OrderInterface;

final class PostUpdateChangesChecker implements PostUpdateChangesCheckerInterface
{
public function check(InitialTotalAwareOrderInterface $previousOrder, OrderInterface $newOrder): void
public function check(EditableOrderInterface $previousOrder, OrderInterface $newOrder): void

Check failure on line 13 in src/Checker/PostUpdateChangesChecker.php

View workflow job for this annotation

GitHub Actions / Backwards Compatibility Check

The parameter $previousOrder of Setono\SyliusOrderEditPlugin\Checker\PostUpdateChangesChecker#check() changed from Setono\SyliusOrderEditPlugin\Entity\InitialTotalAwareOrderInterface to a non-contravariant Setono\SyliusOrderEditPlugin\Entity\EditableOrderInterface
{
if ($newOrder->getTotal() > $previousOrder->getInitialTotal()) {
throw new NewOrderWrongTotalException();
Expand Down
7 changes: 2 additions & 5 deletions src/Checker/PostUpdateChangesCheckerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

namespace Setono\SyliusOrderEditPlugin\Checker;

use Setono\SyliusOrderEditPlugin\Entity\InitialTotalAwareOrderInterface;
use Setono\SyliusOrderEditPlugin\Entity\EditableOrderInterface;
use Sylius\Component\Core\Model\OrderInterface;

interface PostUpdateChangesCheckerInterface
{
public function check(
InitialTotalAwareOrderInterface $previousOrder,
OrderInterface $newOrder,
): void;
public function check(EditableOrderInterface $previousOrder, OrderInterface $newOrder): void;

Check failure on line 12 in src/Checker/PostUpdateChangesCheckerInterface.php

View workflow job for this annotation

GitHub Actions / Backwards Compatibility Check

The parameter $previousOrder of Setono\SyliusOrderEditPlugin\Checker\PostUpdateChangesCheckerInterface#check() changed from Setono\SyliusOrderEditPlugin\Entity\InitialTotalAwareOrderInterface to a non-contravariant Setono\SyliusOrderEditPlugin\Entity\EditableOrderInterface

Check failure on line 12 in src/Checker/PostUpdateChangesCheckerInterface.php

View workflow job for this annotation

GitHub Actions / Backwards Compatibility Check

The parameter $previousOrder of Setono\SyliusOrderEditPlugin\Checker\PostUpdateChangesCheckerInterface#check() changed from Setono\SyliusOrderEditPlugin\Entity\InitialTotalAwareOrderInterface to Setono\SyliusOrderEditPlugin\Entity\EditableOrderInterface
}
8 changes: 8 additions & 0 deletions src/DependencyInjection/SetonoSyliusOrderEditExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public function prepend(ContainerBuilder $container): void
'templates' => [
'action' => [
'edit_order' => '@SetonoSyliusOrderEditPlugin/admin/order/grid/editOrder.html.twig',
],
],
]);

Check warning on line 63 in src/DependencyInjection/SetonoSyliusOrderEditExtension.php

View check run for this annotation

Codecov / codecov/patch

src/DependencyInjection/SetonoSyliusOrderEditExtension.php#L61-L63

Added lines #L61 - L63 were not covered by tests

$container->prependExtensionConfig('framework', [
'messenger' => [
'buses' => [
'setono_sylius_order_edit.event_bus' => null,

Check warning on line 68 in src/DependencyInjection/SetonoSyliusOrderEditExtension.php

View check run for this annotation

Codecov / codecov/patch

src/DependencyInjection/SetonoSyliusOrderEditExtension.php#L65-L68

Added lines #L65 - L68 were not covered by tests
],
],
]);
Expand Down
6 changes: 5 additions & 1 deletion src/Entity/EditableOrderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

use Sylius\Component\Core\Model\OrderInterface;

interface EditableOrderInterface extends OrderInterface, InitialTotalAwareOrderInterface
interface EditableOrderInterface extends OrderInterface
{
public function isAlreadyPaid(): bool;

public function getInitialTotal(): int;

public function setInitialTotal(int $initialTotal): void;
}
18 changes: 17 additions & 1 deletion src/Entity/EditableOrderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@

namespace Setono\SyliusOrderEditPlugin\Entity;

use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\OrderPaymentStates;

/** @method getPaymentState() */
/** @mixin OrderInterface */
trait EditableOrderTrait
{
/** @ORM\Column(type="integer") */
#[ORM\Column(type: 'integer')]
private int $initialTotal = 0;

public function isAlreadyPaid(): bool

Check warning on line 18 in src/Entity/EditableOrderTrait.php

View check run for this annotation

Codecov / codecov/patch

src/Entity/EditableOrderTrait.php#L18

Added line #L18 was not covered by tests
{
return $this->getPaymentState() === OrderPaymentStates::STATE_PAID;

Check warning on line 20 in src/Entity/EditableOrderTrait.php

View check run for this annotation

Codecov / codecov/patch

src/Entity/EditableOrderTrait.php#L20

Added line #L20 was not covered by tests
}

public function getInitialTotal(): int
{
return $this->initialTotal;
}

public function setInitialTotal(int $initialTotal): void
{
$this->initialTotal = $initialTotal;
}
}
12 changes: 0 additions & 12 deletions src/Entity/InitialTotalAwareOrderInterface.php

This file was deleted.

24 changes: 0 additions & 24 deletions src/Entity/InitialTotalAwareOrderTrait.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Setono\SyliusOrderEditPlugin\Event;

final class PaidOrderTotalChanged
final class PaidOrderUpdated
{
public function __construct(public int $orderId, public int $oldTotal, public int $newTotal)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services/order_processing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<argument type="service" id="setono_sylius_order_edit.processor.updated_order_processor" />
<argument type="service" id="setono_sylius_order_edit.checker.post_update_changes_checker" />
<argument type="service" id="doctrine.orm.entity_manager" />
<argument type="service" id="sylius.event_bus" />
<argument type="service" id="setono_sylius_order_edit.event_bus" />
</service>
</services>
</container>
4 changes: 2 additions & 2 deletions src/Updated/OrderUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Setono\SyliusOrderEditPlugin\Checker\PostUpdateChangesCheckerInterface;
use Setono\SyliusOrderEditPlugin\Entity\EditableOrderInterface;
use Setono\SyliusOrderEditPlugin\Event\OrderUpdated;
use Setono\SyliusOrderEditPlugin\Event\PaidOrderTotalChanged;
use Setono\SyliusOrderEditPlugin\Event\PaidOrderUpdated;
use Setono\SyliusOrderEditPlugin\Preparer\OrderPreparerInterface;
use Setono\SyliusOrderEditPlugin\Processor\UpdatedOrderProcessorInterface;
use Setono\SyliusOrderEditPlugin\Provider\UpdatedOrderProviderInterface;
Expand Down Expand Up @@ -40,7 +40,7 @@ public function update(Request $request, int $orderId): void

$this->eventBus->dispatch(new OrderUpdated($orderId));
if ($updatedOrder->isAlreadyPaid()) {
$this->eventBus->dispatch(new PaidOrderTotalChanged($orderId, $oldOrder->getTotal(), $updatedOrder->getTotal()));
$this->eventBus->dispatch(new PaidOrderUpdated($orderId, $oldOrder->getTotal(), $updatedOrder->getTotal()));
}
}
}
3 changes: 1 addition & 2 deletions src/Updated/OrderUpdaterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ interface OrderUpdaterInterface
{
/**
* @throws NewOrderWrongTotalException
*
* @throw \InvalidArgumentException
* @throws \InvalidArgumentException
*/
public function update(Request $request, int $orderId): void;
}
2 changes: 0 additions & 2 deletions tests/Application/src/Entity/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
use Doctrine\ORM\Mapping as ORM;
use Setono\SyliusOrderEditPlugin\Entity\EditableOrderInterface;
use Setono\SyliusOrderEditPlugin\Entity\EditableOrderTrait;
use Setono\SyliusOrderEditPlugin\Entity\InitialTotalAwareOrderTrait;

#[ORM\Entity]
#[ORM\Table(name: 'sylius_order')]
class Order extends \Sylius\Component\Core\Model\Order implements EditableOrderInterface
{
use EditableOrderTrait;
use InitialTotalAwareOrderTrait;
}
3 changes: 1 addition & 2 deletions tests/Functional/OrderUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Doctrine\ORM\EntityManagerInterface;
use Setono\SyliusOrderEditPlugin\Entity\EditableOrderInterface;
use Setono\SyliusOrderEditPlugin\Entity\InitialTotalAwareOrderInterface;
use Setono\SyliusOrderEditPlugin\Model\AdjustmentTypes;
use Sylius\Bundle\ApiBundle\Command\Cart\AddItemToCart;
use Sylius\Bundle\ApiBundle\Command\Cart\PickupCart;
Expand Down Expand Up @@ -194,7 +193,7 @@ public function testItAllowsToAddAndRemoveDiscountsForTheOrderItemMultipleTimes(
private function placeOrderProgramatically(
string $variantCode = '000F_office_grey_jeans-variant-0',
int $quantity = 1,
): Order|InitialTotalAwareOrderInterface {
): EditableOrderInterface {
/** @var MessageBusInterface $commandBus */
$commandBus = self::getContainer()->get('sylius.command_bus');

Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Checker/PostUpdateChangesCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Setono\SyliusOrderEditPlugin\Checker\PostUpdateChangesChecker;
use Setono\SyliusOrderEditPlugin\Entity\InitialTotalAwareOrderInterface;
use Setono\SyliusOrderEditPlugin\Entity\EditableOrderInterface;
use Setono\SyliusOrderEditPlugin\Exception\NewOrderWrongTotalException;
use Sylius\Component\Core\Model\OrderInterface;

Expand All @@ -24,7 +24,7 @@ public function testItThrowsExceptionIfNewOrderTotalIsBiggerThanThePreviousOne()
$newOrder = $this->prophesize(OrderInterface::class);
$newOrder->getTotal()->willReturn(1000);

$previousOrder = $this->prophesize(InitialTotalAwareOrderInterface::class);
$previousOrder = $this->prophesize(EditableOrderInterface::class);
$previousOrder->getInitialTotal()->willReturn(500);

$validator->check($previousOrder->reveal(), $newOrder->reveal());
Expand All @@ -37,7 +37,7 @@ public function testItDoesNothingIfNewOrderTotalIsSmallerThanThePreviousOne(): v
$newOrder = $this->prophesize(OrderInterface::class);
$newOrder->getTotal()->willReturn(500);

$previousOrder = $this->prophesize(InitialTotalAwareOrderInterface::class);
$previousOrder = $this->prophesize(EditableOrderInterface::class);
$previousOrder->getInitialTotal()->willReturn(1000);

$this->expectNotToPerformAssertions();
Expand All @@ -52,7 +52,7 @@ public function testItDoesNothingIfNewOrderTotalIsEqualToThePreviousOne(): void
$newOrder = $this->prophesize(OrderInterface::class);
$newOrder->getTotal()->willReturn(500);

$previousOrder = $this->prophesize(InitialTotalAwareOrderInterface::class);
$previousOrder = $this->prophesize(EditableOrderInterface::class);
$previousOrder->getInitialTotal()->willReturn(500);

$this->expectNotToPerformAssertions();
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Updater/OrderUpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Setono\SyliusOrderEditPlugin\Checker\PostUpdateChangesCheckerInterface;
use Setono\SyliusOrderEditPlugin\Entity\EditableOrderInterface;
use Setono\SyliusOrderEditPlugin\Event\OrderUpdated;
use Setono\SyliusOrderEditPlugin\Event\PaidOrderTotalChanged;
use Setono\SyliusOrderEditPlugin\Event\PaidOrderUpdated;
use Setono\SyliusOrderEditPlugin\Preparer\OrderPreparerInterface;
use Setono\SyliusOrderEditPlugin\Processor\UpdatedOrderProcessorInterface;
use Setono\SyliusOrderEditPlugin\Provider\UpdatedOrderProviderInterface;
Expand Down Expand Up @@ -62,7 +62,7 @@ public function testItUpdatesOrder(): void
$orderUpdater->update($request->reveal(), 1);
}

public function testItDispatchesAdditionalEventIfOrderWasAlreadyPaid(): void
public function testItDispatchesAdditionalEventIfOrderWasAlreadyPaidAndTheTotalChanged(): void
{
$request = $this->prophesize(Request::class);
$orderPreparer = $this->prophesize(OrderPreparerInterface::class);
Expand Down Expand Up @@ -99,8 +99,8 @@ public function testItDispatchesAdditionalEventIfOrderWasAlreadyPaid(): void
->shouldBeCalled()
;
$eventBus
->dispatch(new PaidOrderTotalChanged(1, 1000, 900))
->willReturn(new Envelope(Argument::type(PaidOrderTotalChanged::class)))
->dispatch(new PaidOrderUpdated(1, 1000, 900))
->willReturn(new Envelope(Argument::type(PaidOrderUpdated::class)))
->shouldBeCalled()
;

Expand Down

0 comments on commit e4fbb72

Please sign in to comment.