I have this actions that allows me to run unit tests upon PR:
name: on-pr-unittest
on:
pull_request:
branches:
- dev
jobs:
run_unit_test:
runs-on: ubuntu-latest
services:
mariadb:
image: mariadb:latest
ports:
- 33306:3306
env:
MYSQL_USER: php_usr
MYSQL_PASSWORD: php_apsswd
MYSQL_DATABASE: test_php_app
MYSQL_ROOT_PASSWORD: password
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Remove Default Mysql and install nessesary tools to ping db connection
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo service mysql stop
sudo apt-get update && sudo apt-get purge -y mysql* && sudo apt-get install -y mariadb-client-10.6 netcat
# I do not want to modify the .env.testing therefore I spin my own host
- name: Add hosts to /etc/hosts
run: |
sudo echo "127.0.0.1 mariadb" | sudo tee -a /etc/hosts
- name: Test Connect Into DB
run: |
docker ps &&
nc -vz mariadb 33306 &&
mysql -h localhost -u php_usr -pphp_apsswd test_php_app -P 33306 -e "select DATABASE();"
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: bcmath, ctype, curl, dom, fileinfo, filter, hash, mbstring, openssl, pcre, pdo, pdo_mysql, tokenizer, libxml
- name: Install dependencies
uses: php-actions/composer@v6
- name: PHPUnit tests
run: |
sed -i "s/DB_PORT=.*/DB_PORT=33306/" .env.testing &&
./vendor/bin/phpunit
But upon ruuning the step php-actions/composer
I get this error:
Run php-actions/composer@v6
Run set -e
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.
Problem 1
- Root composer.json requires PHP extension ext-pdo_mysql * but it is missing from your system. Install or enable PHP's pdo_mysql extension.
To enable extensions, verify that they are enabled in your .ini files:
- /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-pdo_mysql` to temporarily ignore these required extensions.
Error: Your lock file does not contain a compatible set of packages. Please run composer update.
Problem 1
- Root composer.json requires PHP extension ext-pdo_mysql * but it is missing from your system. Install or enable PHP's pdo_mysql extension.
To enable extensions, verify that they are enabled in your .ini files:
- /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-pdo_mysql` to temporarily ignore these required extensions.
Despite installing the pdo_mysql
extetion on a previous step:
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: bcmath, ctype, curl, dom, fileinfo,sodium, filter, hash, mbstring, openssl, pcre, pdo, pdo_mysql, tokenizer, libxml
Why this happens and how I can fix it?
TLDR A way to fix the issue is to append the php_extensions
parameter:
- name: Install dependencies
uses: php-actions/composer@v6
with:
php_extensions: pdo_mysql
Resulting to this config:
name: on-pr-unittest
on:
push:
pull_request:
branches:
- dev
jobs:
run_unit_test:
runs-on: ubuntu-latest
services:
mariadb:
image: mariadb:latest
ports:
- 33306:3306
env:
MYSQL_USER: php_usr
MYSQL_PASSWORD: php_apsswd
MYSQL_DATABASE: test_php_app
MYSQL_ROOT_PASSWORD: password
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Remove Default Mysql and install nessesary tools to ping db connection
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo service mysql stop
sudo apt-get update && sudo apt-get purge -y mysql* && sudo apt-get install -y mariadb-client-10.6 netcat
# I do not want to modify the .env.testing therefore I spin my own host
- name: Add hosts to /etc/hosts
run: |
sudo echo "127.0.0.1 mariadb" | sudo tee -a /etc/hosts
- name: Test Connect Into DB
run: |
docker ps &&
nc -vz mariadb 33306 &&
mysql -h localhost -u php_usr -pphp_apsswd test_php_app -P 33306 -e "select DATABASE();"
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: bcmath, ctype, curl, dom, fileinfo, sodium, filter, hash, mbstring, openssl, pcre, pdo, pdo_mysql, tokenizer, libxml
- name: Install dependencies
uses: php-actions/composer@v6
with:
php_extensions: pdo_mysql
- name: PHPUnit tests
run: |
sed -i 's/<env name="DB_PORT" value="3306" \/>/<env name="DB_PORT" value="33306" \/>/' phpunit.xml &&
./vendor/bin/phpunit
The reason why this happens is because the php-actions/composer
runs its own php into a seperate container, thus needs to re-install any missing modules again.
An alternate approach is not to use iot at all and install it manually.