1+ name : PHPUnit Tests
2+
3+ on :
4+ push :
5+ branches : [ master, main ]
6+ pull_request :
7+ branches : [ master, main ]
8+
9+ env :
10+ DB_NAME : facturascripts_test
11+ DB_USER : root
12+ DB_PASS : root
13+ DB_HOST : 127.0.0.1
14+
15+ jobs :
16+ test :
17+ runs-on : ubuntu-latest
18+
19+ strategy :
20+ matrix :
21+ php-version : ['8.0', '8.1', '8.2', '8.3', '8.4']
22+ database :
23+ - type : mysql
24+ version : ' 8.0'
25+ port : 3306
26+ - type : mariadb
27+ version : ' 11.0'
28+ port : 3306
29+ - type : postgresql
30+ version : ' 13'
31+ port : 5432
32+ fail-fast : false
33+
34+ name : PHP ${{ matrix.php-version }} - ${{ matrix.database.type }} ${{ matrix.database.version }}
35+
36+ services :
37+ mysql :
38+ image : ${{ matrix.database.type == 'mysql' && format('mysql:{0}', matrix.database.version) || '' }}
39+ env :
40+ MYSQL_ROOT_PASSWORD : root
41+ MYSQL_DATABASE : facturascripts_test
42+ ports :
43+ - 3306:3306
44+ options : >-
45+ --health-cmd="mysqladmin ping"
46+ --health-interval=10s
47+ --health-timeout=5s
48+ --health-retries=3
49+
50+ mariadb :
51+ image : ${{ matrix.database.type == 'mariadb' && format('mariadb:{0}', matrix.database.version) || '' }}
52+ env :
53+ MARIADB_ROOT_PASSWORD : root
54+ MARIADB_DATABASE : facturascripts_test
55+ MARIADB_ALLOW_EMPTY_ROOT_PASSWORD : false
56+ ports :
57+ - 3306:3306
58+ options : >-
59+ --health-cmd="healthcheck.sh --connect --innodb_initialized"
60+ --health-interval=10s
61+ --health-timeout=5s
62+ --health-retries=3
63+
64+ postgres :
65+ image : ${{ matrix.database.type == 'postgresql' && format('postgres:{0}', matrix.database.version) || '' }}
66+ env :
67+ POSTGRES_PASSWORD : root
68+ POSTGRES_DB : facturascripts_test
69+ POSTGRES_USER : root
70+ ports :
71+ - 5432:5432
72+ options : >-
73+ --health-cmd="pg_isready -U root -d facturascripts_test"
74+ --health-interval=10s
75+ --health-timeout=5s
76+ --health-retries=5
77+
78+ steps :
79+ - name : Checkout repository
80+ uses : actions/checkout@v4
81+
82+ - name : Setup PHP ${{ matrix.php-version }}
83+ uses : shivammathur/setup-php@v2
84+ with :
85+ php-version : ${{ matrix.php-version }}
86+ extensions : bcmath, curl, gd, iconv, mysqli, pdo_mysql, pdo_pgsql, pgsql, soap, zip, fileinfo, openssl, simplexml, mbstring, intl
87+ coverage : xdebug
88+ tools : composer:v2
89+ env :
90+ COMPOSER_TOKEN : ${{ secrets.GITHUB_TOKEN }}
91+
92+ - name : Get composer cache directory
93+ id : composer-cache
94+ run : echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
95+
96+ - name : Cache composer dependencies
97+ uses : actions/cache@v4
98+ with :
99+ path : ${{ steps.composer-cache.outputs.dir }}
100+ key : ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
101+ restore-keys : ${{ runner.os }}-composer-
102+
103+ - name : Install dependencies
104+ run : composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader
105+
106+ - name : Verify database connection
107+ run : |
108+ if [ "${{ matrix.database.type }}" = "mysql" ] || [ "${{ matrix.database.type }}" = "mariadb" ]; then
109+ echo "Testing ${{ matrix.database.type }} ${{ matrix.database.version }} connection..."
110+ mysql --host=${{ env.DB_HOST }} --user=${{ env.DB_USER }} --password=${{ env.DB_PASS }} -e "SHOW DATABASES;"
111+ mysql --host=${{ env.DB_HOST }} --user=${{ env.DB_USER }} --password=${{ env.DB_PASS }} -e "SELECT VERSION();"
112+ else
113+ echo "Testing PostgreSQL ${{ matrix.database.version }} connection..."
114+ PGPASSWORD=${{ env.DB_PASS }} psql -h ${{ env.DB_HOST }} -U ${{ env.DB_USER }} -d ${{ env.DB_NAME }} -c "\l"
115+ PGPASSWORD=${{ env.DB_PASS }} psql -h ${{ env.DB_HOST }} -U ${{ env.DB_USER }} -d ${{ env.DB_NAME }} -c "SELECT version();"
116+ fi
117+
118+ - name : Create application config
119+ run : |
120+ if [ "${{ matrix.database.type }}" = "mysql" ] || [ "${{ matrix.database.type }}" = "mariadb" ]; then
121+ cat > config.php << 'EOF'
122+ <?php
123+ define('FS_COOKIES_EXPIRE', 31536000);
124+ define('FS_ROUTE', '');
125+ define('FS_DB_TYPE', 'mysql');
126+ define('FS_DB_HOST', '${{ env.DB_HOST }}');
127+ define('FS_DB_PORT', 3306);
128+ define('FS_DB_NAME', '${{ env.DB_NAME }}');
129+ define('FS_DB_USER', '${{ env.DB_USER }}');
130+ define('FS_DB_PASS', '${{ env.DB_PASS }}');
131+ define('FS_DB_FOREIGN_KEYS', true);
132+ define('FS_DB_TYPE_CHECK', true);
133+ define('FS_MYSQL_CHARSET', 'utf8mb4');
134+ define('FS_MYSQL_COLLATE', 'utf8mb4_unicode_520_ci');
135+ define('FS_LANG', 'es_ES');
136+ define('FS_TIMEZONE', 'Europe/Madrid');
137+ define('FS_HIDDEN_PLUGINS', '');
138+ define('FS_DEBUG', true);
139+ define('FS_DISABLE_ADD_PLUGINS', false);
140+ define('FS_DISABLE_RM_PLUGINS', false);
141+ EOF
142+ else
143+ cat > config.php << 'EOF'
144+ <?php
145+ define('FS_COOKIES_EXPIRE', 31536000);
146+ define('FS_ROUTE', '');
147+ define('FS_DB_TYPE', 'postgresql');
148+ define('FS_DB_HOST', '${{ env.DB_HOST }}');
149+ define('FS_DB_PORT', 5432);
150+ define('FS_DB_NAME', '${{ env.DB_NAME }}');
151+ define('FS_DB_USER', '${{ env.DB_USER }}');
152+ define('FS_DB_PASS', '${{ env.DB_PASS }}');
153+ define('FS_DB_FOREIGN_KEYS', true);
154+ define('FS_DB_TYPE_CHECK', true);
155+ define('FS_LANG', 'es_ES');
156+ define('FS_TIMEZONE', 'Europe/Madrid');
157+ define('FS_HIDDEN_PLUGINS', '');
158+ define('FS_DEBUG', true);
159+ define('FS_DISABLE_ADD_PLUGINS', false);
160+ define('FS_DISABLE_RM_PLUGINS', false);
161+ EOF
162+ fi
163+
164+ - name : Run PHPUnit tests
165+ run : |
166+ if [ -f phpunit.xml ] || [ -f phpunit.xml.dist ]; then
167+ vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml
168+ else
169+ echo "No PHPUnit configuration found. Running with default settings..."
170+ vendor/bin/phpunit --bootstrap vendor/autoload.php tests/
171+ fi
172+
173+ - name : Upload coverage reports
174+ if : matrix.php-version == '8.3' && matrix.database.type == 'mysql' && matrix.database.version == '8.1'
175+ uses : codecov/codecov-action@v4
176+ with :
177+ file : ./coverage.xml
178+ flags : unittests
179+ name : codecov-umbrella
180+ fail_ci_if_error : false
181+
182+ security-audit :
183+ runs-on : ubuntu-latest
184+ name : Security Audit
185+
186+ steps :
187+ - name : Checkout repository
188+ uses : actions/checkout@v4
189+
190+ - name : Setup PHP
191+ uses : shivammathur/setup-php@v2
192+ with :
193+ php-version : ' 8.3'
194+ tools : composer:v2
195+
196+ - name : Install dependencies
197+ run : composer install --prefer-dist --no-dev --optimize-autoloader
198+
199+ - name : Run security audit
200+ run : composer audit
201+
202+ code-quality :
203+ runs-on : ubuntu-latest
204+ name : Code Quality
205+
206+ steps :
207+ - name : Checkout repository
208+ uses : actions/checkout@v4
209+
210+ - name : Setup PHP
211+ uses : shivammathur/setup-php@v2
212+ with :
213+ php-version : ' 8.3'
214+ tools : composer:v2, phpcs, phpstan
215+
216+ - name : Install dependencies
217+ run : composer install --prefer-dist --no-progress --optimize-autoloader
218+
219+ - name : Run PHP CodeSniffer
220+ run : |
221+ if [ -f phpcs.xml ] || [ -f phpcs.xml.dist ]; then
222+ phpcs
223+ else
224+ echo "No PHPCS configuration found, skipping..."
225+ fi
226+ continue-on-error : true
227+
228+ - name : Run PHPStan
229+ run : |
230+ if [ -f phpstan.neon ] || [ -f phpstan.neon.dist ]; then
231+ phpstan analyse
232+ else
233+ echo "No PHPStan configuration found, skipping..."
234+ fi
235+ continue-on-error : true
0 commit comments