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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Apiary
name: WS API documentation
description: Issue about documentation for ThePay.cz WS API
labels: ["Apiary"]
labels: ["OpenAPI"]
body:
- type: markdown
attributes:
Expand Down
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ body:
options:
- Production
- Demo
- Apiary mock
- Apiary proxy
- OpenAPI mock
validations:
required: false
- type: input
Expand Down
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/ws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ body:
options:
- Production
- Demo
- Apiary mock
- Apiary proxy
- OpenAPI mock
validations:
required: true
- type: input
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ jobs:
name: "php 8.4"
runs-on: ubuntu-latest
container: "nofutur3/php-tests:8.4"
services:
openAPImock:
image: mockserver/mockserver
ports:
- 1080:1080
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -20,13 +25,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

php83:
name: "php 8.3"
runs-on: ubuntu-latest
container: "nofutur3/php-tests:8.3"
services:
openAPImock:
image: mockserver/mockserver
ports:
- 1080:1080
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -37,13 +50,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

php82:
name: "php 8.2 psr/http-message 2.0"
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 @@ -57,13 +78,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

php82psrmessage10:
name: "php 8.2 psr/http-message 1.0"
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 @@ -74,13 +103,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

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 @@ -91,13 +128,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

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 @@ -108,13 +153,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 @@ -130,6 +183,9 @@ 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

Expand Down
16 changes: 5 additions & 11 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use PHPUnit\Framework\TestCase;
use ThePay\ApiClient\Service\ApiService;
use ThePay\ApiClient\Service\SignatureService;
use ThePay\ApiClient\Tests\Mocks\TheConfig;
use ThePay\ApiClient\TheClient;
use ThePay\ApiClient\TheConfig;

abstract class BaseTestCase extends TestCase
{
Expand All @@ -22,21 +22,15 @@ protected function setUp(): void
{
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
*/
protected function getApiaryClient(): TheClient
protected function getMockClient(): TheClient
{
$config = new TheConfig(
'6cdf1b24',
1212,
'password',
'https://private-aa6aa3-thepay.apiary-mock.com/',
'https://private-ddc40-gatezalozeniplatby.apiary-mock.com/'
);
$config = new TheConfig();

$httpFactory = new HttpFactory();

Expand Down
50 changes: 4 additions & 46 deletions tests/CancelPreauthorizationPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,29 @@

namespace ThePay\ApiClient\Tests;

use GuzzleHttp\Psr7\HttpFactory;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use ThePay\ApiClient\Service\ApiService;
use ThePay\ApiClient\Service\SignatureService;
use ThePay\ApiClient\TheClient;

final class CancelPreauthorizationPaymentTest extends BaseTestCase
{
/** @var MockObject&ClientInterface */
private MockObject $httpClient;
private TheClient $client;

protected function setUp(): void
{
parent::setUp();
$this->httpClient = $this->createMock(ClientInterface::class);
$httpFactory = new HttpFactory();
$apiService = new ApiService(
$this->config,
$this->createMock(SignatureService::class),
$this->httpClient,
$httpFactory,
$httpFactory
);
$this->client = new TheClient($this->config, $apiService);
$this->client = $this->getMockClient();
}

public function testRequest(): void
{
$this->httpClient
->expects(self::once())
->method('sendRequest')
->willReturnCallback(function (RequestInterface $request): ResponseInterface {
$expectedUrl = $this->config->getApiUrl() . 'projects/1/payments/abc/preauthorized?merchant_id=' . self::MERCHANT_ID;

self::assertSame('DELETE', $request->getMethod());
self::assertSame($expectedUrl, $request->getUri()->__toString());

return $this->getOkResponse();
})
;

$this->client->cancelPreauthorizedPayment('abc');
self::assertTrue(true);
}

public function testNotOkResponse(): void
{
$this->expectException(\Exception::class);

$this->httpClient->method('sendRequest')->willReturn($this->getNotOkResponse());

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

private function getOkResponse(): ResponseInterface
{
return new Response(204);
}

private function getNotOkResponse(): ResponseInterface
{
return new Response(401);
/** @phpstan-ignore-next-line */
$this->client->cancelPreauthorizedPayment('');
}
}
58 changes: 6 additions & 52 deletions tests/GeneratePaymentConfirmationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,24 @@

namespace ThePay\ApiClient\Tests;

use GuzzleHttp\Psr7\HttpFactory;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use ThePay\ApiClient\Service\ApiService;
use ThePay\ApiClient\Service\SignatureService;
use ThePay\ApiClient\TheClient;

final class GeneratePaymentConfirmationTest extends BaseTestCase
{
public function testSuccess(): void
{
$httpFactory = new HttpFactory();

$httpClient = $this->createMock(ClientInterface::class);
$httpClient->expects(self::once())->method('sendRequest')
->willReturnCallback(function (RequestInterface $request): Response {
self::assertSame('GET', $request->getMethod());
self::assertSame(
$this->config->getApiUrl() . 'projects/1/payments/testUID/generate_confirmation?language=cs&merchant_id=' . self::MERCHANT_ID,
$request->getUri()->__toString()
);

return new Response(200, [], 'test pdf content');
})
;

$theClient = new TheClient(
$this->config,
new ApiService(
$this->config,
$this->createMock(SignatureService::class),
$httpClient,
$httpFactory,
$httpFactory
)
);
$theClient = $this->getMockClient();

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

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

public function testFailed(): void
{
$httpFactory = new HttpFactory();

$httpClient = $this->createMock(ClientInterface::class);
$httpClient->expects(self::once())->method('sendRequest')
->willReturn(new Response(400));

$theClient = new TheClient(
$this->config,
new ApiService(
$this->config,
$this->createMock(SignatureService::class),
$httpClient,
$httpFactory,
$httpFactory
)
);
$theClient = $this->getMockClient();

$this->expectException(\RuntimeException::class);
$this->expectException(\InvalidArgumentException::class);

$theClient->generatePaymentConfirmationPdf('testUID', 'cs');
/** @phpstan-ignore-next-line */
$theClient->generatePaymentConfirmationPdf('');
}
}
Loading
Loading