name: CI

on:
    push:
        branches: [ master, '[1-9]+.x' ]
    pull_request:

jobs:
    tests:
        name: "Tests on PHP ${{ matrix.php }}${{ matrix.name_suffix }}"
        runs-on: ${{ matrix.os }}

        strategy:
            fail-fast: false
            matrix:
                php: [ '7.2', '7.3', '7.4', '8.0' ]
                extensions: [ '' ]
                os: [ubuntu-latest]
                include:
                    - php: '8.0'
                      os: ubuntu-latest
                      extensions: ':mbstring'
                      name_suffix: ' without mbstring'
                    - php: '8.0'
                      os: windows-latest
                      name_suffix: ' on Windows'
                    - php: '8.0'
                      os: macos-latest
                      name_suffix: ' on macOS'

        steps:
            -   if: ${{ runner.os == 'Windows' }}
                run: git config --global core.autocrlf false

            -   name: Checkout
                uses: actions/checkout@v2

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

            -   name: Install dependencies
                # PHPUnit requires ext-mbstring. But it is only necessary for features that we don't currently use:
                # - the testdox, JUnit and XML result printers
                # - the StringContains assertion when ignoring case
                # Ignoring the requirement is necessary for the job running the testsuite without mbstring
                run: composer update --ansi --no-progress --ignore-platform-req=ext-mbstring

            -   name: Run tests
                run: vendor/bin/phpunit --colors=always

    static_analysis:
        name: Static analysis
        runs-on: ubuntu-latest

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

            -   name: Setup PHP
                uses: shivammathur/setup-php@v2
                with:
                    coverage: "none"
                    php-version: "7.4"

            -   name: Install dependencies
                run: composer update --ansi --no-progress

            -   name: Install phpstan
                run: composer bin phpstan update --ansi --no-progress

            -   name: Run phpstan
                run: vendor/bin/phpstan analyse --ansi --no-progress
