name: Tests

on:
  push:
  pull_request:

jobs:
  tests_linux:
    name: PHP ${{ matrix.php }} Linux
    runs-on: ubuntu-20.04

    strategy:
      matrix:
        php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']

    steps:
      - name: Checkout Code
        uses: actions/checkout@v2

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

      - name: Setup Problem Matchers
        run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

      - name: Install PHP 5/7 Dependencies
        uses: nick-invision/retry@v1
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer update --no-interaction --no-progress
        if: "matrix.php < 8"

      - name: Install PHP 8 Dependencies
        uses: nick-invision/retry@v1
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer update --no-interaction --no-progress --ignore-platform-req=php
        if: "matrix.php >= 8"

      - name: Execute PHPUnit
        run: vendor/bin/phpunit
 
  tests_windows:
    name: PHP ${{ matrix.php }} Windows
    runs-on: windows-2019

    strategy:
      matrix:
        php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']

    steps:
      - name: Configure Git
        run: |
          git config --global core.autocrlf false
          git config --global core.eol lf

      - name: Checkout Code
        uses: actions/checkout@v2

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

      - name: Setup Problem Matchers
        run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

      - name: Install PHP 5/7 Dependencies
        uses: nick-invision/retry@v1
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer update --no-interaction --no-progress
        if: "matrix.php < 8"

      - name: Install PHP 8 Dependencies
        uses: nick-invision/retry@v1
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer update --no-interaction --no-progress --ignore-platform-req=php
        if: "matrix.php >= 8"

      - name: Execute PHPUnit
        run: vendor\bin\phpunit.bat

  test_hhvm:
    name: HHVM ${{ matrix.hhvm }}
    runs-on: ubuntu-16.04

    strategy:
      matrix:
        hhvm: ["3.15", "3.18", "3.21", "3.24"]

    steps:
      - name: Checkout Code
        uses: actions/checkout@v2

      - name: Install HHVM
        shell: bash
        run: sudo .github/bin/hhvm.sh ${{ matrix.hhvm }}

      - name: Install Composer
        shell: bash
        run: sudo .github/bin/composer.sh

      - name: Install Dependencies
        uses: nick-invision/retry@v1
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer update --no-interaction --no-progress

      - name: Execute PHPUnit
        run: hhvm vendor/bin/phpunit
