From cd3bbf1b7a79a8c4ce2fa3f50584e0d4e424842d Mon Sep 17 00:00:00 2001 From: Alayn Gortazar Huete Date: Tue, 11 Aug 2026 09:40:28 +0200 Subject: [PATCH 1/8] test: Added throttle on enpdoints test and testing only against lowest and highest supported PHP version --- .github/workflows/ci.yml | 23 +++++++++++++------ phpunit.xml.dist | 9 +++++++- .../Barnetik/Tbai/Api/Araba/EndpointTest.php | 6 +++++ .../Tbai/Api/Bizkaia/EndpointTest.php | 6 +++++ .../Tbai/Api/Gipuzkoa/EndpointTest.php | 6 +++++ 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11adab5..7f3c2ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,16 @@ jobs: 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', 'phpunit-api'] + exclude: + - php-version: '8.1' + test-type: 'phpunit-api' + - php-version: '8.2' + test-type: 'phpunit-api' + - php-version: '8.3' + test-type: 'phpunit-api' + - php-version: '8.4' + test-type: 'phpunit-api' steps: - uses: actions/checkout@v4 @@ -40,8 +49,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 }} @@ -53,10 +62,10 @@ 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' + - name: Run phpunit (API endpoint tests) + if: matrix.test-type == 'phpunit-api' env: TBAI_ARABA_APP_LICENSE: ${{ secrets.TBAI_ARABA_APP_LICENSE }} TBAI_ARABA_APP_DEVELOPER_NIF: ${{ secrets.TBAI_ARABA_APP_DEVELOPER_NIF }} @@ -68,5 +77,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 diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a225865..884c047 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,9 +5,16 @@ failOnWarning="true" colors="true" testdox="false" displayDetailsOnTestsThatTriggerDeprecations="true"> - + ./tests + + ./tests/Barnetik/Tbai/Api + + + ./tests + ./tests/Barnetik/Tbai/Api + diff --git a/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php b/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php index 107822b..7234a87 100644 --- a/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php +++ b/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php @@ -15,6 +15,12 @@ class EndpointTest extends TestCase const SUBMIT_RETRY_DELAY = 3; const DEFAULT_TERRITORY = TicketBai::TERRITORY_ARABA; + protected function setUp(): void + { + parent::setUp(); + sleep(5); + } + public function test_TicketBai_is_delivered(): void { $nif = $_ENV['TBAI_ARABA_ISSUER_NIF']; diff --git a/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php b/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php index bac871c..5055b3b 100644 --- a/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php +++ b/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php @@ -19,6 +19,12 @@ class EndpointTest extends TestCase const SUBMIT_RETRY_DELAY = 3; const DEFAULT_TERRITORY = TicketBai::TERRITORY_BIZKAIA; + protected function setUp(): void + { + parent::setUp(); + sleep(5); + } + public function test_sent_FacturasEmitidasConSGAltaPeticion_xml_is_valid(): void { [$privateKey, $password] = $this->getBizkaiaP12Credentials(); diff --git a/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php b/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php index 5ebdf1d..5a82279 100644 --- a/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php +++ b/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php @@ -16,6 +16,12 @@ class EndpointTest extends TestCase const SUBMIT_RETRY_DELAY = 3; const DEFAULT_TERRITORY = TicketBai::TERRITORY_GIPUZKOA; + protected function setUp(): void + { + parent::setUp(); + sleep(5); + } + public function test_TicketBai_is_delivered(): void { [$privateKey, $certPassword] = $this->getGipuzkoaP12Credentials(); From f76a45c46bffd4752ad3d8c5c5f6a545e981b1ec Mon Sep 17 00:00:00 2001 From: Alayn Gortazar Huete Date: Tue, 11 Aug 2026 10:08:01 +0200 Subject: [PATCH 2/8] test: Removed max parallel parameter on gitlab actions config --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f3c2ec..e39d6e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,6 @@ 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-unit', 'phpunit-api'] From 2583843b9454770ce1d6cda707cb47246498fc4e Mon Sep 17 00:00:00 2001 From: Alayn Gortazar Huete Date: Tue, 11 Aug 2026 10:12:22 +0200 Subject: [PATCH 3/8] test: Added job for api tests so we can avoid running them on parallel --- .github/workflows/ci.yml | 44 +++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e39d6e1..3995c7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,16 +12,7 @@ jobs: fail-fast: false matrix: php-version: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] - test-type: ['phpstan', 'phpunit-unit', 'phpunit-api'] - exclude: - - php-version: '8.1' - test-type: 'phpunit-api' - - php-version: '8.2' - test-type: 'phpunit-api' - - php-version: '8.3' - test-type: 'phpunit-api' - - php-version: '8.4' - test-type: 'phpunit-api' + test-type: ['phpstan', 'phpunit-unit'] steps: - uses: actions/checkout@v4 @@ -63,8 +54,37 @@ jobs: TBAI_GIPUZKOA_ISSUER_NIF: ${{ secrets.TBAI_GIPUZKOA_ISSUER_NIF }} run: phpunit -c phpunit.xml.dist --testsuite unit + 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) - if: matrix.test-type == 'phpunit-api' env: TBAI_ARABA_APP_LICENSE: ${{ secrets.TBAI_ARABA_APP_LICENSE }} TBAI_ARABA_APP_DEVELOPER_NIF: ${{ secrets.TBAI_ARABA_APP_DEVELOPER_NIF }} @@ -77,4 +97,4 @@ jobs: 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 --testsuite api - + From f2b90fddcd8a56f114bb0add29789b44e5060488 Mon Sep 17 00:00:00 2001 From: Alayn Gortazar Huete Date: Tue, 11 Aug 2026 10:13:24 +0200 Subject: [PATCH 4/8] test: Added LROE tests to API suite --- phpunit.xml.dist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 884c047..62b8e79 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,10 +10,12 @@ ./tests/Barnetik/Tbai/Api + ./tests/Barnetik/Tbai/LROE ./tests ./tests/Barnetik/Tbai/Api + ./tests/Barnetik/Tbai/LROE From 8ba724411899226fb13071564a0cb99350e8255c Mon Sep 17 00:00:00 2001 From: Alayn Gortazar Huete Date: Tue, 11 Aug 2026 10:23:51 +0200 Subject: [PATCH 5/8] test: Avoid remote call to w3.org to validate xml schemas --- tests/Barnetik/Tbai/Api/Araba/EndpointTest.php | 2 +- tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php | 2 +- tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php | 2 +- tests/Barnetik/Tbai/__files/specs/anula_ticketbaiv1-2-2.xsd | 2 +- .../Tbai/__files/specs/ticketbaiv1-2-2-no-signature.xsd | 2 +- tests/Barnetik/Tbai/__files/specs/ticketbaiv1-2-2.xsd | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php b/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php index 7234a87..b14edbe 100644 --- a/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php +++ b/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php @@ -18,7 +18,7 @@ class EndpointTest extends TestCase protected function setUp(): void { parent::setUp(); - sleep(5); + sleep(2); } public function test_TicketBai_is_delivered(): void diff --git a/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php b/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php index 5055b3b..a4f7524 100644 --- a/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php +++ b/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php @@ -22,7 +22,7 @@ class EndpointTest extends TestCase protected function setUp(): void { parent::setUp(); - sleep(5); + sleep(2); } public function test_sent_FacturasEmitidasConSGAltaPeticion_xml_is_valid(): void diff --git a/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php b/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php index 5a82279..6b70684 100644 --- a/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php +++ b/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php @@ -19,7 +19,7 @@ class EndpointTest extends TestCase protected function setUp(): void { parent::setUp(); - sleep(5); + sleep(2); } public function test_TicketBai_is_delivered(): void diff --git a/tests/Barnetik/Tbai/__files/specs/anula_ticketbaiv1-2-2.xsd b/tests/Barnetik/Tbai/__files/specs/anula_ticketbaiv1-2-2.xsd index ef8b16c..75001fb 100644 --- a/tests/Barnetik/Tbai/__files/specs/anula_ticketbaiv1-2-2.xsd +++ b/tests/Barnetik/Tbai/__files/specs/anula_ticketbaiv1-2-2.xsd @@ -1,7 +1,7 @@  - + diff --git a/tests/Barnetik/Tbai/__files/specs/ticketbaiv1-2-2-no-signature.xsd b/tests/Barnetik/Tbai/__files/specs/ticketbaiv1-2-2-no-signature.xsd index f78a718..b2d9829 100644 --- a/tests/Barnetik/Tbai/__files/specs/ticketbaiv1-2-2-no-signature.xsd +++ b/tests/Barnetik/Tbai/__files/specs/ticketbaiv1-2-2-no-signature.xsd @@ -1,7 +1,7 @@ - + diff --git a/tests/Barnetik/Tbai/__files/specs/ticketbaiv1-2-2.xsd b/tests/Barnetik/Tbai/__files/specs/ticketbaiv1-2-2.xsd index 740a041..3cb4044 100644 --- a/tests/Barnetik/Tbai/__files/specs/ticketbaiv1-2-2.xsd +++ b/tests/Barnetik/Tbai/__files/specs/ticketbaiv1-2-2.xsd @@ -1,7 +1,7 @@ - + From b51d7e46473d467168643e4feb90fb58d4e84b24 Mon Sep 17 00:00:00 2001 From: Alayn Gortazar Huete Date: Tue, 11 Aug 2026 10:52:50 +0200 Subject: [PATCH 6/8] fix: Better curl connection error handle for retries --- src/Barnetik/Tbai/Api/AbstractTerritory.php | 15 ++++++++++++--- tests/Barnetik/Tbai/Api/Araba/EndpointTest.php | 3 +-- tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php | 5 +---- tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php | 3 +-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Barnetik/Tbai/Api/AbstractTerritory.php b/src/Barnetik/Tbai/Api/AbstractTerritory.php index ba0b3b7..de15a75 100644 --- a/src/Barnetik/Tbai/Api/AbstractTerritory.php +++ b/src/Barnetik/Tbai/Api/AbstractTerritory.php @@ -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; } } diff --git a/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php b/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php index b14edbe..76a15cc 100644 --- a/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php +++ b/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php @@ -12,13 +12,12 @@ 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(); - sleep(2); } public function test_TicketBai_is_delivered(): void diff --git a/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php b/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php index a4f7524..8564539 100644 --- a/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php +++ b/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php @@ -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; @@ -16,13 +14,12 @@ 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(); - sleep(2); } public function test_sent_FacturasEmitidasConSGAltaPeticion_xml_is_valid(): void diff --git a/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php b/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php index 6b70684..efc26b9 100644 --- a/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php +++ b/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php @@ -13,13 +13,12 @@ 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(); - sleep(2); } public function test_TicketBai_is_delivered(): void From 20bbf5d274311bb792e2fa664c2ac6b616b4c901 Mon Sep 17 00:00:00 2001 From: Alayn Gortazar Huete Date: Tue, 11 Aug 2026 11:24:16 +0200 Subject: [PATCH 7/8] test: Test again without max-parallel limits --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3995c7a..fc6ca59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,7 +59,6 @@ jobs: runs-on: ubuntu-latest strategy: fail-fast: false - max-parallel: 1 matrix: php-version: ['8.0', '8.5'] From ae46fe06faa6f661ff034312ebe6f469ea2b12b5 Mon Sep 17 00:00:00 2001 From: Alayn Gortazar Huete Date: Tue, 11 Aug 2026 11:35:27 +0200 Subject: [PATCH 8/8] test: Back to max-parallel limits for api tests --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc6ca59..3995c7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,7 @@ jobs: runs-on: ubuntu-latest strategy: fail-fast: false + max-parallel: 1 matrix: php-version: ['8.0', '8.5']