Compare commits
14 Commits
38fb6f3bcc
...
360537c638
Author | SHA1 | Date | |
---|---|---|---|
360537c638 | |||
a6e6b8acc0 | |||
a4e2b4fc7a | |||
479047cd6a | |||
29d9ea8e4a | |||
a7cd661938 | |||
7bdcc7168a | |||
d2dff57531 | |||
39198bbe7c | |||
200510d60a | |||
ecc67a43c8 | |||
64791d1fc5 | |||
4053854410 | |||
a687743762 |
@ -10,7 +10,8 @@ class CreateTipoEstadoPago extends Phinx\Migration\AbstractMigration
|
|||||||
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
|
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
|
||||||
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
||||||
|
|
||||||
$this->table('tipo_estado_pago')
|
$this->table('tipo_estado_pago', ['id' => false, 'primary_key' => 'id'])
|
||||||
|
->addColumn('id', 'integer', ['signed' => true])
|
||||||
->addColumn('descripcion', 'string', ['length' => 20, 'default' => null, 'null' => true])
|
->addColumn('descripcion', 'string', ['length' => 20, 'default' => null, 'null' => true])
|
||||||
->addColumn('active', 'integer', ['length' => 1, 'default' => 0])
|
->addColumn('active', 'integer', ['length' => 1, 'default' => 0])
|
||||||
->create();
|
->create();
|
||||||
|
391
app/resources/database/seeds/Comuna.php
Normal file
391
app/resources/database/seeds/Comuna.php
Normal file
@ -0,0 +1,391 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Seed\AbstractSeed;
|
||||||
|
|
||||||
|
class Comuna extends AbstractSeed
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run Method.
|
||||||
|
*
|
||||||
|
* Write your database seeder using this method.
|
||||||
|
*
|
||||||
|
* More information on writing seeders is available here:
|
||||||
|
* https://book.cakephp.org/phinx/0/en/seeding.html
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
/*id descripcion provincia
|
||||||
|
1101 Iquique 11
|
||||||
|
1107 Alto Hospicio 11
|
||||||
|
1401 Pozo Almonte 14
|
||||||
|
1402 Camiña 14
|
||||||
|
1403 Colchane 14
|
||||||
|
1404 Huara 14
|
||||||
|
1405 Pica 14
|
||||||
|
2101 Antofagasta 21
|
||||||
|
2102 Mejillones 21
|
||||||
|
2103 Sierra Gorda 21
|
||||||
|
2104 Taltal 21
|
||||||
|
2201 Calama 22
|
||||||
|
2202 Ollagüe 22
|
||||||
|
2203 San Pedro de Atacama 22
|
||||||
|
2301 Tocopilla 23
|
||||||
|
2302 María Elena 23
|
||||||
|
3101 Copiapó 31
|
||||||
|
3102 Caldera 31
|
||||||
|
3103 Tierra Amarilla 31
|
||||||
|
3201 Chañaral 32
|
||||||
|
3202 Diego de Almagro 32
|
||||||
|
3301 Vallenar 33
|
||||||
|
3302 Alto del Carmen 33
|
||||||
|
3303 Freirina 33
|
||||||
|
3304 Huasco 33
|
||||||
|
4101 La Serena 41
|
||||||
|
4102 Coquimbo 41
|
||||||
|
4103 Andacollo 41
|
||||||
|
4104 La Higuera 41
|
||||||
|
4105 Paiguano 41
|
||||||
|
4106 Vicuña 41
|
||||||
|
4201 Illapel 42
|
||||||
|
4202 Canela 42
|
||||||
|
4203 Los Vilos 42
|
||||||
|
4204 Salamanca 42
|
||||||
|
4301 Ovalle 43
|
||||||
|
4302 Combarbalá 43
|
||||||
|
4303 Monte Patria 43
|
||||||
|
4304 Punitaqui 43
|
||||||
|
4305 Río Hurtado 43
|
||||||
|
5101 Valparaíso 51
|
||||||
|
5102 Casablanca 51
|
||||||
|
5103 Concón 51
|
||||||
|
5104 Juan Fernández 51
|
||||||
|
5105 Puchuncaví 51
|
||||||
|
5107 Quintero 51
|
||||||
|
5109 Viña del Mar 51
|
||||||
|
5201 Isla de Pascua 52
|
||||||
|
5301 Los Andes 53
|
||||||
|
5302 Calle Larga 53
|
||||||
|
5303 Rinconada 53
|
||||||
|
5304 San Esteban 53
|
||||||
|
5401 La Ligua 54
|
||||||
|
5402 Cabildo 54
|
||||||
|
5403 Papudo 54
|
||||||
|
5404 Petorca 54
|
||||||
|
5405 Zapallar 54
|
||||||
|
5501 Quillota 55
|
||||||
|
5502 Calera 55
|
||||||
|
5503 Hijuelas 55
|
||||||
|
5504 La Cruz 55
|
||||||
|
5506 Nogales 55
|
||||||
|
5601 San Antonio 56
|
||||||
|
5602 Algarrobo 56
|
||||||
|
5603 Cartagena 56
|
||||||
|
5604 El Quisco 56
|
||||||
|
5605 El Tabo 56
|
||||||
|
5606 Santo Domingo 56
|
||||||
|
5701 San Felipe 57
|
||||||
|
5702 Catemu 57
|
||||||
|
5703 Llaillay 57
|
||||||
|
5704 Panquehue 57
|
||||||
|
5705 Putaendo 57
|
||||||
|
5706 Santa María 57
|
||||||
|
5801 Quilpué 58
|
||||||
|
5802 Limache 58
|
||||||
|
5803 Olmué 58
|
||||||
|
5804 Villa Alemana 58
|
||||||
|
6101 Rancagua 61
|
||||||
|
6102 Codegua 61
|
||||||
|
6103 Coinco 61
|
||||||
|
6104 Coltauco 61
|
||||||
|
6105 Doñihue 61
|
||||||
|
6106 Graneros 61
|
||||||
|
6107 Las Cabras 61
|
||||||
|
6108 Machalí 61
|
||||||
|
6109 Malloa 61
|
||||||
|
6110 Mostazal 61
|
||||||
|
6111 Olivar 61
|
||||||
|
6112 Peumo 61
|
||||||
|
6113 Pichidegua 61
|
||||||
|
6114 Quinta de Tilcoco 61
|
||||||
|
6115 Rengo 61
|
||||||
|
6116 Requínoa 61
|
||||||
|
6117 San Vicente 61
|
||||||
|
6201 Pichilemu 62
|
||||||
|
6202 La Estrella 62
|
||||||
|
6203 Litueche 62
|
||||||
|
6204 Marchihue 62
|
||||||
|
6205 Navidad 62
|
||||||
|
6206 Paredones 62
|
||||||
|
6301 San Fernando 63
|
||||||
|
6302 Chépica 63
|
||||||
|
6303 Chimbarongo 63
|
||||||
|
6304 Lolol 63
|
||||||
|
6305 Nancagua 63
|
||||||
|
6306 Palmilla 63
|
||||||
|
6307 Peralillo 63
|
||||||
|
6308 Placilla 63
|
||||||
|
6309 Pumanque 63
|
||||||
|
6310 Santa Cruz 63
|
||||||
|
7101 Talca 71
|
||||||
|
7102 Constitución 71
|
||||||
|
7103 Curepto 71
|
||||||
|
7104 Empedrado 71
|
||||||
|
7105 Maule 71
|
||||||
|
7106 Pelarco 71
|
||||||
|
7107 Pencahue 71
|
||||||
|
7108 Río Claro 71
|
||||||
|
7109 San Clemente 71
|
||||||
|
7110 San Rafael 71
|
||||||
|
7201 Cauquenes 72
|
||||||
|
7202 Chanco 72
|
||||||
|
7203 Pelluhue 72
|
||||||
|
7301 Curicó 73
|
||||||
|
7302 Hualañé 73
|
||||||
|
7303 Licantén 73
|
||||||
|
7304 Molina 73
|
||||||
|
7305 Rauco 73
|
||||||
|
7306 Romeral 73
|
||||||
|
7307 Sagrada Familia 73
|
||||||
|
7308 Teno 73
|
||||||
|
7309 Vichuquén 73
|
||||||
|
7401 Linares 74
|
||||||
|
7402 Colbún 74
|
||||||
|
7403 Longaví 74
|
||||||
|
7404 Parral 74
|
||||||
|
7405 Retiro 74
|
||||||
|
7406 San Javier 74
|
||||||
|
7407 Villa Alegre 74
|
||||||
|
7408 Yerbas Buenas 74
|
||||||
|
8101 Concepción 81
|
||||||
|
8102 Coronel 81
|
||||||
|
8103 Chiguayante 81
|
||||||
|
8104 Florida 81
|
||||||
|
8105 Hualqui 81
|
||||||
|
8106 Lota 81
|
||||||
|
8107 Penco 81
|
||||||
|
8108 San Pedro de la Paz 81
|
||||||
|
8109 Santa Juana 81
|
||||||
|
8110 Talcahuano 81
|
||||||
|
8111 Tomé 81
|
||||||
|
8112 Hualpén 81
|
||||||
|
8201 Lebu 82
|
||||||
|
8202 Arauco 82
|
||||||
|
8203 Cañete 82
|
||||||
|
8204 Contulmo 82
|
||||||
|
8205 Curanilahue 82
|
||||||
|
8206 Los Álamos 82
|
||||||
|
8207 Tirúa 82
|
||||||
|
8301 Los Ángeles 83
|
||||||
|
8302 Antuco 83
|
||||||
|
8303 Cabrero 83
|
||||||
|
8304 Laja 83
|
||||||
|
8305 Mulchén 83
|
||||||
|
8306 Nacimiento 83
|
||||||
|
8307 Negrete 83
|
||||||
|
8308 Quilaco 83
|
||||||
|
8309 Quilleco 83
|
||||||
|
8310 San Rosendo 83
|
||||||
|
8311 Santa Bárbara 83
|
||||||
|
8312 Tucapel 83
|
||||||
|
8313 Yumbel 83
|
||||||
|
8314 Alto Biobío 83
|
||||||
|
8401 Chillán 84
|
||||||
|
8402 Bulnes 84
|
||||||
|
8403 Cobquecura 84
|
||||||
|
8404 Coelemu 84
|
||||||
|
8405 Coihueco 84
|
||||||
|
8406 Chillán Viejo 84
|
||||||
|
8407 El Carmen 84
|
||||||
|
8408 Ninhue 84
|
||||||
|
8409 Ñiquén 84
|
||||||
|
8410 Pemuco 84
|
||||||
|
8411 Pinto 84
|
||||||
|
8412 Portezuelo 84
|
||||||
|
8413 Quillón 84
|
||||||
|
8414 Quirihue 84
|
||||||
|
8415 Ránquil 84
|
||||||
|
8416 San Carlos 84
|
||||||
|
8417 San Fabián 84
|
||||||
|
8418 San Ignacio 84
|
||||||
|
8419 San Nicolás 84
|
||||||
|
8420 Treguaco 84
|
||||||
|
8421 Yungay 84
|
||||||
|
9101 Temuco 91
|
||||||
|
9102 Carahue 91
|
||||||
|
9103 Cunco 91
|
||||||
|
9104 Curarrehue 91
|
||||||
|
9105 Freire 91
|
||||||
|
9106 Galvarino 91
|
||||||
|
9107 Gorbea 91
|
||||||
|
9108 Lautaro 91
|
||||||
|
9109 Loncoche 91
|
||||||
|
9110 Melipeuco 91
|
||||||
|
9111 Nueva Imperial 91
|
||||||
|
9112 Padre las Casas 91
|
||||||
|
9113 Perquenco 91
|
||||||
|
9114 Pitrufquén 91
|
||||||
|
9115 Pucón 91
|
||||||
|
9116 Saavedra 91
|
||||||
|
9117 Teodoro Schmidt 91
|
||||||
|
9118 Toltén 91
|
||||||
|
9119 Vilcún 91
|
||||||
|
9120 Villarrica 91
|
||||||
|
9121 Cholchol 91
|
||||||
|
9201 Angol 92
|
||||||
|
9202 Collipulli 92
|
||||||
|
9203 Curacautín 92
|
||||||
|
9204 Ercilla 92
|
||||||
|
9205 Lonquimay 92
|
||||||
|
9206 Los Sauces 92
|
||||||
|
9207 Lumaco 92
|
||||||
|
9208 Purén 92
|
||||||
|
9209 Renaico 92
|
||||||
|
9210 Traiguén 92
|
||||||
|
9211 Victoria 92
|
||||||
|
10101 Puerto Montt 101
|
||||||
|
10102 Calbuco 101
|
||||||
|
10103 Cochamó 101
|
||||||
|
10104 Fresia 101
|
||||||
|
10105 Frutillar 101
|
||||||
|
10106 Los Muermos 101
|
||||||
|
10107 Llanquihue 101
|
||||||
|
10108 Maullín 101
|
||||||
|
10109 Puerto Varas 101
|
||||||
|
10201 Castro 102
|
||||||
|
10202 Ancud 102
|
||||||
|
10203 Chonchi 102
|
||||||
|
10204 Curaco de Vélez 102
|
||||||
|
10205 Dalcahue 102
|
||||||
|
10206 Puqueldón 102
|
||||||
|
10207 Queilén 102
|
||||||
|
10208 Quellón 102
|
||||||
|
10209 Quemchi 102
|
||||||
|
10210 Quinchao 102
|
||||||
|
10301 Osorno 103
|
||||||
|
10302 Puerto Octay 103
|
||||||
|
10303 Purranque 103
|
||||||
|
10304 Puyehue 103
|
||||||
|
10305 Río Negro 103
|
||||||
|
10306 San Juan de la Costa 103
|
||||||
|
10307 San Pablo 103
|
||||||
|
10401 Chaitén 104
|
||||||
|
10402 Futaleufú 104
|
||||||
|
10403 Hualaihué 104
|
||||||
|
10404 Palena 104
|
||||||
|
11101 Coihaique 111
|
||||||
|
11102 Lago Verde 111
|
||||||
|
11201 Aisén 112
|
||||||
|
11202 Cisnes 112
|
||||||
|
11203 Guaitecas 112
|
||||||
|
11301 Cochrane 113
|
||||||
|
11302 O’Higgins 113
|
||||||
|
11303 Tortel 113
|
||||||
|
11401 Chile Chico 114
|
||||||
|
11402 Río Ibáñez 114
|
||||||
|
12101 Punta Arenas 121
|
||||||
|
12102 Laguna Blanca 121
|
||||||
|
12103 Río Verde 121
|
||||||
|
12104 San Gregorio 121
|
||||||
|
12201 Cabo de Hornos (Ex Navarino) 122
|
||||||
|
12202 Antártica 122
|
||||||
|
12301 Porvenir 123
|
||||||
|
12302 Primavera 123
|
||||||
|
12303 Timaukel 123
|
||||||
|
12401 Natales 124
|
||||||
|
12402 Torres del Paine 124
|
||||||
|
13101 Santiago 131
|
||||||
|
13102 Cerrillos 131
|
||||||
|
13103 Cerro Navia 131
|
||||||
|
13104 Conchalí 131
|
||||||
|
13105 El Bosque 131
|
||||||
|
13106 Estación Central 131
|
||||||
|
13107 Huechuraba 131
|
||||||
|
13108 Independencia 131
|
||||||
|
13109 La Cisterna 131
|
||||||
|
13110 La Florida 131
|
||||||
|
13111 La Granja 131
|
||||||
|
13112 La Pintana 131
|
||||||
|
13113 La Reina 131
|
||||||
|
13114 Las Condes 131
|
||||||
|
13115 Lo Barnechea 131
|
||||||
|
13116 Lo Espejo 131
|
||||||
|
13117 Lo Prado 131
|
||||||
|
13118 Macul 131
|
||||||
|
13119 Maipú 131
|
||||||
|
13120 Ñuñoa 131
|
||||||
|
13121 Pedro Aguirre Cerda 131
|
||||||
|
13122 Peñalolén 131
|
||||||
|
13123 Providencia 131
|
||||||
|
13124 Pudahuel 131
|
||||||
|
13125 Quilicura 131
|
||||||
|
13126 Quinta Normal 131
|
||||||
|
13127 Recoleta 131
|
||||||
|
13128 Renca 131
|
||||||
|
13129 San Joaquín 131
|
||||||
|
13130 San Miguel 131
|
||||||
|
13131 San Ramón 131
|
||||||
|
13132 Vitacura 131
|
||||||
|
13201 Puente Alto 132
|
||||||
|
13202 Pirque 132
|
||||||
|
13203 San José de Maipo 132
|
||||||
|
13301 Colina 133
|
||||||
|
13302 Lampa 133
|
||||||
|
13303 Tiltil 133
|
||||||
|
13401 San Bernardo 134
|
||||||
|
13402 Buin 134
|
||||||
|
13403 Calera de Tango 134
|
||||||
|
13404 Paine 134
|
||||||
|
13501 Melipilla 135
|
||||||
|
13502 Alhué 135
|
||||||
|
13503 Curacaví 135
|
||||||
|
13504 María Pinto 135
|
||||||
|
13505 San Pedro 135
|
||||||
|
13601 Talagante 136
|
||||||
|
13602 El Monte 136
|
||||||
|
13603 Isla de Maipo 136
|
||||||
|
13604 Padre Hurtado 136
|
||||||
|
13605 Peñaflor 136
|
||||||
|
14101 Valdivia 141
|
||||||
|
14102 Corral 141
|
||||||
|
14103 Lanco 141
|
||||||
|
14104 Los Lagos 141
|
||||||
|
14105 Máfil 141
|
||||||
|
14106 Mariquina 141
|
||||||
|
14107 Paillaco 141
|
||||||
|
14108 Panguipulli 141
|
||||||
|
14201 La Unión 142
|
||||||
|
14202 Futrono 142
|
||||||
|
14203 Lago Ranco 142
|
||||||
|
14204 Río Bueno 142
|
||||||
|
15101 Arica 151
|
||||||
|
15102 Camarones 151
|
||||||
|
15201 Putre 152
|
||||||
|
15202 General Lagos 152
|
||||||
|
*/
|
||||||
|
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
|
||||||
|
|
||||||
|
$table = $this->table('comuna');
|
||||||
|
$table->truncate();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
['id' => 1101, 'descripcion' => 'Iquique', 'provincia' => 11],
|
||||||
|
['id' => 1107, 'descripcion' => 'Alto Hospicio', 'provincia' => 11],
|
||||||
|
['id' => 1401, 'descripcion' => 'Pozo Almonte', 'provincia' => 14],
|
||||||
|
['id' => 1402, 'descripcion' => 'Camiña', 'provincia' => 14],
|
||||||
|
['id' => 1403, 'descripcion' => 'Colchane', 'provincia' => 14],
|
||||||
|
['id' => 1404, 'descripcion' => 'Huara', 'provincia' => 14],
|
||||||
|
['id' => 1405, 'descripcion' => 'Pica', 'provincia' => 14],
|
||||||
|
['id' => 2101, 'descripcion' => 'Antofagasta', 'provincia' => 21],
|
||||||
|
['id' => 2102, 'descripcion' => 'Mejillones', 'provincia' => 21],
|
||||||
|
['id' => 2103, 'descripcion' => 'Sierra Gorda', 'provincia' => 21],
|
||||||
|
['id' => 2104, 'descripcion' => 'Taltal', 'provincia' => 21],
|
||||||
|
['id' => 2201, 'descripcion' => 'Calama', 'provincia' => 22],
|
||||||
|
['id' => 2202, 'descripcion' => 'Ollagüe', 'provincia' => 22],
|
||||||
|
['id' => 2203, 'descripcion' => 'San Pedro de Alcántara', 'provincia' => 22],
|
||||||
|
['id' => 2301, 'descripcion' => 'Tocopilla', 'provincia' => 23],
|
||||||
|
['id' => 2302, 'descripcion' => 'María Elena', 'provincia' => 23],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
36
app/resources/database/seeds/TipoEstadoPago.php
Normal file
36
app/resources/database/seeds/TipoEstadoPago.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Seed\AbstractSeed;
|
||||||
|
|
||||||
|
class TipoEstadoPago extends AbstractSeed
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run Method.
|
||||||
|
*
|
||||||
|
* Write your database seeder using this method.
|
||||||
|
*
|
||||||
|
* More information on writing seeders is available here:
|
||||||
|
* https://book.cakephp.org/phinx/0/en/seeding.html
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
|
||||||
|
|
||||||
|
$table = $this->table('tipo_estado_pago');
|
||||||
|
$table->truncate();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
['id' => -3, 'descripcion' => 'anulado'],
|
||||||
|
['id' => -2, 'descripcion' => 'reemplazado'],
|
||||||
|
['id' => -1, 'descripcion' => 'devuelto'],
|
||||||
|
['id' => 0, 'descripcion' => 'no pagado', 'active' => 1],
|
||||||
|
['id' => 1, 'descripcion' => 'depositado', 'active' => 1],
|
||||||
|
['id' => 2, 'descripcion' => 'abonado', 'active' => 1],
|
||||||
|
];
|
||||||
|
$table->insert($data)->saveData();
|
||||||
|
|
||||||
|
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||||
|
}
|
||||||
|
}
|
@ -5,28 +5,8 @@ use DI\Bridge\Slim\Bridge;
|
|||||||
require_once 'composer.php';
|
require_once 'composer.php';
|
||||||
|
|
||||||
function buildApp() {
|
function buildApp() {
|
||||||
$builder = new ContainerBuilder();
|
require_once 'container.php';
|
||||||
$folders = [
|
$app = Bridge::create(buildContainer());
|
||||||
'settings',
|
|
||||||
'setups'
|
|
||||||
];
|
|
||||||
foreach ($folders as $folder_name) {
|
|
||||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
|
||||||
__DIR__,
|
|
||||||
$folder_name
|
|
||||||
]);
|
|
||||||
if (!file_exists($folder)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$files = new FilesystemIterator($folder);
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if ($file->isDir()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$builder->addDefinitions($file->getRealPath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$app = Bridge::create($builder->build());
|
|
||||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||||
__DIR__,
|
__DIR__,
|
||||||
'middlewares'
|
'middlewares'
|
||||||
|
33
app/setup/container.php
Normal file
33
app/setup/container.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
use DI\ContainerBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ContainerInterface
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
function buildContainer(): ContainerInterface
|
||||||
|
{
|
||||||
|
$builder = new ContainerBuilder();
|
||||||
|
$folders = [
|
||||||
|
'settings',
|
||||||
|
'setups'
|
||||||
|
];
|
||||||
|
foreach ($folders as $folder_name) {
|
||||||
|
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||||
|
__DIR__,
|
||||||
|
$folder_name
|
||||||
|
]);
|
||||||
|
if (!file_exists($folder)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$files = new FilesystemIterator($folder);
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if ($file->isDir()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$builder->addDefinitions($file->getRealPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $builder->build();
|
||||||
|
}
|
@ -169,6 +169,7 @@ return [
|
|||||||
$container->get(Incoviba\Service\Worker\Request::class)
|
$container->get(Incoviba\Service\Worker\Request::class)
|
||||||
)
|
)
|
||||||
->register('request', $container->get(Incoviba\Service\Worker\Request::class))
|
->register('request', $container->get(Incoviba\Service\Worker\Request::class))
|
||||||
|
->register('service', $container->get(Incoviba\Service\Worker\Service::class))
|
||||||
->register('dummy', $container->get(Incoviba\Service\Worker\Dummy::class))
|
->register('dummy', $container->get(Incoviba\Service\Worker\Dummy::class))
|
||||||
->register('checkExternal', $container->get(Incoviba\Service\Worker\CheckExternal::class));
|
->register('checkExternal', $container->get(Incoviba\Service\Worker\CheckExternal::class));
|
||||||
},
|
},
|
||||||
|
@ -34,6 +34,10 @@ class Queue extends Ideal\Service
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public function push(array $configuration): bool
|
||||||
|
{
|
||||||
|
return $this->enqueue($configuration);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
|
@ -18,9 +18,13 @@ class UF
|
|||||||
|
|
||||||
public function get(?DateTimeInterface $date = null): float
|
public function get(?DateTimeInterface $date = null): float
|
||||||
{
|
{
|
||||||
|
$today = new DateTimeImmutable();
|
||||||
if ($date === null) {
|
if ($date === null) {
|
||||||
$date = new DateTimeImmutable();
|
$date = new DateTimeImmutable();
|
||||||
}
|
}
|
||||||
|
if ($date->diff($today)->days < 0) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 1 - Redis
|
* 1 - Redis
|
||||||
* 2 - DB
|
* 2 - DB
|
||||||
|
@ -20,7 +20,8 @@ class Pago
|
|||||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
||||||
protected Service\UF $ufService,
|
protected Service\UF $ufService,
|
||||||
protected Service\Valor $valorService
|
protected Service\Valor $valorService,
|
||||||
|
protected Service\Queue $queueService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||||
@ -89,13 +90,23 @@ class Pago
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int|null $pago_id
|
||||||
|
* @return Model\Venta\Pago|null
|
||||||
|
* @throws Read
|
||||||
|
*/
|
||||||
public function getById(?int $pago_id): ?Model\Venta\Pago
|
public function getById(?int $pago_id): ?Model\Venta\Pago
|
||||||
{
|
{
|
||||||
if ($pago_id === null) {
|
if ($pago_id === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$pago = $this->pagoRepository->fetchById($pago_id);
|
try {
|
||||||
return $this->process($pago);
|
$pago = $this->pagoRepository->fetchById($pago_id);
|
||||||
|
return $this->process($pago);
|
||||||
|
} catch (EmptyResult) {
|
||||||
|
throw new Read(__CLASS__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByVenta(int $venta_id): array
|
public function getByVenta(int $venta_id): array
|
||||||
@ -144,9 +155,6 @@ class Pago
|
|||||||
$fecha = new DateTimeImmutable();
|
$fecha = new DateTimeImmutable();
|
||||||
}
|
}
|
||||||
$data['fecha'] = $fecha->format('Y-m-d');
|
$data['fecha'] = $fecha->format('Y-m-d');
|
||||||
if (!array_key_exists('uf', $data)) {
|
|
||||||
$data['uf'] = $this->ufService->get($fecha);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$data['valor'] = $this->valorService->toPesos($this->valorService->clean($data['valor']), $data['fecha']);
|
$data['valor'] = $this->valorService->toPesos($this->valorService->clean($data['valor']), $data['fecha']);
|
||||||
|
|
||||||
@ -158,6 +166,9 @@ class Pago
|
|||||||
} catch (PDOException $exception) {
|
} catch (PDOException $exception) {
|
||||||
throw new Create(__CLASS__, $exception);
|
throw new Create(__CLASS__, $exception);
|
||||||
}
|
}
|
||||||
|
if (!array_key_exists('uf', $data)) {
|
||||||
|
$this->getUFAsync($pago);
|
||||||
|
}
|
||||||
|
|
||||||
$tipoEstado = $this->tipoEstadoPagoRepository->fetchByDescripcion('no pagado');
|
$tipoEstado = $this->tipoEstadoPagoRepository->fetchByDescripcion('no pagado');
|
||||||
try {
|
try {
|
||||||
@ -226,6 +237,21 @@ class Pago
|
|||||||
|
|
||||||
return $this->process($this->pagoRepository->fetchById($pago->id));
|
return $this->process($this->pagoRepository->fetchById($pago->id));
|
||||||
}
|
}
|
||||||
|
public function updateUF(int $pago_id): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$pago = $this->getById($pago_id);
|
||||||
|
} catch (Read) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$uf = $this->ufService->get($pago->currentEstado->fecha);
|
||||||
|
try {
|
||||||
|
$this->pagoRepository->edit($pago, ['uf' => $uf]);
|
||||||
|
return true;
|
||||||
|
} catch (EmptyResult | PDOException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function process($pago): Model\Venta\Pago
|
protected function process($pago): Model\Venta\Pago
|
||||||
{
|
{
|
||||||
@ -258,4 +284,14 @@ class Pago
|
|||||||
}
|
}
|
||||||
return $pago->uf;
|
return $pago->uf;
|
||||||
}
|
}
|
||||||
|
protected function getUFAsync(Model\Venta\Pago $pago): void
|
||||||
|
{
|
||||||
|
$queueData = [
|
||||||
|
'type' => 'service',
|
||||||
|
'service' => __CLASS__,
|
||||||
|
'method' => 'updateUF',
|
||||||
|
'params' => ['pago_id' => $pago->id]
|
||||||
|
];
|
||||||
|
$this->queueService->push($queueData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
50
app/src/Service/Worker/Service.php
Normal file
50
app/src/Service/Worker/Service.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Service\Worker;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Service\Worker;
|
||||||
|
|
||||||
|
class Service extends Ideal\Service implements Worker
|
||||||
|
{
|
||||||
|
public function __construct(protected ContainerInterface $container ,LoggerInterface $logger)
|
||||||
|
{
|
||||||
|
parent::__construct($logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(Model\Job $job): bool
|
||||||
|
{
|
||||||
|
$configuration = $job->configuration;
|
||||||
|
$serviceClass = $configuration['service'];
|
||||||
|
$method = $configuration['method'];
|
||||||
|
$params = $configuration['params'] ?? [];
|
||||||
|
try {
|
||||||
|
$service = $this->container->get($serviceClass);
|
||||||
|
} catch (NotFoundExceptionInterface | ContainerExceptionInterface $exception) {
|
||||||
|
$this->logger->error($exception->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$result = call_user_func_array([$service, $method], $params);
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
$this->logger->error($exception->getMessage(), [
|
||||||
|
'Worker' => __CLASS__,
|
||||||
|
'job_id' => $job->id,
|
||||||
|
'service' => $serviceClass,
|
||||||
|
'method' => $method,
|
||||||
|
'params' => $params,
|
||||||
|
'exception' => $exception
|
||||||
|
]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (is_bool($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -62,6 +62,7 @@ class TestBootstrap
|
|||||||
if (!Benchmark::execute([$this, 'isMigrated'])) {
|
if (!Benchmark::execute([$this, 'isMigrated'])) {
|
||||||
Benchmark::execute([$this, 'migrate']);
|
Benchmark::execute([$this, 'migrate']);
|
||||||
}
|
}
|
||||||
|
Benchmark::execute([$this, 'seedTables']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string $baseCommand = "bin/phinx";
|
protected string $baseCommand = "bin/phinx";
|
||||||
@ -71,16 +72,12 @@ class TestBootstrap
|
|||||||
$output = shell_exec($cmd);
|
$output = shell_exec($cmd);
|
||||||
$status = json_decode($output, true);
|
$status = json_decode($output, true);
|
||||||
|
|
||||||
return $status['missing_count'] === 0;
|
return $status['missing_count'] === 0 and $status['pending_count'] === 0;
|
||||||
}
|
}
|
||||||
public function migrate(): void
|
public function migrate(): void
|
||||||
{
|
{
|
||||||
$cmd = "{$this->baseCommand} migrate -e testing";
|
$cmd = "{$this->baseCommand} migrate -e testing";
|
||||||
$status = shell_exec($cmd);
|
shell_exec($cmd);
|
||||||
if ($status !== false and $status !== null) {
|
|
||||||
$cmd = "{$this->baseCommand} seed:run -e testing";
|
|
||||||
shell_exec($cmd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resetDatabase(): void
|
public function resetDatabase(): void
|
||||||
@ -125,6 +122,11 @@ class TestBootstrap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public function seedTables(): void
|
||||||
|
{
|
||||||
|
$cmd = "{$this->baseCommand} seed:run -e testing";
|
||||||
|
shell_exec($cmd);
|
||||||
|
}
|
||||||
|
|
||||||
protected PDO $connection;
|
protected PDO $connection;
|
||||||
protected function connect(): PDO
|
protected function connect(): PDO
|
||||||
@ -171,6 +173,6 @@ Benchmark::execute([$bootstrap, 'run'], ['resetDatabase' => $resetDatabase]);
|
|||||||
Benchmark::print();
|
Benchmark::print();
|
||||||
|
|
||||||
register_shutdown_function(function() use ($bootstrap) {
|
register_shutdown_function(function() use ($bootstrap) {
|
||||||
Benchmark::execute([$bootstrap, 'truncateTables']);
|
Benchmark::execute([$bootstrap, 'resetDatabase']);
|
||||||
Benchmark::print();
|
Benchmark::print();
|
||||||
});
|
});
|
||||||
|
86
app/tests/integration/QueueTest.php
Normal file
86
app/tests/integration/QueueTest.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Test\Integration;
|
||||||
|
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Faker;
|
||||||
|
use Incoviba\Common\Implement;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Service;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
|
||||||
|
class QueueTest extends TestCase
|
||||||
|
{
|
||||||
|
protected ContainerInterface $container;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
require_once implode(DIRECTORY_SEPARATOR, [dirname(__DIR__, 2), 'setup', 'container.php']);
|
||||||
|
$this->container = buildContainer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testServiceWorker(): void
|
||||||
|
{
|
||||||
|
$faker = Faker\Factory::create();
|
||||||
|
$pagoData = [
|
||||||
|
'fecha' => '2022-01-01',
|
||||||
|
'valor' => 10000,
|
||||||
|
];
|
||||||
|
$pagoService = $this->container->get(Service\Venta\Pago::class);
|
||||||
|
$pago = $pagoService->add($pagoData);
|
||||||
|
|
||||||
|
$this->assertEquals(0.0, $pago->uf);
|
||||||
|
|
||||||
|
$queueService = $this->container->get(Service\Queue::class);
|
||||||
|
$queueService->run();
|
||||||
|
|
||||||
|
$pago = $pagoService->getById($pago->id);
|
||||||
|
$this->assertNotEquals(0.0, $pago->uf);
|
||||||
|
|
||||||
|
$comunaRepository = $this->container->get(Repository\Comuna::class);
|
||||||
|
$comunas = $comunaRepository->fetchAll();
|
||||||
|
$id = $faker->numberBetween(0, count($comunas) - 1);
|
||||||
|
$comuna = $comunas[$id];
|
||||||
|
$direccionData = [
|
||||||
|
'calle' => $faker->streetName,
|
||||||
|
'numero' => $faker->buildingNumber,
|
||||||
|
'comuna' => $comuna->id
|
||||||
|
];
|
||||||
|
$propietarioData = [
|
||||||
|
'rut' => $faker->numberBetween(10000000, 99999999),
|
||||||
|
'nombre' => $faker->name,
|
||||||
|
'apellido_paterno' => $faker->lastName,
|
||||||
|
'apellido_materno' => $faker->lastName,
|
||||||
|
];
|
||||||
|
$propietarioRepository = $this->container->get(Repository\Venta\Propietario::class);
|
||||||
|
$propietario = $propietarioRepository->create($propietarioData);
|
||||||
|
$propietario = $propietarioRepository->save($propietario);
|
||||||
|
$propiedadRepository = $this->container->get(Repository\Venta\Propiedad::class);
|
||||||
|
$propiedad = $propiedadRepository->create();
|
||||||
|
$propiedad = $propiedadRepository->save($propiedad);
|
||||||
|
$ventaData = [
|
||||||
|
'fecha' => '2022-01-01',
|
||||||
|
'propietario' => $propietario->rut,
|
||||||
|
'propiedad' => $propiedad->id,
|
||||||
|
];
|
||||||
|
$ventaRepository = $this->container->get(Repository\Venta::class);
|
||||||
|
$venta = $ventaRepository->create($ventaData);
|
||||||
|
$venta = $ventaRepository->save($venta);
|
||||||
|
|
||||||
|
$cuotaData = [
|
||||||
|
'venta' => $venta->id,
|
||||||
|
'fecha' => '2022-01-01',
|
||||||
|
'valor' => 10000,
|
||||||
|
];
|
||||||
|
$cuotaService = $this->container->get(Service\Venta\Cuota::class);
|
||||||
|
$cuota = $cuotaService->add($cuotaData);
|
||||||
|
|
||||||
|
$this->assertEquals(0.0, $cuota->pago->uf);
|
||||||
|
|
||||||
|
$queueService = $this->container->get(Service\Queue::class);
|
||||||
|
$queueService->run();
|
||||||
|
|
||||||
|
$cuota = $cuotaService->getById($cuota->id);
|
||||||
|
$this->assertNotEquals(0.0, $cuota->pago->uf);
|
||||||
|
}
|
||||||
|
}
|
66
app/tests/unit/src/Service/UFTest.php
Normal file
66
app/tests/unit/src/Service/UFTest.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Test\Service;
|
||||||
|
|
||||||
|
use DateInterval;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Faker;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
|
use Incoviba\Service;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
|
||||||
|
class UFTest extends TestCase
|
||||||
|
{
|
||||||
|
protected array $dateMap;
|
||||||
|
protected array $ufMap;
|
||||||
|
protected Service\Redis $redisService;
|
||||||
|
protected Service\Money $moneyService;
|
||||||
|
protected Repository\UF $ufRepository;
|
||||||
|
protected LoggerInterface $logger;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$faker = Faker\Factory::create();
|
||||||
|
$today = new DateTimeImmutable($faker->dateTime->format('Y-m-1'));
|
||||||
|
|
||||||
|
$this->dateMap = [
|
||||||
|
$today->sub(new DateInterval("P1M")), // Case: Date past
|
||||||
|
$today, // Case: Date === "Today" (1st of month)
|
||||||
|
new DateTimeImmutable($today->format('Y-m-8')), // Case: Date 8th of month (before 9th)
|
||||||
|
new DateTimeImmutable($today->format('Y-m-15')), // Case: Date 15th of month (after 9th)
|
||||||
|
$today->add(new DateInterval("P1M")), // Case: Date one month from now
|
||||||
|
];
|
||||||
|
$this->ufMap = [
|
||||||
|
$faker->randomFloat(2, 10000, 20000), // 1st value
|
||||||
|
$faker->randomFloat(2, 25000, 38000), // 2nd value
|
||||||
|
$faker->randomFloat(2, 38000, 39000), // 3rd value (before 9th)
|
||||||
|
0.0, // no value (after 9th)
|
||||||
|
0.0 // no value
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->redisService = $this->getMockBuilder(Service\Redis::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$emptyRedis = $this->getMockBuilder(EmptyRedis::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$this->redisService->method('get')->willThrowException($emptyRedis);
|
||||||
|
$this->moneyService = $this->getMockBuilder(Service\Money::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$this->moneyService->method('getUF')->willReturnCallback(function($date) {
|
||||||
|
return $this->ufMap[array_search($date, $this->dateMap)];
|
||||||
|
});
|
||||||
|
$this->ufRepository = $this->getMockBuilder(Repository\UF::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$emptyResult = $this->getMockBuilder(EmptyResult::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$this->ufRepository->method('fetchByFecha')->willThrowException($emptyResult);
|
||||||
|
$this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGet()
|
||||||
|
{
|
||||||
|
$service = new Service\UF($this->redisService, $this->moneyService, $this->ufRepository, $this->logger);
|
||||||
|
|
||||||
|
foreach ($this->dateMap as $i => $date) {
|
||||||
|
$uf = $service->get($date);
|
||||||
|
|
||||||
|
$this->assertEquals($this->ufMap[$i], $uf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
73
app/tests/unit/src/Service/Venta/PagoTest.php
Normal file
73
app/tests/unit/src/Service/Venta/PagoTest.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
namespace Inventario\Service\Venta;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Service;
|
||||||
|
|
||||||
|
class PagoTest extends TestCase
|
||||||
|
{
|
||||||
|
protected float $uf;
|
||||||
|
protected Model\Venta\Pago $pago;
|
||||||
|
protected Repository\Venta\Pago $pagoRepository;
|
||||||
|
protected Repository\Venta\EstadoPago $estadoPagoRepository;
|
||||||
|
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository;
|
||||||
|
protected Service\UF $ufService;
|
||||||
|
protected Service\Valor $valorService;
|
||||||
|
protected Service\Queue $queueService;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$fecha = new DateTimeImmutable();
|
||||||
|
$this->uf = 37568.84;
|
||||||
|
|
||||||
|
$tipoEstadoPago = $this->getMockBuilder(Model\Venta\TipoEstadoPago::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$tipoEstadoPago->id = 1;
|
||||||
|
$tipoEstadoPago->descripcion = 'depositado';
|
||||||
|
$estadoPago = $this->getMockBuilder(Model\Venta\EstadoPago::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$estadoPago->id = 1;
|
||||||
|
$estadoPago->tipoEstadoPago = $tipoEstadoPago;
|
||||||
|
$estadoPago->fecha = $fecha;
|
||||||
|
|
||||||
|
$this->pago = $this->getMockBuilder(Model\Venta\Pago::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$this->pago->id = 1;
|
||||||
|
$this->pago->fecha = $fecha;
|
||||||
|
$this->pago->uf = $this->uf;
|
||||||
|
$this->pago->currentEstado = $estadoPago;
|
||||||
|
$this->pagoRepository = $this->getMockBuilder(Repository\Venta\Pago::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$this->pagoRepository->method('fetchById')->willReturn($this->pago);
|
||||||
|
$this->pagoRepository->method('edit')->willReturnCallback(function() {
|
||||||
|
$this->pago->uf = $this->uf;
|
||||||
|
return $this->pago;
|
||||||
|
});
|
||||||
|
$this->estadoPagoRepository = $this->getMockBuilder(Repository\Venta\EstadoPago::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$this->estadoPagoRepository->method('fetchCurrentByPago')->with($this->pago->id)->willReturn($estadoPago);
|
||||||
|
$this->tipoEstadoPagoRepository = $this->getMockBuilder(Repository\Venta\TipoEstadoPago::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$this->ufService = $this->getMockBuilder(Service\UF::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$this->ufService->method('get')->with($fecha)->willReturn($this->uf);
|
||||||
|
$this->valorService = $this->getMockBuilder(Service\Valor::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$this->queueService = $this->getMockBuilder(Service\Queue::class)->disableOriginalConstructor()->getMock();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateUF(): void
|
||||||
|
{
|
||||||
|
$this->pago->uf = null;
|
||||||
|
|
||||||
|
$pagoService = new Service\Venta\Pago(
|
||||||
|
$this->pagoRepository,
|
||||||
|
$this->estadoPagoRepository,
|
||||||
|
$this->tipoEstadoPagoRepository,
|
||||||
|
$this->ufService,
|
||||||
|
$this->valorService,
|
||||||
|
$this->queueService
|
||||||
|
);
|
||||||
|
|
||||||
|
$status = $pagoService->updateUF($this->pago->id);
|
||||||
|
$pago = $pagoService->getById($this->pago->id);
|
||||||
|
|
||||||
|
$this->assertTrue($status);
|
||||||
|
$this->assertEquals($pago->uf, $this->uf);
|
||||||
|
}
|
||||||
|
}
|
46
app/tests/unit/src/Service/Worker/ServiceTest.php
Normal file
46
app/tests/unit/src/Service/Worker/ServiceTest.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
namespace Tests\Unit\Service\Worker;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Incoviba\Service;
|
||||||
|
use Incoviba\Model;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
class ServiceTest extends TestCase
|
||||||
|
{
|
||||||
|
protected Model\Job $job;
|
||||||
|
protected ContainerInterface $container;
|
||||||
|
protected LoggerInterface $logger;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$pagoService = $this->getMockBuilder(Service\Venta\Pago::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$pagoService->method('updateUF')->willReturn(true);
|
||||||
|
$this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$this->container = $this->getMockBuilder(ContainerInterface::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$this->container->method('get')->willReturnMap([
|
||||||
|
[LoggerInterface::class, $this->logger],
|
||||||
|
[Service\Queue::class, $this->getMockBuilder(Service\Queue::class)->disableOriginalConstructor()->getMock()],
|
||||||
|
[Service\UF::class, $this->getMockBuilder(Service\UF::class)->disableOriginalConstructor()->getMock()],
|
||||||
|
[Service\Venta\Pago::class, $pagoService],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testExecute(): void
|
||||||
|
{
|
||||||
|
$configuration = [
|
||||||
|
'type' => 'service',
|
||||||
|
'service' => Service\Venta\Pago::class,
|
||||||
|
'method' => 'updateUF',
|
||||||
|
'params' => ['pago_id' => 1]
|
||||||
|
];
|
||||||
|
$job = $this->getMockBuilder(Model\Job::class)->disableOriginalConstructor()->getMock();
|
||||||
|
$job->configuration = $configuration;
|
||||||
|
|
||||||
|
$service = new Service\Worker\Service($this->container, $this->logger);
|
||||||
|
$result = $service->execute($job);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,10 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- testing
|
- testing
|
||||||
depends_on:
|
depends_on:
|
||||||
- test-db
|
test-db:
|
||||||
|
condition: service_healthy
|
||||||
|
test-redis:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
test-db:
|
test-db:
|
||||||
profiles:
|
profiles:
|
||||||
@ -23,7 +26,25 @@ services:
|
|||||||
container_name: incoviba_test_db
|
container_name: incoviba_test_db
|
||||||
env_file: ${APP_PATH:-.}/.test.db.env
|
env_file: ${APP_PATH:-.}/.test.db.env
|
||||||
volumes:
|
volumes:
|
||||||
- test-db:/var/lib/mysql
|
- test-db:/var/lib/mysql}
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD", "mariadb-admin", "ping", "-h", "localhost" ]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 10
|
||||||
|
networks:
|
||||||
|
- testing
|
||||||
|
|
||||||
|
test-redis:
|
||||||
|
profiles:
|
||||||
|
- testing
|
||||||
|
image: redis:latest
|
||||||
|
container_name: incoviba_test_redis
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
networks:
|
networks:
|
||||||
- testing
|
- testing
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user