Skip to content

Commit cfb47a8

Browse files
committed
Se rehicieron los tests dte_facturacion y pagos_cobros_masivos, conservando algunos de cobros, y de lce_contabilidad. Se añadió documentación a los tests. Se añadieron clases padre (abstract) para reciclar y reducir código. Se modificó composer.json y phpunit.xml para utilizar los tests nuevos. Se cambió la nomenclatura de los métodos de los tests. Se actualizó documentación de prueba unitaria. Se actualizó el workflow ci.yml.
1 parent 7e7dec9 commit cfb47a8

24 files changed

Lines changed: 1366 additions & 645 deletions

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ jobs:
3434
LIBREDTE_HASH: ${{ secrets.LIBREDTE_HASH }}
3535
LIBREDTE_RUT: ${{ vars.LIBREDTE_RUT }}
3636
run: |
37-
composer tests_dte_temp
37+
composer tests-dte
38+
composer tests-cobros
3839
3940
- name: Upload PHPUnit result report
4041
if: failure()

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
vendor/
22
tests/test.env
3+
tests/archivos/
34

45
var/
56
tools/

composer.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@
3131
"vlucas/phpdotenv": "^5.6"
3232
},
3333
"autoload": {
34-
"psr-4": {"libredte\\api_client\\": "src/"}
34+
"psr-4": {
35+
"libredte\\api_client\\": "src/",
36+
"libredte\\dte_facturacion\\": "tests/dte_facturacion/",
37+
"libredte\\pagos_cobros_masivos\\": "tests/pagos_cobros_masivos/"
38+
}
3539
},
3640
"scripts": {
3741
"docs": "php tools/phpdocumentor run --config=phpdoc.xml",
3842
"tests": "XDEBUG_MODE=coverage vendor/bin/phpunit --configuration=phpunit.xml",
39-
"tests_dte": "vendor/bin/phpunit --configuration=phpunit.xml --no-coverage --testsuite dte",
40-
"tests_contab": "vendor/bin/phpunit --configuration=phpunit.xml --no-coverage --testsuite contab",
41-
"tests_pagos": "vendor/bin/phpunit --configuration=phpunit.xml --no-coverage --testsuite pagos",
42-
"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'",
43-
"tests_dte_temp": "XDEBUG_MODE=coverage vendor/bin/phpunit --configuration=phpunit.xml --testsuite dte_temp",
43+
"tests-dte": "XDEBUG_MODE=coverage vendor/bin/phpunit --configuration=phpunit.xml --testsuite dte-facturacion",
44+
"tests-cobros": "XDEBUG_MODE=coverage vendor/bin/phpunit --configuration=phpunit.xml --testsuite pagos-cobros-mas",
45+
"tests-readonly": "XDEBUG_MODE=coverage vendor/bin/phpunit --configuration=phpunit.xml --testsuite readonly",
4446
"phpcs-fix": "php-cs-fixer fix -v --config=php-cs-fixer.php .",
4547
"phpcs-fix-dry-run": "php-cs-fixer fix -v --dry-run --diff --config=php-cs-fixer.php .",
4648
"phpstan": "phpstan analyse --configuration=phpstan.neon --memory-limit=1G",

docs/dev/unit-test.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ Para ejecutar las pruebas unitarias se necesita tener instaladas las dependencia
1919
También es posible ejecutar una prueba específica indicando el test. Ejemplo:
2020

2121
.. code-block:: shell
22-
./vendor/bin/phpunit --filter test_dte_buscar_documento_emitido
22+
./vendor/bin/phpunit --filter testEmitirDteTemp --no-coverage

phpunit.xml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,15 @@
2828
</include>
2929
</source>
3030
<testsuites>
31-
<testsuite name="LibreDTE: Cliente de API en PHP - Pruebas Unitarias.">
32-
<directory>tests</directory>
33-
</testsuite>
34-
<testsuite name="dte">
31+
<testsuite name="dte-facturacion">
3532
<directory>tests/dte_facturacion</directory>
3633
</testsuite>
37-
<testsuite name="contab">
34+
<testsuite name="lce-contabilidad">
3835
<directory>tests/lce_contabilidad</directory>
3936
</testsuite>
40-
<testsuite name="pagos">
37+
<testsuite name="pagos-cobros-mas">
4138
<directory>tests/pagos_cobros_masivos</directory>
4239
</testsuite>
43-
<testsuite name="readonly">
44-
<file>tests/dte_facturacion/BuscarDocumentoEmitidoTest.php</file>
45-
<file>tests/pagos_cobros_masivos/BuscarCobroTest.php</file>
46-
</testsuite>
47-
<testsuite name="dte_temp">
48-
<file>tests/dte_facturacion/EmitirDteTemporalTest.php</file>
49-
</testsuite>
5040
</testsuites>
5141
<coverage
5242
ignoreDeprecatedCodeUnits="true"
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* LibreDTE: Cliente de API en PHP - Pruebas Unitarias.
7+
* Copyright (C) LibreDTE <https://www.libredte.cl>
8+
*
9+
* Este programa es software libre: usted puede redistribuirlo y/o modificarlo
10+
* bajo los términos de la GNU Lesser General Public License (LGPL) publicada
11+
* por la Fundación para el Software Libre, ya sea la versión 3 de la Licencia,
12+
* o (a su elección) cualquier versión posterior de la misma.
13+
*
14+
* Este programa se distribuye con la esperanza de que sea útil, pero SIN
15+
* GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD
16+
* PARA UN PROPÓSITO DETERMINADO. Consulte los detalles de la GNU Lesser General
17+
* Public License (LGPL) para obtener una información más detallada.
18+
*
19+
* Debería haber recibido una copia de la GNU Lesser General Public License
20+
* (LGPL) junto a este programa. En caso contrario, consulte
21+
* <http://www.gnu.org/licenses/lgpl.html>.
22+
*/
23+
24+
namespace libredte\dte_facturacion;
25+
26+
use libredte\api_client\ApiClient;
27+
use libredte\api_client\ApiException;
28+
use PHPUnit\Framework\TestCase;
29+
30+
abstract class AbstractDteFacturacion extends TestCase
31+
{
32+
/**
33+
* Variable para desplegar resultados.
34+
*
35+
* @var bool
36+
*/
37+
protected static $verbose;
38+
39+
/**
40+
* Variable instancia del API Client.
41+
*
42+
* @var ApiClient
43+
*/
44+
protected static $client;
45+
46+
/**
47+
* RUT del emisor a utilizar.
48+
*
49+
* @var int
50+
*/
51+
protected static $emisor_rut;
52+
53+
/**
54+
* Datos para producir el DTE temporal.
55+
*
56+
* @var array
57+
*/
58+
private static $datos = [
59+
'Encabezado' => [
60+
'IdDoc' => [
61+
'TipoDTE' => 33,
62+
],
63+
'Emisor' => [
64+
'RUTEmisor' => null, // se reemplaza al preparar la clase
65+
],
66+
'Receptor' => [
67+
'RUTRecep' => '60803000-K',
68+
'RznSocRecep' => 'Servicio de Impuestos Internos (SII)',
69+
'GiroRecep' => 'Administración Pública',
70+
'Contacto' => '+56 2 3252 5575',
71+
'CorreoRecep' => 'facturacionmipyme@sii.cl',
72+
'DirRecep' => 'Teatinos 120',
73+
'CmnaRecep' => 'Santiago',
74+
],
75+
],
76+
'Detalle' => [
77+
[
78+
//'IndExe' => 1, // para items exentos
79+
'NmbItem' => 'Asesoría de LibreDTE',
80+
'QtyItem' => 1,
81+
'PrcItem' => 1000,
82+
],
83+
],
84+
'Referencia' => [
85+
[
86+
'TpoDocRef' => 801,
87+
'FolioRef' => 'OC123',
88+
'FchRef' => '2015-10-01',
89+
],
90+
],
91+
];
92+
93+
/**
94+
* Inicialización de variables y clases pre ejecución de tests.
95+
*
96+
* @return void
97+
*/
98+
public static function setUpBeforeClass(): void
99+
{
100+
self::$verbose = (bool)env('TEST_VERBOSE', 'false');
101+
self::$emisor_rut = (explode('-', (string)env('LIBREDTE_RUT'))[0]);
102+
self::$datos['Encabezado']['Emisor']['RUTEmisor'] = env('LIBREDTE_RUT');
103+
self::$client = new ApiClient();
104+
}
105+
106+
/**
107+
* Método para listar DTEs temporales.
108+
*
109+
* @throws \libredte\api_client\ApiException
110+
*
111+
* @return array Listado de DTEs temporales entre 2015 y hoy.
112+
*/
113+
protected function listarDteTemp(): array
114+
{
115+
# Se crea el filtro a utilizar, en este caso fechas de búsqueda.
116+
$filtros = [
117+
'fecha_desde' => '2015-01-01',
118+
'fecha_hasta' => date('Y-m-d'),
119+
];
120+
# Se genera el recurso a consumir.
121+
$resource = sprintf('/dte/dte_tmps/buscar/%d', self::$emisor_rut);
122+
# Se envía la solicitud http y se guarda su respuesta.
123+
$response = self::$client->post($resource, $filtros);
124+
125+
# Si el código http no es '200', arroja error ApiException.
126+
if ($response['status']['code'] !== '200') {
127+
throw new ApiException($response['body'], (int)$response['status']['code']);
128+
}
129+
130+
# Retorna la respuesta http.
131+
return $response;
132+
}
133+
134+
/**
135+
* Método para emitir un DTE temporal.
136+
*
137+
* @throws \libredte\api_client\ApiException
138+
*
139+
* @return array DTE temporal generado.
140+
*/
141+
protected function emitirDteTemp(): array
142+
{
143+
# Se envía la solicitud http y se guarda su respuesta.
144+
$response = self::$client->post('/dte/documentos/emitir', self::$datos);
145+
146+
# Si el código http no es '200', arroja error ApiException.
147+
if ($response['status']['code'] !== '200') {
148+
throw new ApiException($response['body'], (int)$response['status']['code']);
149+
}
150+
151+
# Retorna la respuesta http.
152+
return $response;
153+
}
154+
}

0 commit comments

Comments
 (0)