name: PHP Composer

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  tests:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        php-version:
          - "7.2"
          - "7.3"
          - "7.4"
          - "8.0"
          - "8.1"
    steps:
    - uses: actions/checkout@v2
    - name: Validate composer.json and composer.lock
      run: composer validate

    - name: Cache Composer packages
      id: composer-cache
      uses: actions/cache@v2
      with:
        path: vendor
        key: ${{ runner.os }}-node-${{ hashFiles('**/composer.lock') }}
        restore-keys: |
          ${{ runner.os }}-node-

    - name: Install dependencies
      if: steps.composer-cache.outputs.cache-hit != 'true'
      run: composer update --prefer-dist --no-progress --no-suggest

    - name: Run test suite
      run: vendor/bin/phpunit

  tests-lowest:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        php-version:
          - "7.2"
          - "7.3"
          - "7.4"
          - "8.0"
          - "8.1"
    steps:
      - uses: actions/checkout@v2

      - name: Validate composer.json and composer.lock
        run: composer validate

      - name: Cache Composer packages
        id: composer-cache
        uses: actions/cache@v2
        with:
          path: vendor
          key: ${{ runner.os }}-node-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - name: Install dependencies
        if: steps.composer-cache.outputs.cache-hit != 'true'
        run: composer update --prefer-dist --prefer-lowest --no-progress --no-suggest

      - name: Run test suite
        run: vendor/bin/phpunit
  tests-coverage:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        php-version:
          - "7.2"
    steps:
      - uses: actions/checkout@v2

      - name: Validate composer.json and composer.lock
        run: composer validate

      - name: Cache Composer packages
        id: composer-cache
        uses: actions/cache@v2
        with:
          path: vendor
          key: ${{ runner.os }}-node-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - name: Install dependencies
        if: steps.composer-cache.outputs.cache-hit != 'true'
        run: composer update --prefer-dist --no-progress --no-suggest

      - name: Run test suite
        run: vendor/bin/phpunit --coverage-clover clover
      - name: ocular
        run: wget https://scrutinizer-ci.com/ocular.phar
      - name: ocular
        run: php ocular.phar code-coverage:upload --format=php-clover clover

  cs:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        php-version:
          - "7.2"
    steps:
      - uses: actions/checkout@v2
      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          coverage: "none"
          php-version: "${{ matrix.php-version }}"
          tools: "cs2pr"

      - name: Validate composer
        run: composer validate

      - name: Cache Composer packages
        id: composer-cache
        uses: actions/cache@v2
        with:
          path: vendor
          key: ${{ runner.os }}-node-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - name: Install dependencies
        if: steps.composer-cache.outputs.cache-hit != 'true'
        run: composer update --prefer-dist --no-progress --no-suggest

      - name: Run CS
        run: vendor/bin/phpcs --report=checkstyle -q | cs2pr
