Skip to content

Commit f510342

Browse files
committed
Se añadieron múltiples testsuites en phpunit. Se añadieron scripts a composer.json: estos scripts permiten probar tests específicos que solo son de lectura, filtrando dichos test. Se añadió insignias faltantes a index.rst. Se añadió un enlace que lleva a la página web principal de documentación al README.md. Se eliminó el desgloce de ejemplo de example.rst. Se creó el workflow ci.yml.
1 parent ab49dcd commit f510342

6 files changed

Lines changed: 163 additions & 77 deletions

File tree

.github/workflows/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master # Ejecuta pruebas al hacer push en la rama 'master'
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
php-version: ['7.3', '8.0'] # Puedes cambiar las versiones según necesites
15+
16+
steps:
17+
- name: Check out repository code
18+
uses: actions/checkout@v3
19+
20+
- name: Setup PHP ${{ matrix.php-version }}
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php-version }} # Configura la versión de PHP desde la matriz
24+
extensions: curl, mbstring, intl, xdebug # Instala extensiones de PHP si es necesario
25+
toos: composer
26+
27+
- name: Install Composer dependencies
28+
run: composer install --no-progress --no-suggest
29+
30+
- name: Create temporary env file
31+
run: |
32+
echo "LIBREDTE_HASH=${{ secrets.LIBREDTE_HASH }}" >> tests/test.env
33+
echo "LIBREDTE_RUT=${{ secrets.LIBREDTE_RUT }}" >> tests/test.env
34+
35+
- name: Run PHP tests read only
36+
run: |
37+
composer tests_readonly
38+
39+
- name: Upload PHPUnit result report
40+
if: failure()
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: tests-testdox-php_${{ matrix.php-version }}.txt
44+
path: var/tests-testdox.txt
45+
46+
- name: Display PHP version
47+
run: php -v

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ LibreDTE: Cliente de API en PHP
1212

1313
Cliente para realizar la integración con los servicios web de [LibreDTE](https://www.libredte.cl) desde PHP.
1414

15+
Revisa la [documentación](https://api-client-php.docs.libredte.cl/guide/index.html) de la biblioteca para más información, sus características y detalles de su uso.
16+
1517
Licencia
1618
--------
1719

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,13 @@
3131
},
3232
"autoload": {
3333
"psr-4": {"libredte\\api_client\\": "src/"}
34+
},
35+
"scripts": {
36+
"docs": "php tools/phpdocumentor run --config=phpdoc.xml",
37+
"tests": "XDEBUG_MODE=coverage vendor/bin/phpunit --configuration=phpunit.xml",
38+
"tests_dte": "vendor/bin/phpunit --configuration=phpunit.xml --no-coverage --testsuite dte",
39+
"tests_contab": "vendor/bin/phpunit --configuration=phpunit.xml --no-coverage --testsuite contab",
40+
"tests_pagos": "vendor/bin/phpunit --configuration=phpunit.xml --no-coverage --testsuite pagos",
41+
"tests_readonly": "vendor/bin/phpunit --testsuite readonly --filter 'test_dte_buscar_documento_emitido|test_dte_estado|test_dte_consultar|test_dte_ted|test_pagos_buscar_cobro|test_pagos_info_cobro'"
3442
}
3543
}

docs/getting-started/example.rst

Lines changed: 48 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,19 @@
11
Ejemplo
22
=======
33

4-
El siguiente es un ejemplo básico de cómo obtener un documento DTE emitido usando el cliente de API de LibreDTE:
5-
6-
.. code-block:: php
7-
<?php
8-
9-
# Definición de directorio autoload. Necesario si se usa la versión de GitHub.
10-
require_once __DIR__ . '/vendor/autoload.php';
11-
12-
# Importación de biblioteca de LibreDTE
13-
use libredte\api_client\ApiClient;
14-
15-
# Instanciación de cliente de API
16-
$client = new ApiClient();
17-
18-
# RUT del emisor sin Dígito Verificador.
19-
$emisor_rut = 12345678;
20-
# Filtros a aplicar en la búsqueda de DTEs.
21-
$filtros = [
22-
'fecha_desde' => '2024-10-25',
23-
'fecha_hasta' => date('Y-m-d'),
24-
];
25-
26-
# Recurso a consumir.
27-
$resource = sprintf('/dte/dte_tmps/buscar/%d', $emisor_rut);
28-
29-
# Se efectua la solicitud HTTP y se guarda la respuesta. En esta variable están el estado, cuerpo, etc.
30-
$response = $client->post($resource, $filtros);
31-
32-
echo "Status: ".$response['status']['code']."\n";
33-
34-
if ($response['status']['code'] != 200) {
35-
echo $response['body']."\n";
36-
} else {
37-
$documentos = $response['body'];
38-
$dte_id = 'T'.$documentos[0]['dte'].'F'.$documentos[0]['folio'];
39-
40-
echo "\nDTEs Temporales: \n";
41-
echo "\n",'N DOCUMENTOS: ',count($documentos),"\n";
42-
echo "\n",'DTE ID: ',$dte_id,"\n";
43-
echo "\n",'DTE FECHA: ',$documentos[0]['fecha'],"\n";
44-
}
45-
46-
Desgloce de ejemplo
47-
-------------------
4+
Ejemplo de Generar un DTE temporal
5+
-------------------------------
486

497
Antes de probar, integrar y/o utilizar el cliente de API, necesitas haber definido previamente las variables de entorno.
508

519
.. seealso::
5210
Para más información sobre este paso, referirse al la guía en Configuración.
5311

54-
Se empieza por importar e instanciar el cliente de API.
12+
El siguiente es un ejemplo básico de cómo emitir un DTE usando el cliente de API de LibreDTE:
5513

5614
.. code-block:: php
15+
<?php
16+
5717
# Definición de directorio autoload. Necesario si se usa la versión de GitHub.
5818
require_once __DIR__ . '/vendor/autoload.php';
5919
@@ -62,49 +22,61 @@ Se empieza por importar e instanciar el cliente de API.
6222
6323
# Instanciación de cliente de API
6424
$client = new ApiClient();
65-
66-
Luego, se definen las variables a utilizar.
67-
68-
.. code-block:: php
69-
# RUT del emisor sin Dígito Verificador.
70-
$emisor_rut = 12345678;
71-
# Filtros a aplicar en la búsqueda de DTEs.
72-
$filtros = [
73-
'fecha_desde' => '2015-01-01',
74-
'fecha_hasta' => date('Y-m-d'),
25+
# RUT del emisor, con DV.
26+
$emisor_rut = '12345678-9';
27+
28+
# Datos del DTE temporal a crear.
29+
$datos = [
30+
'Encabezado' => [
31+
'IdDoc' => [
32+
'TipoDTE' => 33,
33+
],
34+
'Emisor' => [
35+
'RUTEmisor' => $emisor_rut,
36+
],
37+
'Receptor' => [
38+
'RUTRecep' => '60803000-K',
39+
'RznSocRecep' => 'Servicio de Impuestos Internos (SII)',
40+
'GiroRecep' => 'Administración Pública',
41+
'Contacto' => '+56 2 3252 5575',
42+
'CorreoRecep' => 'facturacionmipyme@sii.cl',
43+
'DirRecep' => 'Teatinos 120',
44+
'CmnaRecep' => 'Santiago',
45+
],
46+
],
47+
'Detalle' => [
48+
[
49+
//'IndExe' => 1, // para items exentos
50+
'NmbItem' => 'Asesoría de LibreDTE',
51+
'QtyItem' => 1,
52+
'PrcItem' => 1000,
53+
],
54+
],
55+
'Referencia' => [
56+
[
57+
'TpoDocRef' => 801,
58+
'FolioRef' => 'OC123',
59+
'FchRef' => '2015-10-01',
60+
]
61+
],
7562
];
7663
77-
Más adelante, se arma el recurso a utilizar, se consume, y se obtiene su respuesta HTTP.
78-
79-
.. code-block:: php
8064
# Recurso a consumir.
81-
$resource = sprintf('/dte/dte_tmps/buscar/%d', $emisor_rut);
65+
$resource = '/dte/documentos/emitir';
8266
8367
# Se efectua la solicitud HTTP y se guarda la respuesta.
84-
$response = $client->post($resource, $filtros);
85-
86-
``$response`` contiene toda la información de la respuesta HTTP, desde el cuerpo hasta el código de estado.
87-
88-
Por último, se despliega en consola el resultado. Si el código de la respuesta HTTP no es 200, se mostrará el mensaje de error. Si es 200, se desplegarán los documentos consultados.
68+
$response = $client->post($resource, $datos);
8969
90-
.. code-block:: php
70+
# Código del response
9171
echo "Status: ".$response['status']['code']."\n";
9272
73+
# Despliegue del body.
9374
if ($response['status']['code'] != 200) {
94-
echo $response['body']."\n";
75+
echo $response['body']."\n"; # Si falla, el body contendrá el mensaje de error.
9576
} else {
96-
$documentos = $response['body'];
97-
$dte_id = 'T'.$documentos[0]['dte'].'F'.$documentos[0]['folio'];
98-
9977
echo "\nDTEs Temporales: \n";
100-
echo "\n",'N DOCUMENTOS: ',count($documentos),"\n";
101-
echo "\n",'DTE ID: ',$dte_id,"\n";
102-
echo "\n",'DTE FECHA: ',$documentos[0]['fecha'],"\n";
78+
echo "\n",'FACTURAR DTE TEMP: ',json_encode($response['body']),"\n";
10379
}
10480
105-
.. important::
106-
Este ejemplo solo funciona con DTEs temporales.
107-
108-
10981
.. seealso::
11082
Para saber más sobre los parámetros posibles y el cómo consumir las API, referirse a la `documentación de LibreDTE. <https://developers.libredte.cl/>`_

docs/index.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
Docs: libredte-api-client-php
22
==============
33

4+
.. image:: https://github.com/libredte/libredte-api-client-php/actions/workflows/ci.yml/badge.svg?branch=master&event=push
5+
:target: https://github.com/libredte/libredte-api-client-php/actions/workflows/ci.yml?query=branch%3Amaster
6+
7+
.. image:: https://scrutinizer-ci.com/g/libredte/libredte-api-client-php/badges/quality-score.png?b=master
8+
:target: https://scrutinizer-ci.com/g/libredte/libredte-api-client-php/
9+
10+
.. image:: https://scrutinizer-ci.com/g/libredte/libredte-api-client-php/badges/coverage.png?b=master
11+
:target: https://scrutinizer-ci.com/g/libredte/libredte-api-client-php/
12+
413
.. image:: https://poser.pugx.org/libredte/libredte-api-client/license
514
:target: https://packagist.org/packages/libredte/libredte-api-client
615

16+
.. image:: https://app.fossa.com/api/projects/git%2Bgithub.com%2FLibreDTE%2Flibredte-api-client-php.svg?type=shield&issueType=license
17+
:target: https://app.fossa.com/projects/git%2Bgithub.com%2FLibreDTE%2Flibredte-api-client-php?ref=badge_shield&issueType=license
18+
19+
.. image:: https://app.fossa.com/api/projects/git%2Bgithub.com%2FLibreDTE%2Flibredte-api-client-php.svg?type=shield&issueType=security
20+
:target: https://app.fossa.com/projects/git%2Bgithub.com%2FLibreDTE%2Flibredte-api-client-php?ref=badge_shield&issueType=security
21+
722
.. image:: https://poser.pugx.org/libredte/libredte-api-client/downloads
823
:target: https://packagist.org/packages/libredte/libredte-api-client
924

phpunit.xml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,54 @@
1-
<phpunit bootstrap="tests/bootstrap.php" colors="true" verbose="true">
1+
<phpunit
2+
backupGlobals="true"
3+
bootstrap="tests/bootstrap.php"
4+
cacheDirectory="var/cache/phpunit"
5+
processIsolation="true"
6+
executionOrder="depends,defects"
7+
colors="true"
8+
testdox="true"
9+
verbose="true"
10+
requireCoverageMetadata="true"
11+
beStrictAboutCoverageMetadata="true"
12+
beStrictAboutOutputDuringTests="false"
13+
beStrictAboutChangesToGlobalState="true"
14+
stopOnError="true"
15+
stopOnFailure="true"
16+
stopOnWarning="true"
17+
stopOnDeprecation="true"
18+
stopOnNotice="true"
19+
failOnEmptyTestSuite="true"
20+
failOnWarning="true"
21+
failOnRisky="true"
22+
failOnDeprecation="true"
23+
failOnPhpunitDeprecation="true"
24+
failOnNotice="true"
25+
>
226
<testsuites>
327
<testsuite name="LibreDTE: Cliente de API en PHP - Pruebas Unitarias.">
428
<directory>tests</directory>
529
</testsuite>
30+
<testsuite name="dte">
31+
<directory>tests/dte_facturacion</directory>
32+
</testsuite>
33+
<testsuite name="contab">
34+
<directory>tests/lce_contabilidad</directory>
35+
</testsuite>
36+
<testsuite name="pagos">
37+
<directory>tests/pagos_cobros_masivos</directory>
38+
</testsuite>
39+
<testsuite name="readonly">
40+
<file>tests/dte_facturacion/BuscarDocumentoEmitidoTest.php</file>
41+
<file>tests/pagos_cobros_masivos/BuscarCobroTest.php</file>
42+
</testsuite>
643
</testsuites>
744
<filter>
845
<whitelist>
946
<directory suffix=".php">src</directory>
1047
</whitelist>
1148
</filter>
49+
<php>
50+
<ini name="memory_limit" value="-1" />
51+
<env name="LIBREDTE_URL" value="https://apigateway.cl" />
52+
<env name="LIBREDTE_RUT" value="76192083-9" />
53+
</php>
1254
</phpunit>

0 commit comments

Comments
 (0)