Skip to content

Commit

Permalink
Merge pull request #307 from TransbankDevelopers/chore/update-test-li…
Browse files Browse the repository at this point in the history
…braries

chore: update test libraries
  • Loading branch information
mvarlic authored Feb 7, 2025
2 parents 5ddd01e + 33c2bd4 commit 5a9d212
Show file tree
Hide file tree
Showing 35 changed files with 212 additions and 176 deletions.
42 changes: 22 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@
"ext-mbstring": "*",
"guzzlehttp/guzzle":"^7"
},
"require-dev": {
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "~2.0",
"dms/phpunit-arraysubset-asserts": "^0.2.1"
},
"autoload": {
"psr-4": {
"Transbank\\": [
"src/"
]
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": [
"tests/"
]
}
},
"license": "BSD-3-Clause"
"require-dev": {
"phpunit/phpunit": "^11",
"squizlabs/php_codesniffer": "^3"
},
"autoload": {
"psr-4": {
"Transbank\\": [
"src/"
]
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": [
"tests/"
]
}
},
"scripts": {
"test": "phpunit || true"
},
"license": "BSD-3-Clause"
}
20 changes: 11 additions & 9 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/logs/html"/>
</report>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/logs/html"/>
</report>
</coverage>
<testsuites>
<testsuite name="Transbank SDK Test Suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
11 changes: 6 additions & 5 deletions tests/OptionsTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Transbank\Webpay\Options;

class OptionsTest extends TestCase
Expand All @@ -13,7 +14,7 @@ public function setUp(): void
$this->options = new Options($apiKey, $commerceCode, Options::ENVIRONMENT_INTEGRATION);
}

/** @test */
#[Test]
public function it_assign_contructor_params_to_their_corresponding_properties()
{
$options = new Options('a', 'b', 'c', 10);
Expand All @@ -23,7 +24,7 @@ public function it_assign_contructor_params_to_their_corresponding_properties()
$this->assertSame(10, $options->getTimeout());
}

/** @test */
#[Test]
public function it_returns_the_right_headers_based_on_configuration()
{
$options = new Options('ApiKey', 'CommerceCode', 'TEST');
Expand All @@ -33,7 +34,7 @@ public function it_returns_the_right_headers_based_on_configuration()
]);
}

/** @test */
#[Test]
public function it_set_properties()
{
$this->options->setIntegrationType(Options::ENVIRONMENT_PRODUCTION);
Expand All @@ -47,14 +48,14 @@ public function it_set_properties()
$this->assertEquals(100, $this->options->getTimeout());
}

/** @test */
#[Test]
public function it_check_if_is_production()
{
$this->options->setIntegrationType(Options::ENVIRONMENT_PRODUCTION);
$this->assertEquals(true, $this->options->isProduction());
}

/** @test */
#[Test]
public function it_get_base_url()
{
$this->options->setIntegrationType(Options::ENVIRONMENT_PRODUCTION);
Expand Down
3 changes: 2 additions & 1 deletion tests/PatpassComercio/PatpassComercioOptionsTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Transbank\PatpassComercio\Options;

class PatpassComercioOptionsTest extends TestCase
{
/** @test */
#[Test]
public function it_returns_the_right_headers_based_on_configuration()
{
$options = new Options('ApiKey', 'CommerceCode', 'TEST');
Expand Down
19 changes: 10 additions & 9 deletions tests/PatpassComercio/PatpassComercioTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Transbank\PatpassComercio\Options;
use Transbank\PatpassComercio\Inscription;
use Transbank\PatpassComercio\Exceptions\InscriptionStartException;
Expand All @@ -12,7 +13,7 @@

class PatpassComercioTest extends TestCase
{
/** @test */
#[Test]
public function it_configures_with_options()
{
$commerceCode = 'testCommerceCode';
Expand All @@ -28,7 +29,7 @@ public function it_configures_with_options()
$this->assertSame(Options::BASE_URL_PRODUCTION, $inscriptionOptions->getApiBaseUrl());
}

/** @test */
#[Test]
public function it_configures_for_integration()
{
$commerceCode = 'testCommerceCode';
Expand All @@ -43,7 +44,7 @@ public function it_configures_for_integration()
$this->assertSame(Options::BASE_URL_INTEGRATION, $options->getApiBaseUrl());
}

/** @test */
#[Test]
public function it_configures_for_production()
{
$commerceCode = 'testCommerceCode';
Expand All @@ -58,7 +59,7 @@ public function it_configures_for_production()
$this->assertSame(Options::BASE_URL_PRODUCTION, $options->getApiBaseUrl());
}

/** @test */
#[Test]
public function it_returns_inscription_start_response()
{
$options = new Options('apiKey', 'commerceCode', Options::ENVIRONMENT_PRODUCTION);
Expand Down Expand Up @@ -91,7 +92,7 @@ public function it_returns_inscription_start_response()
$this->assertInstanceOf(InscriptionStartResponse::class, $start);
}

/** @test */
#[Test]
public function it_throws_inscription_start_exception()
{
$options = new Options('apiKey', 'commerceCode', Options::ENVIRONMENT_PRODUCTION);
Expand Down Expand Up @@ -119,7 +120,7 @@ public function it_throws_inscription_start_exception()
);
}

/** @test */
#[Test]
public function it_returns_inscription_status_response()
{
$options = new Options('apiKey', 'commerceCode', Options::ENVIRONMENT_PRODUCTION);
Expand All @@ -136,7 +137,7 @@ public function it_returns_inscription_status_response()
$this->assertInstanceOf(InscriptionStatusResponse::class, $start);
}

/** @test */
#[Test]
public function it_throws_inscription_status_exception()
{
$options = new Options('apiKey', 'commerceCode', Options::ENVIRONMENT_PRODUCTION);
Expand All @@ -148,7 +149,7 @@ public function it_throws_inscription_status_exception()
$inscription->status('token');
}

/** @test */
#[Test]
public function it_can_set_options()
{
$options = new Options('apiKey', 'commerceCode', Options::ENVIRONMENT_PRODUCTION);
Expand All @@ -158,7 +159,7 @@ public function it_can_set_options()
$this->assertEquals(Options::BASE_URL_INTEGRATION, $inscription->getOptions()->getApiBaseUrl());
}

/** @test */
#[Test]
public function it_can_get_base_url()
{
$options = new Options('test-api-key', 'test-commerce-code', Options::ENVIRONMENT_INTEGRATION);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
<?php

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Transbank\PatpassComercio\Responses\InscriptionFinishResponse;

class PatpassInscriptionFinishResponseTest extends TestCase
{
/** @test */
#[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 */
#[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 */
#[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 */
#[Test]
public function it_can_get_status()
{
$response = new InscriptionFinishResponse(204);
$this->assertSame('OK', $response->getStatus());
}

/** @test */
#[Test]
public function it_can_get_code()
{
$response = new InscriptionFinishResponse(204);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Transbank\PatpassComercio\Responses\InscriptionStartResponse;

class InscriptionStartResponseTest extends TestCase
Expand All @@ -18,13 +19,13 @@ public function setUp(): void

}

/** @test */
#[Test]
public function it_can_set_and_get_token()
{
$this->assertSame('testToken', $this->inscriptionStartResponse->getToken());
}

/** @test */
#[Test]
public function it_can_set_and_get_url_webpay()
{
$this->assertSame('testUrl', $this->inscriptionStartResponse->getUrlWebpay());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Transbank\PatpassComercio\Responses\InscriptionStatusResponse;

class InscriptionStatusResponseTest extends TestCase
Expand All @@ -18,7 +19,7 @@ public function setUp(): void
$this->inscriptionResponse = new InscriptionStatusResponse($this->json);
}

/** @test */
#[Test]
public function it_can_be_created_from_json()
{
$response = new InscriptionStatusResponse($this->json);
Expand All @@ -27,7 +28,7 @@ public function it_can_be_created_from_json()
$this->assertSame('urlVoucher', $response->urlVoucher);
}

/** @test */
#[Test]
public function it_returns_null_when_json_key_does_not_exist()
{
$json = [];
Expand All @@ -38,13 +39,13 @@ public function it_returns_null_when_json_key_does_not_exist()
$this->assertNull($response->urlVoucher);
}

/** @test */
#[Test]
public function it_can_get_status()
{
$this->assertSame('status', $this->inscriptionResponse->getStatus());
}

/** @test */
#[Test]
public function it_can_set_and_get_url_voucher()
{
$this->assertSame('urlVoucher', $this->inscriptionResponse->getUrlVoucher());
Expand Down
9 changes: 5 additions & 4 deletions tests/RequestServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Transbank\Utils\HttpClient;
use Transbank\Utils\HttpClientRequestService;
use Transbank\Webpay\Options;

class RequestServiceTest extends TestCase
{
/** @test */
#[Test]
public function it_send_the_headers_provided_by_the_given_options()
{
$expectedHeaders = ['api_key' => 'commerce_code', 'api_secret' => 'fakeApiKey'];
Expand Down Expand Up @@ -37,7 +38,7 @@ public function it_send_the_headers_provided_by_the_given_options()
(new HttpClientRequestService($httpClientMock))->request('POST', '/transactions', [], $optionsMock);
}

/** @test */
#[Test]
public function it_uses_the_base_url_provided_by_the_given_options()
{
$expectedBaseUrl = 'https://mock.mock/';
Expand All @@ -60,7 +61,7 @@ public function it_uses_the_base_url_provided_by_the_given_options()
(new HttpClientRequestService($httpClientMock))->request('POST', $endpoint, [], $optionsMock);
}

/** @test */
#[Test]
public function it_returns_an_empty_array()
{
$options = new Options('ApiKey', 'commerceCode', Options::ENVIRONMENT_INTEGRATION);
Expand All @@ -73,7 +74,7 @@ public function it_returns_an_empty_array()
$this->assertSame([], $response);
}

/** @test */
#[Test]
public function it_returns_an_api_request()
{
$options = new Options('ApiKey', 'commerceCode', Options::ENVIRONMENT_INTEGRATION);
Expand Down
1 change: 1 addition & 0 deletions tests/Utils/HasTransactionStatusTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Transbank\Utils\HasTransactionStatus;

class DummyClass
Expand Down
Loading

0 comments on commit 5a9d212

Please sign in to comment.