name: Test Suite
on:
  push:
    branches:
      - master
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        php: [ "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0" ]
    name: PHP ${{matrix.php }} Unit Test
    steps:
      - uses: actions/checkout@v2
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
      - name: Install Dependencies
        uses: nick-invision/retry@v1
        with:
          timeout_minutes: 10
          max_attempts: 3
          command: composer install
      - name: Run Script
        run: vendor/bin/phpunit

  # use dockerfiles for old versions of php (setup-php times out for those).
  test_php55:
    name: "PHP 5.5 Unit Test"
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Run Unit Tests
      uses: docker://php:5.5-cli
      with:
        entrypoint: ./.github/actions/entrypoint.sh

  test_php54:
    name: "PHP 5.4 Unit Test"
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Run Unit Tests
      uses: docker://php:5.4-cli
      with:
        entrypoint: ./.github/actions/entrypoint.sh

  test_php53:
    name: "PHP 5.3 Unit Test"
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Run Unit Tests
      uses: docker://tomsowerby/php-5.3:cli
      with:
        entrypoint: ./.github/actions/entrypoint.sh

  style:
    runs-on: ubuntu-latest
    name: PHP Style Check
    steps:
      - uses: actions/checkout@v2
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: "7.0"
      - name: Run Script
        run: |
          composer require friendsofphp/php-cs-fixer
          vendor/bin/php-cs-fixer fix --diff --dry-run .
          vendor/bin/php-cs-fixer fix --rules=native_function_invocation --allow-risky=yes --diff src
