generated from Sylius/PluginSkeleton
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from BitBagCommerce/op263-dev
OP-263 - Added phpSpec tests, enabled phpStan and ECS, fixed GitHub actions
- Loading branch information
Showing
30 changed files
with
937 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\BitBag\SyliusImojePlugin\Action; | ||
|
||
use BitBag\SyliusImojePlugin\Api\ImojeApi; | ||
use BitBag\SyliusImojePlugin\Api\ImojeApiInterface; | ||
use BitBag\SyliusImojePlugin\Resolver\SignatureResolverInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Reply\HttpPostRedirect; | ||
use Payum\Core\Request\Capture; | ||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Bundle\PayumBundle\Model\PaymentSecurityTokenInterface; | ||
use Sylius\Component\Core\Model\AddressInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
use Sylius\Component\Customer\Model\CustomerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class CaptureActionSpec extends ObjectBehavior | ||
{ | ||
public function let( | ||
SignatureResolverInterface $signatureResolver, | ||
): void { | ||
$this->beConstructedWith($signatureResolver); | ||
} | ||
|
||
public function it_should_return_true_when_request_and_model_is_valid( | ||
Capture $request, | ||
ArrayObject $arrayObject, | ||
): void { | ||
$request->getModel()->willReturn($arrayObject); | ||
|
||
$this->supports($request)->shouldReturn(true); | ||
} | ||
|
||
public function it_should_return_false_when_model_is_invalid( | ||
Capture $request, | ||
): void { | ||
$request->getModel()->willReturn(null); | ||
|
||
$this->supports($request)->shouldReturn(false); | ||
} | ||
|
||
public function it_should_return_false_when_request_is_not_a_capture_instance( | ||
Request $request, | ||
): void { | ||
$this->supports($request)->shouldReturn(false); | ||
} | ||
|
||
public function it_executes_correctly_with_valid_request( | ||
Capture $request, | ||
OrderInterface $order, | ||
PaymentInterface $payment, | ||
PaymentSecurityTokenInterface $token, | ||
AddressInterface $address, | ||
CustomerInterface $customer, | ||
ImojeApi $apiClass, | ||
SignatureResolverInterface $signatureResolver, | ||
): void { | ||
$data = ['statusImoje' => ImojeApiInterface::NEW_STATUS, 'paymentId' => 123, 'tokenHash' => '1234sdcsdfxz']; | ||
$request->getModel()->willReturn(new ArrayObject($data)); | ||
|
||
$request->getToken()->willReturn('1234sdcsdfxz'); | ||
$request->getFirstModel()->willReturn($payment); | ||
$request->getToken()->willReturn($token); | ||
|
||
$payment->getOrder()->willReturn($order); | ||
$payment->getId()->willReturn(123); | ||
|
||
$token->getHash()->willReturn('1234sdcsdfxz'); | ||
|
||
$apiClass->getServiceKey()->willReturn('1234sdcsdfxz'); | ||
$order->getBillingAddress()->willReturn($address); | ||
$order->getCustomer()->willReturn($customer); | ||
|
||
$apiClass->getApiUrl()->willReturn('http://example.com/'); | ||
|
||
$apiClass->getServiceId()->willReturn('1'); | ||
$apiClass->getMerchantId()->willReturn('1'); | ||
$order->getTotal()->willReturn(1000); | ||
$order->getCurrencyCode()->willReturn('EUR'); | ||
$order->getNumber()->willReturn('123'); | ||
$address->getFirstName()->willReturn('John Doe'); | ||
$address->getLastName()->willReturn('Smith'); | ||
$token->getAfterUrl()->willReturn('http://example.com/'); | ||
$customer->getEmail()->willReturn('[email protected]'); | ||
|
||
$orderData = [ | ||
'serviceId' => '1', | ||
'merchantId' => '1', | ||
'amount' => 1000, | ||
'currency' => 'EUR', | ||
'orderId' => '123', | ||
'customerFirstName' => 'John Doe', | ||
'customerLastName' => 'Smith', | ||
'urlReturn' => 'http://example.com/', | ||
'customerEmail' => '[email protected]', | ||
]; | ||
|
||
$signatureResolver->createSignature($orderData, '1234sdcsdfxz') | ||
->willReturn('signature'); | ||
|
||
$request->setModel(new ArrayObject($data))->shouldBeCalled(); | ||
|
||
$this->setApi($apiClass); | ||
$this->shouldThrow(HttpPostRedirect::class) | ||
->during('execute', [$request]); | ||
} | ||
} |
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,108 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\BitBag\SyliusImojePlugin\Action; | ||
|
||
use BitBag\SyliusImojePlugin\Action\ConvertPaymentAction; | ||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Model\PaymentInterface; | ||
use Payum\Core\Request\Convert; | ||
use PhpSpec\ObjectBehavior; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class ConvertPaymentActionSpec extends ObjectBehavior | ||
{ | ||
public function it_is_initializable(): void | ||
{ | ||
$this->shouldHaveType(ConvertPaymentAction::class); | ||
} | ||
|
||
function it_implements_imoje_gateway_factory_interface(): void | ||
{ | ||
$this->shouldHaveType(ActionInterface::class); | ||
} | ||
|
||
public function it_sets_result_from_payment_details_with_non_empty_details( | ||
Convert $request, | ||
PaymentInterface $payment, | ||
): void { | ||
$request->getSource()->willReturn($payment); | ||
$payment->getDetails()->willReturn(['field' => '123']); | ||
$request->setResult(['field' => '123'])->shouldBeCalled(); | ||
|
||
$this->execute($request); | ||
} | ||
|
||
public function it_sets_empty_result_when_payment_details_are_empty( | ||
Convert $request, | ||
PaymentInterface $payment, | ||
): void { | ||
$payment->getDetails()->willReturn([]); | ||
$request->getSource()->willReturn($payment); | ||
$request->setResult([])->shouldBeCalled(); | ||
|
||
$this->execute($request); | ||
} | ||
|
||
public function it_sets_result_when_payment_details_contain_null( | ||
Convert $request, | ||
PaymentInterface $payment, | ||
): void { | ||
$payment->getDetails()->willReturn(['key' => null]); | ||
$request->getSource()->willReturn($payment); | ||
$request->setResult(['key' => null])->shouldBeCalled(); | ||
|
||
$this->execute($request); | ||
} | ||
|
||
public function it_should_return_true_when_getTo_and_source_is_valid( | ||
Convert $request, | ||
PaymentInterface $payment, | ||
): void { | ||
$request->getSource()->willReturn($payment); | ||
$request->getTo()->willReturn('array'); | ||
|
||
$this->supports($request)->shouldReturn(true); | ||
} | ||
|
||
public function it_should_return_false_when_source_is_invalid( | ||
Convert $request, | ||
): void { | ||
$request->getSource()->willReturn(null); | ||
$request->getTo()->willReturn('array'); | ||
|
||
$this->supports($request)->shouldReturn(false); | ||
} | ||
|
||
public function it_should_return_false_when_getTo_is_invalid( | ||
Convert $request, | ||
PaymentInterface $payment, | ||
): void { | ||
$request->getSource()->willReturn($payment); | ||
$request->getTo()->willReturn('object'); | ||
|
||
$this->supports($request)->shouldReturn(false); | ||
} | ||
|
||
public function it_should_return_false_when_getTo_and_source_is_invalid( | ||
Convert $request, | ||
): void { | ||
$request->getSource()->willReturn(null); | ||
$request->getTo()->willReturn('object'); | ||
|
||
$this->supports($request)->shouldReturn(false); | ||
} | ||
|
||
public function it_should_return_false_when_request_invalid( | ||
Request $request, | ||
): void { | ||
$this->supports($request)->shouldReturn(false); | ||
} | ||
} |
Oops, something went wrong.