name: Unit Tests

on:
  push:

jobs:
  unit-tests:
    name: PHP ${{matrix.php}}, ${{matrix.os}}, ${{matrix.stability}} deps
    runs-on: ${{matrix.os}}

    strategy:
      matrix:
        php: [7.0, 7.1, 7.2, 7.3, 7.4]
        os: [ubuntu-latest, windows-latest]
        stability: [lowest, stable]
        exclude:
          - stability: lowest
            php: 7.1
          - stability: lowest
            php: 7.2
          - stability: lowest
            php: 7.3
          - stability: lowest
            php: 7.4
          - os: windows-latest
            php: 7.1
          - os: windows-latest
            php: 7.2
          - os: windows-latest
            php: 7.3
          - os: windows-latest
            php: 7.4

    steps:
      - name: Checkout code
        uses: actions/checkout@v1

      - name: Setup PHP
        uses: shivammathur/setup-php@v1
        with:
          php-version: ${{matrix.php}}
          extensions: dom, mbstring, xml
          coverage: none

      - name: Get Composer Cache Directory
        id: composer-cache
        run: echo "::set-output name=dir::$(composer config cache-files-dir)"

      - name: Cache dependencies
        uses: actions/cache@v1
        with:
          path: ${{steps.composer-cache.outputs.dir}}
          key: ${{matrix.php}}-${{runner.os}}-composer-${{matrix.stability}}-${{hashFiles('**/composer.json')}}
          restore-keys: ${{matrix.php}}-${{runner.os}}-composer-${{matrix.stability}}-

      - name: Install dependencies
        run: composer update --prefer-${{matrix.stability}} --prefer-dist --no-interaction --no-suggest --no-progress

      - name: Execute tests
        run: vendor/bin/phpunit
