Skip to content

Commit

Permalink
Added additional test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
paypay-ayas committed Sep 29, 2020
1 parent 2639859 commit 8e1356b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
10 changes: 10 additions & 0 deletions tests/ContinuousPaymentTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use PayPay\OpenPaymentAPI\Models\CreateContinuousPaymentPayload;
use PayPay\OpenPaymentAPI\Models\ModelException;

require_once('TestBoilerplate.php');
final class ContinuousPaymentTest extends TestBoilerplate
Expand Down Expand Up @@ -57,4 +58,13 @@ public function testCreateAndCancel()
$this->Create();
$this->Cancel();
}
public function testBadPayloadFailure()
{
try {
$this->client->payment->createContinuousPayment(2);
} catch (ModelException $e) {
$this->assertStringContainsString("Payload not of type CreateContinuousPaymentPayload",$e->getMessage());
}

}
}
8 changes: 5 additions & 3 deletions tests/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ final class PaymentTest extends TestBoilerplate
*
* @return void
*/
public function Create()
public function Create($similar=false)
{
$client = $this->client;
$CPPayload = new CreatePaymentPayload();
// Save Cart totals
$amount = [
"amount" => 12,
"amount" => $similar?12:rand(5,10),
"currency" => "JPY"
];
$CPPayload->setMerchantPaymentId(uniqid('TESTMERCH_PAY_ID'))->setRequestedAt()->setUserAuthorizationId($this->config['uaid'])->setAmount($amount);
// Get data for QR code
$resp = $client->payment->createPayment($CPPayload,true);
$resp = $client->payment->createPayment($CPPayload,$similar);
$resultInfo = $resp['resultInfo'];
$this->assertEquals('SUCCESS', $resultInfo['code']);
$data = $resp['data'];
Expand Down Expand Up @@ -52,5 +52,7 @@ public function testCreateAndCancel()
{
$this->Create();
$this->Cancel();
$this->Create(true);
$this->Cancel();
}
}
10 changes: 10 additions & 0 deletions tests/PendingPaymentTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use PayPay\OpenPaymentAPI\Models\CreateContinuousPaymentPayload;
use PayPay\OpenPaymentAPI\Models\ModelException;
use PayPay\OpenPaymentAPI\Models\RefundPaymentPayload;

require_once 'TestBoilerplate.php' ;
Expand Down Expand Up @@ -122,4 +123,13 @@ public function testRefund()
$this->refund();
$this->refundDetails();
}
public function testBadPayloadFailure()
{
try {
$this->client->payment->createPendingPayment(2);
} catch (ModelException $e) {
$this->assertStringContainsString("Payload not of type CreatePendingPaymentPayload",$e->getMessage());
}

}
}
8 changes: 4 additions & 4 deletions tests/PreAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class PreAuthTest extends TestBoilerplate
{


public function Create()
public function Create($similiar=true)
{
$CPApayload = new CreatePaymentAuthPayload();
$CPApayload->setMerchantPaymentId(uniqid('TEST_PREAUTH'))
->setUserAuthorizationId($this->config['uaid'])
->setAmount(['amount' => 20, 'currency' => 'JPY'])
->setAmount(['amount' => $similiar?20:rand(5,17), 'currency' => 'JPY'])
->setRequestedAt();
$resp = $this->client->payment->createPaymentAuth($CPApayload, true);
$resp = $this->client->payment->createPaymentAuth($CPApayload, $similiar);
var_dump($resp);
$this->assertTrue(isset($resp['resultInfo']));
$this->assertEquals('SUCCESS', $resp['resultInfo']['code'], $resp['resultInfo']['message'] );
Expand Down Expand Up @@ -85,7 +85,7 @@ public function testPreauthCapture()
*/
public function testPreauthRevert()
{
$this->Create();
$this->Create(false);
$this->RevertAuthorization();
}
}

0 comments on commit 8e1356b

Please sign in to comment.