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
46 changes: 37 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 1
matrix:
php-version: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
test-type: ['phpstan', 'phpunit-zuzendu', 'phpunit-ticketbai']
test-type: ['phpstan', 'phpunit-unit']

steps:
- uses: actions/checkout@v4
Expand All @@ -40,8 +39,8 @@ jobs:
if: matrix.test-type == 'phpstan'
run: phpstan analyse --configuration phpstan.neon --memory-limit 1G

- name: Run phpunit (Ticketbai service)
if: matrix.test-type == 'phpunit-ticketbai'
- name: Run phpunit (unit tests)
if: matrix.test-type == 'phpunit-unit'
env:
TBAI_ARABA_APP_LICENSE: ${{ secrets.TBAI_ARABA_APP_LICENSE }}
TBAI_ARABA_APP_DEVELOPER_NIF: ${{ secrets.TBAI_ARABA_APP_DEVELOPER_NIF }}
Expand All @@ -53,10 +52,39 @@ jobs:
TBAI_GIPUZKOA_APP_LICENSE: ${{ secrets.TBAI_GIPUZKOA_APP_LICENSE }}
TBAI_GIPUZKOA_APP_DEVELOPER_NIF: ${{ secrets.TBAI_GIPUZKOA_APP_DEVELOPER_NIF }}
TBAI_GIPUZKOA_ISSUER_NIF: ${{ secrets.TBAI_GIPUZKOA_ISSUER_NIF }}
run: phpunit -c phpunit.xml.dist --filter "^(?!.*(zuzendu)).*$"
run: phpunit -c phpunit.xml.dist --testsuite unit

- name: Run phpunit (Zuzendu service)
if: matrix.test-type == 'phpunit-zuzendu'
api-tests:
name: PHP ${{ matrix.php-version }} - phpunit-api
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 1
matrix:
php-version: ['8.0', '8.5']

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.PHP_EXTENSIONS }}
tools: composer:v2,phpunit

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --prefer-dist

- name: Run phpunit (API endpoint tests)
env:
TBAI_ARABA_APP_LICENSE: ${{ secrets.TBAI_ARABA_APP_LICENSE }}
TBAI_ARABA_APP_DEVELOPER_NIF: ${{ secrets.TBAI_ARABA_APP_DEVELOPER_NIF }}
Expand All @@ -68,5 +96,5 @@ jobs:
TBAI_GIPUZKOA_APP_LICENSE: ${{ secrets.TBAI_GIPUZKOA_APP_LICENSE }}
TBAI_GIPUZKOA_APP_DEVELOPER_NIF: ${{ secrets.TBAI_GIPUZKOA_APP_DEVELOPER_NIF }}
TBAI_GIPUZKOA_ISSUER_NIF: ${{ secrets.TBAI_GIPUZKOA_ISSUER_NIF }}
run: phpunit -c phpunit.xml.dist --filter ".*zuzendu.*"
run: phpunit -c phpunit.xml.dist --testsuite api

11 changes: 10 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
failOnWarning="true" colors="true" testdox="false"
displayDetailsOnTestsThatTriggerDeprecations="true">
<testsuites>
<testsuite name="Tbai test suite">
<testsuite name="all">
<directory suffix="Test.php">./tests</directory>
</testsuite>
<testsuite name="api">
<directory suffix="Test.php">./tests/Barnetik/Tbai/Api</directory>
<directory suffix="Test.php">./tests/Barnetik/Tbai/LROE</directory>
</testsuite>
<testsuite name="unit">
<directory suffix="Test.php">./tests</directory>
<exclude>./tests/Barnetik/Tbai/Api</exclude>
<exclude>./tests/Barnetik/Tbai/LROE</exclude>
</testsuite>
</testsuites>
<source>
<include>
Expand Down
15 changes: 12 additions & 3 deletions src/Barnetik/Tbai/Api/AbstractTerritory.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,23 @@ protected function doRequest(ApiRequestInterface $request, PrivateKey $privateKe

$response = curl_exec($curl);
if (curl_errno($curl)) {
throw new Exception(sprintf('Curl error(%s): %s', curl_errno($curl), curl_error($curl)));
throw new Exception(sprintf('Curl error(%s): %s', curl_errno($curl), curl_error($curl)), curl_errno($curl));
}

list($status, $headers, $content) = $this->parseCurlResponse($response, $curl);
curl_close($curl);
return $this->response($status, $headers, $content);
} catch (Exception $e) {
if ($tries > $maxRetries || $e->getMessage() !== 'No response from server') {
$isCurlConnectionError = in_array($e->getCode(), [
CURLE_COULDNT_RESOLVE_PROXY,
CURLE_COULDNT_RESOLVE_HOST,
CURLE_COULDNT_CONNECT,
CURLE_OPERATION_TIMEDOUT,
CURLE_SSL_CONNECT_ERROR,
CURLE_RECV_ERROR
]);
$isConnectionError = $isCurlConnectionError || $e->getMessage() === 'No response from server';

if ($tries > $maxRetries || !$isConnectionError) {
throw $e;
}
}
Expand Down
7 changes: 6 additions & 1 deletion tests/Barnetik/Tbai/Api/Araba/EndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
class EndpointTest extends TestCase
{
const SUBMIT_RETRIES = 3;
const SUBMIT_RETRY_DELAY = 3;
const SUBMIT_RETRY_DELAY = 2;
const DEFAULT_TERRITORY = TicketBai::TERRITORY_ARABA;

protected function setUp(): void
{
parent::setUp();
}

public function test_TicketBai_is_delivered(): void
{
$nif = $_ENV['TBAI_ARABA_ISSUER_NIF'];
Expand Down
9 changes: 6 additions & 3 deletions tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Test\Barnetik\Tbai\Api\Bizkaia;

use Barnetik\Tbai\AbstractTicketBai;
use Barnetik\Tbai\Api;
use Barnetik\Tbai\Api\AbstractTerritory;
use Barnetik\Tbai\Api\Bizkaia\Endpoint;
use Barnetik\Tbai\Interfaces\TbaiSignable;
use Barnetik\Tbai\PrivateKey;
Expand All @@ -16,9 +14,14 @@
class EndpointTest extends TestCase
{
const SUBMIT_RETRIES = 3;
const SUBMIT_RETRY_DELAY = 3;
const SUBMIT_RETRY_DELAY = 2;
const DEFAULT_TERRITORY = TicketBai::TERRITORY_BIZKAIA;

protected function setUp(): void
{
parent::setUp();
}

public function test_sent_FacturasEmitidasConSGAltaPeticion_xml_is_valid(): void
{
[$privateKey, $password] = $this->getBizkaiaP12Credentials();
Expand Down
7 changes: 6 additions & 1 deletion tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
class EndpointTest extends TestCase
{
const SUBMIT_RETRIES = 3;
const SUBMIT_RETRY_DELAY = 3;
const SUBMIT_RETRY_DELAY = 2;
const DEFAULT_TERRITORY = TicketBai::TERRITORY_GIPUZKOA;

protected function setUp(): void
{
parent::setUp();
}

public function test_TicketBai_is_delivered(): void
{
[$privateKey, $certPassword] = $this->getGipuzkoaP12Credentials();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:T="urn:ticketbai:anulacion" targetNamespace="urn:ticketbai:anulacion">

<import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd"/>
<import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>

<element name="AnulaTicketBai">
<complexType>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:T="urn:ticketbai:emision" targetNamespace="urn:ticketbai:emision">

<import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd"/>
<import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>

<element name="TicketBai">
<complexType>
Expand Down
2 changes: 1 addition & 1 deletion tests/Barnetik/Tbai/__files/specs/ticketbaiv1-2-2.xsd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:T="urn:ticketbai:emision" targetNamespace="urn:ticketbai:emision">

<import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd"/>
<import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>

<element name="TicketBai">
<complexType>
Expand Down
Loading