Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
voronkovich committed Aug 29, 2021
1 parent 513e083 commit 3f02051
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ public function testRegistersANewOrder()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/register.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'currency=330&orderNumber=eee-eee-eee&amount=1200&returnUrl=https%3A%2F%2Fgithub.com%2Fvoronkovich%2Fsberbank-acquiring-client&token=abrakadabra'
);

Expand All @@ -255,6 +257,8 @@ public function testRegistersANewOrderWithCustomPrefix()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/other/prefix/register.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'currency=330&orderNumber=eee-eee-eee&amount=1200&returnUrl=https%3A%2F%2Fgithub.com%2Fvoronkovich%2Fsberbank-acquiring-client&token=abrakadabra'
);

Expand All @@ -271,6 +275,8 @@ public function testRegisterANewPreAuthorizedOrder()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/registerPreAuth.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'currency=330&orderNumber=eee-eee-eee&amount=1200&returnUrl=https%3A%2F%2Fgithub.com%2Fvoronkovich%2Fsberbank-acquiring-client&token=abrakadabra'
);

Expand All @@ -286,6 +292,8 @@ public function testRegistersANewCreditOrder()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/sbercredit/register.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'currency=643&orderNumber=aaa-aaa-aaa&amount=50000&returnUrl=https%3A%2F%2Fgithub.com%2Fvoronkovich%2Fsberbank-acquiring-client&token=secret'
);

Expand All @@ -303,6 +311,8 @@ public function testRegistersANewCreditOrderWithCustomPrefix()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/custom/credit/register.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'currency=643&orderNumber=aaa-aaa-aaa&amount=50000&returnUrl=https%3A%2F%2Fgithub.com%2Fvoronkovich%2Fsberbank-acquiring-client&token=secret'
);

Expand All @@ -321,6 +331,8 @@ public function testRegistersANewPreAuthorizedCreditOrder()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/sbercredit/registerPreAuth.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'currency=643&orderNumber=aaa-aaa-aaa&amount=50000&returnUrl=https%3A%2F%2Fgithub.com%2Fvoronkovich%2Fsberbank-acquiring-client&token=secret'
);

Expand Down Expand Up @@ -359,6 +371,8 @@ public function testEncodesToJSONAnOrderBundleParameter()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/register.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'orderBundle=%7B%22items%22%3A%5B%22item1%22%2C%22item2%22%5D%7D&orderNumber=1&amount=1&returnUrl=returnUrl&token=abc'
);

Expand All @@ -381,6 +395,8 @@ public function testDepositsAPreAuthorizedOrder()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/deposit.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'currency=810&orderId=aaa-bbb-yyy&amount=1000&token=abrakadabra'
);

Expand All @@ -396,6 +412,8 @@ public function testReversesAnOrder()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/reverse.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'currency=480&orderId=aaa-bbb-yyy&token=abrakadabra'
);

Expand All @@ -411,6 +429,8 @@ public function testRefundsAnOrder()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/refund.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'currency=456&orderId=aaa-bbb-yyy&amount=5050&token=abrakadabra'
);

Expand All @@ -426,6 +446,8 @@ public function testGetsAnOrderStatus()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/rest/getOrderStatusExtended.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'currency=100&orderId=aaa-bbb-yyy&token=abrakadabra'
);

Expand All @@ -441,6 +463,8 @@ public function testGetsAnOrderStatusByOwnId()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/rest/getOrderStatusExtended.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'currency=100&orderNumber=111&token=abrakadabra'
);

Expand All @@ -456,6 +480,8 @@ public function testVerifiesACardEnrollment()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/verifyEnrollment.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'currency=200&pan=aaazzz&token=abrakadabra'
);

Expand All @@ -474,6 +500,8 @@ public function testUpdatesAnSSLCardList()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/updateSSLCardList.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'mdorder=aaazzz&token=abrakadabra'
);

Expand All @@ -489,6 +517,8 @@ public function testPaysAnOrderUsingBinding()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/paymentOrderBinding.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'language=en&mdOrder=xxx-yyy-zzz&bindingId=600&token=abrakadabra'
);

Expand All @@ -504,6 +534,8 @@ public function testBindsACard()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/bindCard.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'language=ru&bindingId=bbb000&token=abrakadabra'
);

Expand All @@ -519,6 +551,8 @@ public function testUnbindsACard()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/unBindCard.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'language=en&bindingId=uuu800&token=abrakadabra'
);

Expand All @@ -534,6 +568,8 @@ public function testExtendsABinding()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/extendBinding.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'language=ru&bindingId=eeeB00&newExpiry=203009&token=abrakadabra'
);

Expand All @@ -549,6 +585,8 @@ public function testGetsBindings()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/getBindings.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'language=ru&clientId=clientIDABC&token=abrakadabra'
);

Expand All @@ -564,6 +602,8 @@ public function testGetsARepceiptStatus()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/rest/getReceiptStatus.do',
'POST',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'uuid=ffff&language=ru&token=abrakadabra'
);

Expand All @@ -582,6 +622,8 @@ public function testPaysWithAnApplePay()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/applepay/payment.do',
'POST',
[ 'Content-Type' => 'application/json' ],
'{"language":"en","orderNumber":"eee-eee","merchant":"my_merchant","paymentToken":"token_zzz"}'
);

Expand All @@ -600,6 +642,8 @@ public function testPaysWithAnApplePayWithCustomPrefix()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/other/prefix/payment.do',
'POST',
[ 'Content-Type' => 'application/json' ],
'{"language":"en","orderNumber":"eee-eee","merchant":"my_merchant","paymentToken":"token_zzz"}'
);

Expand All @@ -619,6 +663,8 @@ public function testPaysWithAGooglePay()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/google/payment.do',
'POST',
[ 'Content-Type' => 'application/json' ],
'{"language":"en","orderNumber":"eee-eee","merchant":"my_merchant","paymentToken":"token_zzz"}'
);

Expand All @@ -637,6 +683,8 @@ public function testPaysWithAGooglePayWithCustomPrefix()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/other/prefix/google/payment.do',
'POST',
[ 'Content-Type' => 'application/json' ],
'{"language":"en","orderNumber":"eee-eee","merchant":"my_merchant","paymentToken":"token_zzz"}'
);

Expand All @@ -656,6 +704,8 @@ public function testPaysWithASamsungPay()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/payment/samsung/payment.do',
'POST',
[ 'Content-Type' => 'application/json' ],
'{"language":"en","orderNumber":"eee-eee","merchant":"my_merchant","paymentToken":"token_zzz"}'
);

Expand All @@ -674,6 +724,8 @@ public function testPaysWithASamsungPayWithCustomPrefix()
{
$httpClient = $this->getHttpClientToTestSendingData(
'/other/prefix/sumsung/payment.do',
'POST',
[ 'Content-Type' => 'application/json' ],
'{"language":"en","orderNumber":"eee-eee","merchant":"my_merchant","paymentToken":"token_zzz"}'
);

Expand Down Expand Up @@ -721,14 +773,19 @@ private function mockHttpClient(array $response = null)
return $httpClient;
}

private function getHttpClientToTestSendingData(string $uri, string $data)
private function getHttpClientToTestSendingData(string $uri, string $method, array $headers = [], string $data = '')
{
$httpClient = $this->mockHttpClient();

$httpClient
->expects($this->once())
->method('request')
->with($this->stringEndsWith($uri), $this->anything(), $this->anything(), $this->equalTo($data))
->with(
$this->stringEndsWith($uri),
$this->equalTo($method),
$this->equalTo($headers),
$this->equalTo($data)
)
;

return $httpClient;
Expand Down

0 comments on commit 3f02051

Please sign in to comment.