diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11adab5..3995c7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 }} @@ -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 }} @@ -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 + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a225865..62b8e79 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,9 +5,18 @@ failOnWarning="true" colors="true" testdox="false" displayDetailsOnTestsThatTriggerDeprecations="true"> - + ./tests + + ./tests/Barnetik/Tbai/Api + ./tests/Barnetik/Tbai/LROE + + + ./tests + ./tests/Barnetik/Tbai/Api + ./tests/Barnetik/Tbai/LROE + 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 107822b..76a15cc 100644 --- a/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php +++ b/tests/Barnetik/Tbai/Api/Araba/EndpointTest.php @@ -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']; diff --git a/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php b/tests/Barnetik/Tbai/Api/Bizkaia/EndpointTest.php index bac871c..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,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(); diff --git a/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php b/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php index 5ebdf1d..efc26b9 100644 --- a/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php +++ b/tests/Barnetik/Tbai/Api/Gipuzkoa/EndpointTest.php @@ -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(); 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 @@ - +