-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API][Payments] change endpoints and add missing specs
- Loading branch information
Showing
10 changed files
with
132 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/Sylius/Bundle/ApiBundle/spec/CommandHandler/ChangePaymentMethodHandlerSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?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 spec\Sylius\Bundle\ApiBundle\CommandHandler; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Bundle\ApiBundle\Command\ChangePaymentMethod; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
use Sylius\Component\Core\Model\PaymentMethodInterface; | ||
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface; | ||
use Sylius\Component\Core\Repository\PaymentRepositoryInterface; | ||
|
||
final class ChangePaymentMethodHandlerSpec extends ObjectBehavior | ||
{ | ||
function let( | ||
PaymentMethodRepositoryInterface $paymentMethodRepository, | ||
PaymentRepositoryInterface $paymentRepository | ||
): void { | ||
$this->beConstructedWith($paymentMethodRepository, $paymentRepository); | ||
} | ||
|
||
function it_changes_payment_method_to_specified_payment( | ||
PaymentMethodRepositoryInterface $paymentMethodRepository, | ||
PaymentMethodInterface $paymentMethod, | ||
PaymentRepositoryInterface $paymentRepository, | ||
PaymentInterface $payment | ||
): void { | ||
$changePaymentMethod = new ChangePaymentMethod('CASH_ON_DELIVERY_METHOD'); | ||
$changePaymentMethod->setPaymentId('123'); | ||
$paymentMethodRepository->findOneBy(['code' =>'CASH_ON_DELIVERY_METHOD'])->willReturn($paymentMethod); | ||
|
||
$paymentRepository->find('123')->willReturn($payment); | ||
|
||
$payment->getState()->willReturn(PaymentInterface::STATE_NEW); | ||
$payment->setMethod($paymentMethod)->shouldBeCalled(); | ||
|
||
$this($changePaymentMethod)->shouldReturn($payment); | ||
} | ||
|
||
function it_throws_an_exception_if_payment_method_with_given_code_has_not_been_found( | ||
PaymentMethodRepositoryInterface $paymentMethodRepository | ||
): void { | ||
$changePaymentMethod = new ChangePaymentMethod('CASH_ON_DELIVERY_METHOD'); | ||
$changePaymentMethod->setPaymentId('123'); | ||
$paymentMethodRepository->findOneBy(['code' =>'CASH_ON_DELIVERY_METHOD'])->willReturn(null); | ||
|
||
$this | ||
->shouldThrow(\InvalidArgumentException::class) | ||
->during('__invoke', [$changePaymentMethod]) | ||
; | ||
} | ||
|
||
function it_throws_an_exception_if_payment_has_not_be_found( | ||
PaymentMethodRepositoryInterface $paymentMethodRepository, | ||
PaymentMethodInterface $paymentMethod, | ||
PaymentRepositoryInterface $paymentRepository | ||
): void { | ||
$changePaymentMethod = new ChangePaymentMethod('CASH_ON_DELIVERY_METHOD'); | ||
$changePaymentMethod->setPaymentId('123'); | ||
$paymentMethodRepository->findOneBy(['code' =>'CASH_ON_DELIVERY_METHOD'])->willReturn($paymentMethod); | ||
|
||
$paymentRepository->find('123')->willReturn(null); | ||
|
||
$this | ||
->shouldThrow(\InvalidArgumentException::class) | ||
->during('__invoke', [$changePaymentMethod]) | ||
; | ||
} | ||
|
||
function it_throws_an_exception_if_payment_is_in_different_state_than_new( | ||
PaymentMethodRepositoryInterface $paymentMethodRepository, | ||
PaymentMethodInterface $paymentMethod, | ||
PaymentRepositoryInterface $paymentRepository, | ||
PaymentInterface $payment | ||
): void | ||
{ | ||
$changePaymentMethod = new ChangePaymentMethod('CASH_ON_DELIVERY_METHOD'); | ||
$changePaymentMethod->setPaymentId('123'); | ||
$paymentMethodRepository->findOneBy(['code' => 'CASH_ON_DELIVERY_METHOD'])->willReturn($paymentMethod); | ||
|
||
$paymentRepository->find('123')->willReturn($payment); | ||
|
||
$payment->getState()->willReturn(PaymentInterface::STATE_CANCELLED); | ||
|
||
$this | ||
->shouldThrow(\InvalidArgumentException::class) | ||
->during('__invoke', [$changePaymentMethod]) | ||
; | ||
} | ||
} |