# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

name: "Continuous Integration"

on:
  pull_request:
  push:
    branches:
      - "*.*.x"

jobs:
  phpunit:
    name: "PHPUnit tests"

    runs-on: ${{ matrix.operating-system }}

    strategy:
      matrix:
        dependencies:
          - "lowest"
          - "highest"
          - "locked"
        php-version:
          - "8.0"
          - "8.1"
          - "8.2"
        operating-system:
          - "ubuntu-latest"

    steps:
      - name: "Checkout"
        uses: "actions/checkout@v3"

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          coverage: "pcov"
          php-version: "${{ matrix.php-version }}"
          ini-values: memory_limit=-1

      - name: "Install dependencies"
        uses: "ramsey/composer-install@v2"
        with:
          dependency-versions: "${{ matrix.dependencies }}"

      - name: "Tests"
        run: "vendor/bin/phpunit"

  static-analysis-psalm:
    name: "Static Analysis by Psalm"

    runs-on: ${{ matrix.operating-system }}

    strategy:
      matrix:
        dependencies:
          - "locked"
        php-version:
          - "8.1"
        operating-system:
          - "ubuntu-latest"

    steps:
      - name: "Checkout"
        uses: "actions/checkout@v3"

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          coverage: "none"
          php-version: "${{ matrix.php-version }}"
          ini-values: memory_limit=-1

      - name: "Install dependencies"
        uses: "ramsey/composer-install@v2"
        with:
          dependency-versions: "${{ matrix.dependencies }}"

      - name: "psalm"
        run: "vendor/bin/psalm  --output-format=github --shepherd --stats"

  mutation-tests:
    name: "Mutation tests"

    runs-on: ${{ matrix.operating-system }}

    strategy:
      matrix:
        dependencies:
          - "locked"
        php-version:
          - "8.1"
        operating-system:
          - "ubuntu-latest"

    steps:
      - name: "Checkout"
        uses: "actions/checkout@v3"

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          coverage: "xdebug"
          php-version: "${{ matrix.php-version }}"
          ini-values: memory_limit=-1, zend.assertions=1

      - name: "Install dependencies"
        uses: "ramsey/composer-install@v2"
        with:
          dependency-versions: "${{ matrix.dependencies }}"

      - name: "Infection"
        run: "vendor/bin/infection"

  coding-standards:
    name: "Check Coding Standards"

    runs-on: ${{ matrix.operating-system }}

    strategy:
      matrix:
        dependencies:
          - "locked"
        php-version:
          - "8.1"
        operating-system:
          - "ubuntu-latest"

    steps:
      - name: "Checkout"
        uses: "actions/checkout@v3"

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          coverage: "none"
          php-version: "${{ matrix.php-version }}"
          ini-values: memory_limit=-1

      - name: "Install dependencies"
        uses: "ramsey/composer-install@v2"
        with:
          dependency-versions: "${{ matrix.dependencies }}"

      - name: "Coding Standard"
        run: "vendor/bin/phpcs"
