Skip to content

Commit 4233840

Browse files
author
Carlos Garcia
committed
Añadida github action para ejecutar los tests unitarios.
1 parent 0382107 commit 4233840

1 file changed

Lines changed: 155 additions & 0 deletions

File tree

.github/workflows/tests.yml

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

0 commit comments

Comments
 (0)