Skip to content

Commit

Permalink
Merge pull request #277 from TransbankDevelopers/test/add-unit-tests
Browse files Browse the repository at this point in the history
test: add unit tests
  • Loading branch information
tribiec authored Apr 24, 2024
2 parents 7d72067 + 9ad6ab2 commit 4024c53
Show file tree
Hide file tree
Showing 27 changed files with 1,130 additions and 0 deletions.
75 changes: 75 additions & 0 deletions tests/BaseDeferredStatusResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
use PHPUnit\Framework\TestCase;
use Transbank\Common\Responses\BaseDeferredStatusResponse;

class BaseDeferredStatusResponseTest extends TestCase
{
public function testGetAuthorizationCode()
{
$response = new BaseDeferredStatusResponse(['authorization_code' => '123456']);
$this->assertEquals('123456', $response->authorizationCode);
}

public function testSetAuthorizationCode()
{
$response = new BaseDeferredStatusResponse([]);
$response->setAuthorizationCode('123456');
$this->assertEquals('123456', $response->authorizationCode);
}

public function testGetAuthorizationDate()
{
$date = date('Y-m-d');
$response = new BaseDeferredStatusResponse(['authorization_date' => $date]);
$this->assertEquals($date, $response->authorizationDate);
}

public function testSetAuthorizationDate()
{
$date = date('Y-m-d');
$response = new BaseDeferredStatusResponse([]);
$response->setAuthorizationDate($date);
$this->assertEquals($date, $response->authorizationDate);
}

public function testGetTotalAmount()
{
$response = new BaseDeferredStatusResponse(['total_amount' => 100.00]);
$this->assertEquals(100.00, $response->totalAmount);
}

public function testSetTotalAmount()
{
$response = new BaseDeferredStatusResponse([]);
$response->setTotalAmount(100.00);
$this->assertEquals(100.00, $response->totalAmount);
}

public function testGetExpirationDate()
{
$date = date('Y-m-d');
$response = new BaseDeferredStatusResponse(['expiration_date' => $date]);
$this->assertEquals($date, $response->expirationDate);
}

public function testSetExpirationDate()
{
$date = date('Y-m-d');
$response = new BaseDeferredStatusResponse([]);
$response->setExpirationDate($date);
$this->assertEquals($date, $response->expirationDate);
}

public function testGetResponseCode()
{
$response = new BaseDeferredStatusResponse(['response_code' => '00']);
$this->assertEquals('00', $response->responseCode);
}

public function testSetResponseCode()
{
$response = new BaseDeferredStatusResponse([]);
$response->setResponseCode('00');
$this->assertEquals('00', $response->responseCode);
}
}
84 changes: 84 additions & 0 deletions tests/Patpass/ByWebpay/Responses/TransactionCommitResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

use PHPUnit\Framework\TestCase;
use Transbank\Patpass\PatpassByWebpay\Responses\TransactionCommitResponse;

class TransactionCommitResponseTest extends TestCase
{
public function testSetAndGetVci()
{
$transactionCommitResponse = new TransactionCommitResponse([]);
$transactionCommitResponse->setVci('testVci');
$this->assertSame('testVci', $transactionCommitResponse->getVci());
}

public function testSetAndGetAmount()
{
$transactionCommitResponse = new TransactionCommitResponse([]);
$transactionCommitResponse->setAmount(100);
$this->assertSame(100, $transactionCommitResponse->getAmount());
}

public function testSetAndGetStatus()
{
$transactionCommitResponse = new TransactionCommitResponse([]);
$transactionCommitResponse->setStatus('testStatus');
$this->assertSame('testStatus', $transactionCommitResponse->getStatus());
}

public function testSetAndGetBuyOrder()
{
$transactionCommitResponse = new TransactionCommitResponse([]);
$transactionCommitResponse->setBuyOrder('testBuyOrder');
$this->assertSame('testBuyOrder', $transactionCommitResponse->getBuyOrder());
}

public function testSetAndGetSessionId()
{
$transactionCommitResponse = new TransactionCommitResponse([]);
$transactionCommitResponse->setSessionId('testSessionId');
$this->assertSame('testSessionId', $transactionCommitResponse->getSessionId());
}

public function testSetAndGetCardDetail()
{
$transactionCommitResponse = new TransactionCommitResponse([]);
$transactionCommitResponse->setCardDetail('testCardDetail');
$this->assertSame('testCardDetail', $transactionCommitResponse->getCardDetail());
}

public function testSetAndGetAccountingDate()
{
$transactionCommitResponse = new TransactionCommitResponse([]);
$transactionCommitResponse->setAccountingDate('testAccountingDate');
$this->assertSame('testAccountingDate', $transactionCommitResponse->getAccountingDate());
}

public function testSetAndGetTransactionDate()
{
$transactionCommitResponse = new TransactionCommitResponse([]);
$transactionCommitResponse->setTransactionDate('testTransactionDate');
$this->assertSame('testTransactionDate', $transactionCommitResponse->getTransactionDate());
}

public function testSetAndGetAuthorizationCode()
{
$transactionCommitResponse = new TransactionCommitResponse([]);
$transactionCommitResponse->setAuthorizationCode('testAuthorizationCode');
$this->assertSame('testAuthorizationCode', $transactionCommitResponse->getAuthorizationCode());
}

public function testSetAndGetPaymentTypeCode()
{
$transactionCommitResponse = new TransactionCommitResponse([]);
$transactionCommitResponse->setPaymentTypeCode('testPaymentTypeCode');
$this->assertSame('testPaymentTypeCode', $transactionCommitResponse->getPaymentTypeCode());
}

public function testSetAndGetInstallmentsNumber()
{
$transactionCommitResponse = new TransactionCommitResponse([]);
$transactionCommitResponse->setInstallmentsNumber(3);
$this->assertSame(3, $transactionCommitResponse->getInstallmentsNumber());
}
}
52 changes: 52 additions & 0 deletions tests/Patpass/ByWebpay/Responses/TransactionCreateResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

use PHPUnit\Framework\TestCase;
use Transbank\Patpass\PatpassByWebpay\Responses\TransactionCreateResponse;

class TransactionCreateResponseTest extends TestCase
{
/** @test */
public function it_can_create_instance_from_json()
{
$json = [
'token' => 'testToken',
'url' => 'testUrl'
];

$response = new TransactionCreateResponse($json);

$this->assertSame('testToken', $response->getToken());
$this->assertSame('testUrl', $response->getUrl());
}

/** @test */
public function it_returns_null_when_key_does_not_exist_in_json()
{
$json = [
'token' => 'testToken'
];

$response = new TransactionCreateResponse($json);

$this->assertSame('testToken', $response->getToken());
$this->assertNull($response->getUrl());
}

/** @test */
public function it_can_set_and_get_token()
{
$response = new TransactionCreateResponse([]);
$response->setToken('testToken');

$this->assertSame('testToken', $response->getToken());
}

/** @test */
public function it_can_set_and_get_url()
{
$response = new TransactionCreateResponse([]);
$response->setUrl('testUrl');

$this->assertSame('testUrl', $response->getUrl());
}
}
47 changes: 47 additions & 0 deletions tests/Patpass/Comercio/Responses/InscriptionFinishResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

use PHPUnit\Framework\TestCase;
use Transbank\Patpass\PatpassComercio\Responses\InscriptionFinishResponse;

class PatpassInscriptionFinishResponseTest extends TestCase
{
/** @test */
public function it_sets_status_to_ok_when_http_code_is_204()
{
$response = new InscriptionFinishResponse(204);
$this->assertSame('OK', $response->status);
$this->assertSame(204, $response->code);
}

/** @test */
public function it_sets_status_to_not_found_when_http_code_is_404()
{
$response = new InscriptionFinishResponse(404);
$this->assertSame('Not Found', $response->status);
$this->assertSame(404, $response->code);
}

/** @test */
public function it_sets_status_to_null_when_http_code_is_not_204_or_404()
{
$response = new InscriptionFinishResponse(500);
$this->assertNull($response->status);
$this->assertSame(500, $response->code);
}

/** @test */
public function it_can_set_and_get_status()
{
$response = new InscriptionFinishResponse(200);
$response->setStatus('OK');
$this->assertSame('OK', $response->getStatus());
}

/** @test */
public function it_can_set_and_get_code()
{
$response = new InscriptionFinishResponse(204);
$response->setCode(204);
$this->assertSame(204, $response->getCode());
}
}
23 changes: 23 additions & 0 deletions tests/Patpass/Comercio/Responses/InscriptionStartResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use PHPUnit\Framework\TestCase;
use Transbank\Patpass\PatpassComercio\Responses\InscriptionStartResponse;

class InscriptionStartResponseTest extends TestCase
{
/** @test */
public function it_can_set_and_get_token()
{
$response = new InscriptionStartResponse([]);
$response->setToken('testToken');
$this->assertSame('testToken', $response->getToken());
}

/** @test */
public function it_can_set_and_get_url_webpay()
{
$response = new InscriptionStartResponse([]);
$response->setUrlWebpay('testUrl');
$this->assertSame('testUrl', $response->getUrlWebpay());
}
}
48 changes: 48 additions & 0 deletions tests/Patpass/Comercio/Responses/InscriptionStatusResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

use PHPUnit\Framework\TestCase;
use Transbank\Patpass\PatpassComercio\Responses\InscriptionStatusResponse;

class InscriptionStatusResponseTest extends TestCase
{
/** @test */
public function it_can_be_created_from_json()
{
$json = [
'authorized' => 'status',
'voucherUrl' => 'urlVoucher',
];

$response = new InscriptionStatusResponse($json);

$this->assertSame('status', $response->status);
$this->assertSame('urlVoucher', $response->urlVoucher);
}

/** @test */
public function it_returns_null_when_json_key_does_not_exist()
{
$json = [];

$response = new InscriptionStatusResponse($json);

$this->assertNull($response->status);
$this->assertNull($response->urlVoucher);
}

/** @test */
public function it_can_set_and_get_status()
{
$response = new InscriptionStatusResponse([]);
$response->setStatus('testStatus');
$this->assertSame('testStatus', $response->getStatus());
}

/** @test */
public function it_can_set_and_get_url_voucher()
{
$response = new InscriptionStatusResponse([]);
$response->setUrlVoucher('testUrl');
$this->assertSame('testUrl', $response->getUrlVoucher());
}
}
29 changes: 29 additions & 0 deletions tests/Patpass/PatpassByWebpayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use PHPUnit\Framework\TestCase;
use Transbank\Patpass\PatpassByWebpay;
use Transbank\Webpay\Options;

class PatpassByWebpayTest extends TestCase
{
/** @test */
public function it_configures_for_testing()
{
PatpassByWebpay::configureForTesting();
$options = PatpassByWebpay::getDefaultOptions();

$this->assertSame(PatpassByWebpay::DEFAULT_COMMERCE_CODE, $options->getCommerceCode());
$this->assertSame(PatpassByWebpay::DEFAULT_API_KEY, $options->getApiKey());
$this->assertSame(Options::ENVIRONMENT_INTEGRATION, $options->getIntegrationType());
}

/** @test */
public function it_returns_default_options()
{
$options = PatpassByWebpay::getDefaultOptions();

$this->assertSame(PatpassByWebpay::DEFAULT_COMMERCE_CODE, $options->getCommerceCode());
$this->assertSame(PatpassByWebpay::DEFAULT_API_KEY, $options->getApiKey());
$this->assertSame(Options::ENVIRONMENT_INTEGRATION, $options->getIntegrationType());
}
}
Loading

0 comments on commit 4024c53

Please sign in to comment.