# GitHub Action for Symfony with MySQL name: Testing Symfony with MySQL on: [push, pull_request] jobs: symfony: name: Symfony (PHP ${{ matrix.php-versions }}) runs-on: ubuntu-latest env: APP_ENV: test # Docs: https://docs.github.com/en/actions/using-containerized-services services: mysql: image: mysql:8.4 env: MYSQL_ALLOW_EMPTY_PASSWORD: false MYSQL_ROOT_PASSWORD: symfony MYSQL_DATABASE: symfony ports: - 3306/tcp options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 strategy: fail-fast: false matrix: php-versions: ['8.4', '8.5', '8.6'] steps: - name: Checkout uses: actions/checkout@v6 # Docs: https://github.com/shivammathur/setup-php - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql coverage: xdebug # Local MySQL service in GitHub hosted environments is disabled by default. # If you are using it instead of service containers, make sure you start it. # - name: Start mysql service # run: sudo systemctl start mysql.service - name: Get composer cache directory id: composer-cache run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache composer dependencies uses: actions/cache@v5 with: path: ${{ steps.composer-cache.outputs.dir }} # Use composer.json for key, if composer.lock is not committed. # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies run: composer install --no-interaction --no-progress --prefer-dist --optimize-autoloader - name: Prepare database run: | php bin/console doctrine:database:create --if-not-exists --no-interaction php bin/console doctrine:schema:create --no-interaction php bin/console doctrine:fixtures:load --no-interaction env: DATABASE_URL: mysql://root:symfony@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony?serverVersion=8.4&charset=utf8mb4 - name: Run tests run: php bin/phpunit --coverage-text env: DATABASE_URL: mysql://root:symfony@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony?serverVersion=8.4&charset=utf8mb4