Skip to content

Commit 000e31a

Browse files
authored
Merge pull request #9 from abdedarghal111/extraTestsAndActions
Añadido actions, test y install.
2 parents 5c8d01e + 7203c77 commit 000e31a

File tree

4 files changed

+248
-0
lines changed

4 files changed

+248
-0
lines changed

.github/workflows/tests.yml

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
name: Tests del Plugin FacturaScripts
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
tests:
11+
name: Tests en ${{ matrix.database }} con PHP ${{ matrix.php-version }}
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
php-version: ['8.0', '8.1']
18+
database: ['mysql', 'postgresql']
19+
20+
env:
21+
NOMBRE_PLUGIN: "Modelo130"
22+
23+
services:
24+
mysql:
25+
image: mariadb:11
26+
ports:
27+
- 3306:3306
28+
env:
29+
MARIADB_ROOT_PASSWORD: toor
30+
MARIADB_DATABASE: facturascripts_tests
31+
options: >-
32+
--health-cmd="mariadb-admin ping"
33+
--health-interval=10s
34+
--health-timeout=5s
35+
--health-retries=3
36+
37+
postgres:
38+
image: postgres:13
39+
ports:
40+
- 5432:5432
41+
env:
42+
POSTGRES_PASSWORD: toor
43+
POSTGRES_DB: facturascripts_tests
44+
options: >-
45+
--health-cmd=pg_isready
46+
--health-interval=10s
47+
--health-timeout=5s
48+
--health-retries=5
49+
50+
steps:
51+
- name: Instalar PHP y extensiones
52+
uses: shivammathur/setup-php@v2
53+
with:
54+
php-version: ${{ matrix.php-version }}
55+
extensions: json, fileinfo, simplexml, zip, dom, pdo, pdo_mysql, mysql, mysqli, pgsql, pdo_pgsql, bcmath, gd, curl, soap
56+
tools: composer
57+
coverage: none
58+
59+
- name: Clonar FacturaScripts
60+
uses: actions/checkout@v4
61+
with:
62+
fetch-depth: 0
63+
repository: 'NeoRazorX/facturascripts'
64+
65+
- name: Clonar Plugin ${{ env.NOMBRE_PLUGIN }}
66+
uses: actions/checkout@v4
67+
with:
68+
fetch-depth: 0
69+
path: Plugins/${{ env.NOMBRE_PLUGIN }}
70+
71+
- name: Cache de dependencias de Composer
72+
uses: actions/cache@v3
73+
with:
74+
path: ~/.composer/cache/files
75+
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
76+
restore-keys: |
77+
composer-${{ runner.os }}-${{ matrix.php-version }}-
78+
composer-${{ runner.os }}-
79+
80+
- name: Instalar dependencias de FacturaScripts
81+
run: |
82+
mkdir -p MyFiles
83+
touch MyFiles/plugins.json
84+
composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader
85+
86+
- name: Crear archivo de configuración
87+
run: |
88+
cat > config.php << 'EOF'
89+
<?php
90+
91+
define('FS_COOKIES_EXPIRE', 604800);
92+
define('FS_LANG', 'es_ES');
93+
define('FS_TIMEZONE', 'Europe/Madrid');
94+
define('FS_ROUTE', '');
95+
96+
${{ matrix.database == 'mysql' && format('
97+
define(''FS_DB_TYPE'', ''mysql'');
98+
define(''FS_DB_HOST'', ''127.0.0.1'');
99+
define(''FS_DB_PORT'', ''3306'');
100+
define(''FS_DB_USER'', ''root'');
101+
') || format('
102+
define(''FS_DB_TYPE'', ''postgresql'');
103+
define(''FS_DB_HOST'', ''localhost'');
104+
define(''FS_DB_PORT'', ''5432'');
105+
define(''FS_DB_USER'', ''postgres'');
106+
') }}
107+
define('FS_DB_NAME', 'facturascripts_tests');
108+
define('FS_DB_PASS', 'toor');
109+
define('FS_DB_FOREIGN_KEYS', true);
110+
define('FS_DB_TYPE_CHECK', true);
111+
define('FS_MYSQL_CHARSET', 'utf8');
112+
define('FS_MYSQL_COLLATE', 'utf8_bin');
113+
114+
define('FS_HIDDEN_PLUGINS', '');
115+
define('FS_DEBUG', false);
116+
define('FS_DISABLE_ADD_PLUGINS', false);
117+
define('FS_DISABLE_RM_PLUGINS', false);
118+
define('FS_NF0', 2);
119+
EOF
120+
121+
- name: Copiar archivos de tests del Plugin
122+
run: |
123+
if [ -d "Plugins/${{ env.NOMBRE_PLUGIN }}/Test/main" ]; then
124+
cp -r Plugins/${{ env.NOMBRE_PLUGIN }}/Test/main Test/Plugins
125+
else
126+
echo "No se encontraron tests para el plugin"
127+
exit 1
128+
fi
129+
130+
- name: Instalar dependencias del Plugin ${{ env.NOMBRE_PLUGIN }}
131+
run: |
132+
if [ -f "Plugins/${{ env.NOMBRE_PLUGIN }}/composer.json" ]; then
133+
cd Plugins/${{ env.NOMBRE_PLUGIN }}
134+
composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader
135+
else
136+
echo "El plugin no tiene dependencias de Composer"
137+
fi
138+
139+
- name: Instalar el Plugin ${{ env.NOMBRE_PLUGIN }}
140+
run: php Test/install-plugins.php
141+
142+
- name: Ejecutar tests en ${{ matrix.database }}
143+
run: vendor/bin/phpunit -c phpunit-plugins.xml --verbose
144+
145+
- name: Mostrar logs en caso de fallo
146+
if: failure()
147+
run: |
148+
echo "=== Logs de la base de datos ==="
149+
if [ "${{ matrix.database }}" = "mysql" ]; then
150+
docker logs $(docker ps -q --filter ancestor=mariadb:11) || true
151+
else
152+
docker logs $(docker ps -q --filter ancestor=postgres:13) || true
153+
fi

Model/Subcuenta130.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use FacturaScripts\Core\Session;
2626
use FacturaScripts\Core\Tools;
2727
use FacturaScripts\Dinamic\Model\Subcuenta;
28+
use FacturaScripts\Dinamic\Model\User;
2829

2930
class Subcuenta130 extends ModelClass
3031
{
@@ -59,6 +60,14 @@ public function getSubcuenta(): Subcuenta
5960
return $subcuenta;
6061
}
6162

63+
public function install(): string
64+
{
65+
new User();
66+
new Subcuenta();
67+
68+
return parent::install();
69+
}
70+
6271
public static function primaryColumn(): string
6372
{
6473
return "id";
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
/**
3+
* This file is part of Modelo347 plugin for FacturaScripts
4+
* Copyright (C) 2024 Carlos Garcia Gomez <carlos@facturascripts.com>
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
namespace FacturaScripts\Test\Plugins\Model;
21+
22+
use FacturaScripts\Dinamic\Model\Cuenta;
23+
use FacturaScripts\Dinamic\Model\Ejercicio;
24+
use FacturaScripts\Dinamic\Model\Subcuenta;
25+
use FacturaScripts\Dinamic\Model\Subcuenta130;
26+
use FacturaScripts\Test\Traits\LogErrorsTrait;
27+
use PHPUnit\Framework\TestCase;
28+
29+
/**
30+
* @author Abderrahim Darghal Belkacemi <abdedarghal111@gmail.com>
31+
*/
32+
final class ModTest extends TestCase
33+
{
34+
use LogErrorsTrait;
35+
36+
public function testCreateSubcuenta130()
37+
{
38+
// crear un ejercicio
39+
$exercise = $this->getRandomExercise();
40+
41+
// crear una cuenta
42+
$account = new Cuenta();
43+
$account->codcuenta = '9999';
44+
$account->codejercicio = $exercise->codejercicio;
45+
$account->descripcion = 'Test';
46+
$this->assertTrue($account->save(), 'cant-save-account');
47+
48+
// crear una subcuenta
49+
$subaccount = new Subcuenta();
50+
$subaccount->codcuenta = $account->codcuenta;
51+
$subaccount->codejercicio = $exercise->codejercicio;
52+
$subaccount->codsubcuenta = $account->codcuenta . '.1';
53+
$subaccount->descripcion = 'Test';
54+
$this->assertTrue($subaccount->save(), 'cant-save-subaccount');
55+
$this->assertTrue($subaccount->exists(), 'subaccount-cant-persist');
56+
57+
58+
// crear subcuenta130
59+
$subcuenta130 = new Subcuenta130();
60+
$subcuenta130->codsubcuenta = $subaccount->codsubcuenta;
61+
$this->assertTrue($subcuenta130->save(), 'subcuenta130-cant-save');
62+
63+
// borrar subcuenta y subcuenta130
64+
$this->assertTrue($subcuenta130->delete(), 'subcuenta130-cant-delete');
65+
$this->assertTrue($subaccount->delete(), 'subaccount-cant-delete');
66+
$this->assertTrue($account->delete(), 'account-cant-delete');
67+
}
68+
69+
protected function getRandomExercise(): Ejercicio
70+
{
71+
$model = new Ejercicio();
72+
foreach ($model->all() as $ejercicio) {
73+
return $ejercicio;
74+
}
75+
76+
// no hemos encontrado ninguno, creamos uno
77+
$model->loadFromDate(date('d-m-Y'));
78+
return $model;
79+
}
80+
81+
protected function tearDown(): void
82+
{
83+
$this->logErrors();
84+
}
85+
}

Test/main/install-plugins.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Modelo130

0 commit comments

Comments
 (0)