name: PHP Tests

on:
  push:
    branches: [ develop ]
  pull_request:
    branches: [ develop ]

jobs:

  phpstan-tests:

    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        php: [ 8.1, 8.0, 7.4, 7.3, 7.2]
        os: [ubuntu-latest]

    steps:
      - uses: actions/checkout@v2

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: opcache, mbstring
          tools: composer:v2
          coverage: none
        env:
          COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - 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@v2
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: ${{ runner.os }}-composer-

      - name: Install dependencies
        run: composer install --prefer-dist --no-progress

      - name: Run phpstan tests
        run: composer phpstan
