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
0 commit comments