-
Notifications
You must be signed in to change notification settings - Fork 3
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 #4 from paytic/master
refactor: tests to separate folder with fixtures
- Loading branch information
Showing
8 changed files
with
236 additions
and
98 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 was deleted.
Oops, something went wrong.
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,6 @@ | ||
<?php | ||
|
||
require dirname(__DIR__, 1) . '/vendor/autoload.php'; | ||
|
||
define('BTIPAY_USERNAME', 'test_iPay4_api'); | ||
define('BTIPAY_PASSWORD', 'test_iPay4_ap!r5t'); |
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,42 @@ | ||
<?php | ||
|
||
namespace Stev\BTIPay\Tests\Fixtures\Factories; | ||
|
||
use DateTime; | ||
use Stev\BTIPay\Model\BillingInfo; | ||
use Stev\BTIPay\Model\CustomerDetails; | ||
use Stev\BTIPay\Model\Order; | ||
use Stev\BTIPay\Model\OrderBundle; | ||
|
||
class OrderFactory | ||
{ | ||
public static function basicOrder(): Order | ||
{ | ||
$currentDate = new DateTime(); | ||
$order = new Order(); | ||
$order->setOrderNumber(uniqid('F', false) . '/' . $currentDate->format('d-m-Y')) | ||
->setDescription('Plata Fact F') | ||
->setEmail('contact.webservice@gmail.com') | ||
->setAmount(1000) | ||
->setCurrencyAlpha3('RON') | ||
->setReturnUrl("https://ecclients.btrl.ro:5443/payment/merchants/Test_BT/finish.html"); | ||
|
||
$order->force3DSecure(true); | ||
|
||
$customerDetails = new CustomerDetails(); | ||
$customerDetails->setEmail('contact.webservice@gmail.com') | ||
->setPhone(40743333333) | ||
->setContact('Stefan'); | ||
|
||
$billingInfo = new BillingInfo(); | ||
$billingInfo->setCountryAlpha2('RO') | ||
->setCity('Iasi') | ||
->setPostAddress('Elena Doamna 20-22'); | ||
$customerDetails->setBillingInfo($billingInfo); | ||
|
||
$orderBundle = new OrderBundle($currentDate, $customerDetails); | ||
|
||
$order->setOrderBundle($orderBundle); | ||
return $order; | ||
} | ||
} |
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,75 @@ | ||
<?php | ||
|
||
namespace Stev\BTIPay\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Stev\BTIPay\BTIPayClient; | ||
use Stev\BTIPay\Exceptions\ValidationException; | ||
use Stev\BTIPay\Tests\Fixtures\Factories\OrderFactory; | ||
use Stev\BTIPay\Util\ActionCodes; | ||
use Stev\BTIPay\Util\ErrorCodes; | ||
|
||
final class BTIPayClientTest extends TestCase | ||
{ | ||
protected static $orderIdCreated = null; | ||
|
||
public function testRegisterSuccessful() | ||
{ | ||
$order = OrderFactory::basicOrder(); | ||
|
||
$btClient = new BTIPayClient(BTIPAY_USERNAME, BTIPAY_PASSWORD, true); | ||
|
||
try { | ||
$response = $btClient->register($order); | ||
} catch (ValidationException $exception) { | ||
$this->fail( | ||
print_r( | ||
[ | ||
'property' => $exception->getProperty(), | ||
'value' => $exception->getValue(), | ||
'message' => $exception->getMessage(), | ||
], | ||
true | ||
) | ||
); | ||
} | ||
|
||
// print_r($response); | ||
|
||
$this->assertEquals(ErrorCodes::SUCCESS, $response->getErrorCode()); | ||
$this->assertNotEmpty($response->getFormUrl()); | ||
|
||
self::$orderIdCreated = $response->getOrderId(); | ||
} | ||
|
||
public function testGetOrderStatusExtendedSuccessful() | ||
{ | ||
$btClient = new BTIPayClient(BTIPAY_USERNAME, BTIPAY_PASSWORD, true); | ||
|
||
if (self::$orderIdCreated === null) { | ||
//Run the previous test and finish the payment, then copy the orderId here | ||
$this->fail('You need to run the previous test first'); | ||
} | ||
|
||
try { | ||
$response = $btClient->getOrderStatusExtendedByOrderId(self::$orderIdCreated); | ||
} catch (ValidationException $exception) { | ||
$this->fail( | ||
print_r( | ||
[ | ||
'property' => $exception->getProperty(), | ||
'value' => $exception->getValue(), | ||
'message' => $exception->getMessage(), | ||
], | ||
true | ||
) | ||
); | ||
} | ||
|
||
// print_r($response); | ||
|
||
$this->assertEquals(ErrorCodes::SUCCESS, $response->getErrorCode()); | ||
$this->assertEquals(ActionCodes::ACTION_CODE_NO_PAYMENT_ATTEMPTS, $response->getActionCode()); | ||
} | ||
|
||
} |
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,54 @@ | ||
<?php | ||
|
||
namespace Stev\BTIPay\Tests\Model; | ||
|
||
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy; | ||
use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; | ||
use JMS\Serializer\SerializationContext; | ||
use JMS\Serializer\SerializerBuilder; | ||
use PHPUnit\Framework\TestCase; | ||
use Stev\BTIPay\Tests\Fixtures\Factories\OrderFactory; | ||
|
||
use function PHPUnit\Framework\assertSame; | ||
|
||
class OrderTest extends TestCase | ||
{ | ||
public function testSerialize() | ||
{ | ||
$order = OrderFactory::basicOrder(); | ||
$order->setOrderNumber('F661eaee8bf2a7/16-04-2024'); | ||
$order->setUsername(BTIPAY_USERNAME); | ||
$order->setPassword(BTIPAY_PASSWORD); | ||
|
||
$serializer = SerializerBuilder::create() | ||
->setPropertyNamingStrategy(new SerializedNameAnnotationStrategy(new IdenticalPropertyNamingStrategy())) | ||
->setSerializationContextFactory( | ||
function () { | ||
return SerializationContext::create() | ||
->setSerializeNull(false); | ||
} | ||
) | ||
->build(); | ||
|
||
$orderJson = $serializer->serialize($order, 'json'); | ||
assertSame( | ||
'{"userName":"test_iPay4_api","password":"test_iPay4_ap!r5t","orderNumber":"F661eaee8bf2a7\/16-04-2024","amount":1000,"currency":"946","returnUrl":"https:\/\/ecclients.btrl.ro:5443\/payment\/merchants\/Test_BT\/finish.html","description":"Plata Fact F","pageView":"DESKTOP","email":"contact.webservice@gmail.com"}', | ||
$orderJson | ||
); | ||
$requestData = $serializer->deserialize($orderJson, 'array', 'json'); | ||
assertSame( | ||
[ | ||
'userName' => 'test_iPay4_api', | ||
'password' => 'test_iPay4_ap!r5t', | ||
'orderNumber' => 'F661eaee8bf2a7/16-04-2024', | ||
'amount' => 1000, | ||
'currency' => '946', | ||
'returnUrl' => 'https://ecclients.btrl.ro:5443/payment/merchants/Test_BT/finish.html', | ||
'description' => 'Plata Fact F', | ||
'pageView' => 'DESKTOP', | ||
'email' => 'contact.webservice@gmail.com', | ||
], | ||
$requestData | ||
); | ||
} | ||
} |