Skip to content

Commit

Permalink
add iterface to refundUnits command
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp committed Jun 15, 2021
1 parent b859763 commit 9beecc2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
3 changes: 2 additions & 1 deletion spec/Creator/RefundUnitsCommandCreatorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpSpec\ObjectBehavior;
use Sylius\RefundPlugin\Calculator\UnitRefundTotalCalculatorInterface;
use Sylius\RefundPlugin\Command\RefundUnits;
use Sylius\RefundPlugin\Command\RefundUnitsInterface;
use Sylius\RefundPlugin\Creator\RefundUnitsCommandCreatorInterface;
use Sylius\RefundPlugin\Model\OrderItemUnitRefund;
use Sylius\RefundPlugin\Model\RefundType;
Expand Down Expand Up @@ -120,7 +121,7 @@ public function it_throws_exception_if_there_is_no_order_number_provided(Request
public function getMatchers(): array
{
return [
'returnCommand' => function (RefundUnits $command, RefundUnits $expectedCommand): bool {
'returnCommand' => function (RefundUnitsInterface $command, RefundUnitsInterface $expectedCommand): bool {
return
$command->orderNumber() === $expectedCommand->orderNumber() &&
$command->units() == $expectedCommand->units() &&
Expand Down
2 changes: 1 addition & 1 deletion src/Command/RefundUnits.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Sylius\RefundPlugin\Model\ShipmentRefund;
use Webmozart\Assert\Assert;

class RefundUnits
class RefundUnits implements RefundUnitsInterface
{
/** @var string */
private $orderNumber;
Expand Down
32 changes: 32 additions & 0 deletions src/Command/RefundUnitsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\RefundPlugin\Command;

use Sylius\RefundPlugin\Model\OrderItemUnitRefund;
use Sylius\RefundPlugin\Model\ShipmentRefund;

interface RefundUnitsInterface
{
public function orderNumber(): string;

/** @return array|OrderItemUnitRefund[] */
public function units(): array;

/** @return array|ShipmentRefund[] */
public function shipments(): array;

public function paymentMethodId(): int;

public function comment(): string;
}
3 changes: 2 additions & 1 deletion src/Creator/RefundUnitsCommandCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Sylius\RefundPlugin\Calculator\UnitRefundTotalCalculatorInterface;
use Sylius\RefundPlugin\Command\RefundUnits;
use Sylius\RefundPlugin\Command\RefundUnitsInterface;
use Sylius\RefundPlugin\Exception\InvalidRefundAmount;
use Sylius\RefundPlugin\Model\OrderItemUnitRefund;
use Sylius\RefundPlugin\Model\RefundType;
Expand All @@ -33,7 +34,7 @@ public function __construct(UnitRefundTotalCalculatorInterface $unitRefundTotalC
$this->unitRefundTotalCalculator = $unitRefundTotalCalculator;
}

public function fromRequest(Request $request): RefundUnits
public function fromRequest(Request $request): RefundUnitsInterface
{
Assert::true($request->attributes->has('orderNumber'), 'Refunded order number not provided');

Expand Down
4 changes: 2 additions & 2 deletions src/Creator/RefundUnitsCommandCreatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

namespace Sylius\RefundPlugin\Creator;

use Sylius\RefundPlugin\Command\RefundUnits;
use Sylius\RefundPlugin\Command\RefundUnitsInterface;
use Symfony\Component\HttpFoundation\Request;

interface RefundUnitsCommandCreatorInterface
{
public function fromRequest(Request $request): RefundUnits;
public function fromRequest(Request $request): RefundUnitsInterface;
}

0 comments on commit 9beecc2

Please sign in to comment.