Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ jobs:
name: "php 8.2"
runs-on: ubuntu-latest
container: "nofutur3/php-tests:8.2"
services:
openAPImock:
image: mockserver/mockserver
ports:
- 1080:1080
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -27,13 +32,21 @@ jobs:
- name: Run static analysis
run: composer stan

- name: Create mock server from our production OpenAPI
run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://openAPImock:1080/mockserver/openapi

- name: Run tests
run: composer test81

php81:
name: "php 8.1"
runs-on: ubuntu-latest
container: "nofutur3/php-tests:8.1"
services:
openAPImock:
image: mockserver/mockserver
ports:
- 1080:1080
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -49,13 +62,21 @@ jobs:
- name: Run static analysis
run: composer stan

- name: Create mock server from our production OpenAPI
run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://openAPImock:1080/mockserver/openapi

- name: Run tests
run: composer test81

php80:
name: "php 8.0"
runs-on: ubuntu-latest
container: "nofutur3/php-tests:8.0"
services:
openAPImock:
image: mockserver/mockserver
ports:
- 1080:1080
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -71,13 +92,21 @@ jobs:
- name: Run static analysis
run: composer stan

- name: Create mock server from our production OpenAPI
run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://openAPImock:1080/mockserver/openapi

- name: Run tests
run: composer test

php74:
name: "php 7.4"
runs-on: ubuntu-latest
container: "nofutur3/php-tests:7.4"
services:
openAPImock:
image: mockserver/mockserver
ports:
- 1080:1080
steps:
# Deprecation example for future support removal.
#
Expand All @@ -93,13 +122,21 @@ jobs:
- name: Run static analysis
run: composer stan7

- name: Create mock server from our production OpenAPI
run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://openAPImock:1080/mockserver/openapi

- name: Run tests
run: composer test

php72:
name: "php 7.2"
runs-on: ubuntu-latest
container: "nofutur3/php-tests:7.2"
services:
openAPImock:
image: mockserver/mockserver
ports:
- 1080:1080
steps:
# Deprecation example for future support removal.
#
Expand All @@ -109,12 +146,18 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Composer update
run: composer self-update

- name: Install dependencies
run: composer install --no-interaction
run: composer install --no-interaction --no-security-blocking

- name: Run static analysis
run: composer stan7

- name: Create mock server from our production OpenAPI
run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://openAPImock:1080/mockserver/openapi

- name: Run tests
run: composer test

Expand Down
17 changes: 5 additions & 12 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace ThePay\ApiClient\Tests;

use PHPUnit\Framework\TestCase;
use ThePay\ApiClient\Tests\Mocks\TheConfig;
use ThePay\ApiClient\TheClient;
use ThePay\ApiClient\TheConfig;

abstract class BaseTestCase extends TestCase
{
Expand All @@ -20,23 +20,16 @@ protected function setUp()
{
parent::setUp();

$this->config = new TheConfig(self::MERCHANT_ID, 1, 'password', 'https://test.api.cz/', 'https://test.gate.cz/');
$this->config = new TheConfig();
}

/**
* method return TheClient witch use apiary mock server
* method return TheClient witch use mock server
*
* @return TheClient
*/
protected function getApiaryClient()
protected function getMockClient()
{
$config = new TheConfig(
'6cdf1b24',
1212,
'password',
'https://private-aa6aa3-thepay.apiary-mock.com/',
'https://private-ddc40-gatezalozeniplatby.apiary-mock.com/'
);
return new TheClient($config);
return new TheClient(new TheConfig());
}
}
41 changes: 4 additions & 37 deletions tests/CancelPreauthorizationPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@

namespace ThePay\ApiClient\Tests;

use Mockery;
use ThePay\ApiClient\Http\HttpResponse;
use ThePay\ApiClient\Service\ApiService;
use ThePay\ApiClient\TheClient;
use ThePay\ApiClient\ValueObject\Identifier;

class CancelPreauthorizationPaymentTest extends BaseTestCase
{
/** @var \Mockery\LegacyMockInterface|\ThePay\ApiClient\Http\HttpServiceInterface */
private $httpService;

/** @var TheClient */
private $client;

Expand All @@ -22,24 +16,16 @@ class CancelPreauthorizationPaymentTest extends BaseTestCase
protected function setUp()
{
parent::setUp();
$this->httpService = Mockery::mock('ThePay\ApiClient\Http\HttpServiceInterface');
/** @phpstan-ignore-next-line */
$apiService = new ApiService($this->config, $this->httpService);
/** @phpstan-ignore-next-line */
$this->client = new TheClient($this->config, null, $this->httpService, $apiService);
$this->client = $this->getMockClient();
}

/**
* @return void
*/
public function testRequest()
{
call_user_func(array($this->httpService, 'shouldReceive'), 'delete')->once()
->with($this->config->getApiUrl() . 'projects/1/payments/abc/preauthorized?merchant_id=' . self::MERCHANT_ID)
->andReturn($this->getOkResponse());

$this->client->cancelPreauthorizedPayment(new Identifier('abc'));
\Mockery::close();
$result = $this->client->cancelPreauthorizedPayment(new Identifier('abc'));
self::assertTrue($result);
}

/**
Expand All @@ -48,25 +34,6 @@ public function testRequest()
*/
public function testNotOkResponse()
{
call_user_func(array($this->httpService, 'shouldReceive'), 'delete')
->andReturn($this->getNotOkResponse());

$this->client->cancelPreauthorizedPayment(new Identifier('abc'));
}

/**
* @return HttpResponse
*/
private function getOkResponse()
{
return new HttpResponse(null, 204);
}

/**
* @return HttpResponse
*/
private function getNotOkResponse()
{
return new HttpResponse(null, 401);
$this->client->cancelPreauthorizedPayment(new Identifier(''));
}
}
51 changes: 8 additions & 43 deletions tests/GeneratePaymentConfirmationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,18 @@

namespace ThePay\ApiClient\Tests;

use ThePay\ApiClient\Http\HttpResponse;
use ThePay\ApiClient\Http\HttpServiceInterface;
use ThePay\ApiClient\TheClient;

final class GeneratePaymentConfirmationTest extends BaseTestCase
{
/**
* @return void
*/
public function testSuccess()
{
/** @var HttpServiceInterface $httpService */
$httpService = \Mockery::mock('ThePay\ApiClient\Http\HttpServiceInterface');

call_user_func(array($httpService, 'shouldReceive'), 'get')->once()
->with($this->config->getApiUrl() . 'projects/1/payments/testUID/generate_confirmation?language=cs&merchant_id=' . self::MERCHANT_ID)
->andReturn(
new HttpResponse(
null,
200,
'',
null,
'test pdf content'
)
);

$theClient = new TheClient(
$this->config,
null,
$httpService
);
$theClient = $this->getMockClient();

$pdfContent = $theClient->generatePaymentConfirmationPdf('testUID', 'cs');

self::assertSame('test pdf content', $pdfContent);
self::assertTrue(is_string($pdfContent));

\Mockery::close();
}
Expand All @@ -48,26 +25,16 @@ public function testSuccess()
*
* @return void
*/
public function testFailed($expectedException, HttpResponse $response)
public function testFailed($expectedException)
{
/** @var HttpServiceInterface $httpService */
$httpService = \Mockery::mock('ThePay\ApiClient\Http\HttpServiceInterface');
call_user_func(array($httpService, 'shouldReceive'), 'get')->once()
->andReturn($response);

$theClient = new TheClient(
$this->config,
null,
$httpService
);
$theClient = $this->getMockClient();

try {
$theClient->generatePaymentConfirmationPdf('testUID');
/** @phpstan-ignore-next-line */
$theClient->generatePaymentConfirmationPdf('');
} catch (\Exception $exception) {
self::assertSame($expectedException, get_class($exception));
}

\Mockery::close();
}

/**
Expand All @@ -76,10 +43,8 @@ public function testFailed($expectedException, HttpResponse $response)
public function dataFailed()
{
return array(
// failed response code
array('RuntimeException', new HttpResponse(null, 400)),
// response without body
array('ThePay\ApiClient\Exception\ApiException', new HttpResponse(null, 200)),
// failed input
array('InvalidArgumentException'),
);
}
}
34 changes: 3 additions & 31 deletions tests/GetAccountsBalancesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

namespace ThePay\ApiClient\Tests;

use ThePay\ApiClient\Http\HttpResponse;
use ThePay\ApiClient\Http\HttpServiceInterface;
use ThePay\ApiClient\Model\AccountBalance;
use ThePay\ApiClient\TheClient;

final class GetAccountsBalancesTest extends BaseTestCase
{
Expand All @@ -14,43 +11,18 @@ final class GetAccountsBalancesTest extends BaseTestCase
*/
public function test()
{
/** @var HttpServiceInterface $httpService */
$httpService = \Mockery::mock('ThePay\ApiClient\Http\HttpServiceInterface');
call_user_func(array($httpService, 'shouldReceive'), 'get')->once()
->with($this->config->getApiUrl() . 'balances?account_iban=TP7811112150822790787055&project_id=1&balance_at=2023-03-14T15%3A08%3A44%2B00%3A00&merchant_id=' . self::MERCHANT_ID)
->andReturn(
new HttpResponse(
null,
200,
'',
null,
'[
{
"iban": "TP7811112150822790787055",
"name": "Test",
"balance": {
"CZK": "45899",
"EUR": "500"
}
}
]'
)
);

$client = new TheClient($this->config, null, $httpService);
$client = $this->getMockClient();

$balances = $client->getAccountsBalances('TP7811112150822790787055', 1, new \DateTime('2023-03-14 15:08:44+00:00'));
self::assertEquals(
array(
new AccountBalance(
'TP7811112150822790787055',
'Test',
array('CZK' => '45899', 'EUR' => '500')
'Account #1',
array('CZK' => '1256', 'EUR' => '231', 'USD' => '0')
),
),
$balances
);

\Mockery::close();
}
}
Loading
Loading