# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

on:
  push:
    branches:
      - main
  pull_request:
  schedule:
    - cron: '3 3 * * 1'

name: CI

jobs:
  php-lint:
    name: PHP Lint
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        php-version: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php-version }}
          coverage: none

      - name: PHP Lint
        run: find src tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l

  unit-tests:
    name: Unit tests

    runs-on: ubuntu-22.04

    needs: [ php-lint ]

    strategy:
      fail-fast: false
      matrix:
        php-version: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php-version }}
          ini-values: error_reporting=E_ALL
          tools: composer:v2
          coverage: none

      - name: Show the Composer configuration
        run: composer config --global --list

      - name: Cache dependencies installed with composer
        uses: actions/cache@v4
        with:
          path: ~/.cache/composer
          key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
          restore-keys: |
            php${{ matrix.php-version }}-composer-

      - name: Install Composer dependencies
        run: |
          composer update --with-dependencies --no-progress;
          composer show;

      - name: Run Tests
        run: ./vendor/bin/phpunit
