name: Build

on: [ pull_request ]

jobs:
    tests:
        runs-on: ubuntu-latest
        name: Test
        env:
            SYMFONY_REQUIRE: "${{ matrix.symfony_require }}"
        services:
            mysql:
                image: mysql:5.7
                env:
                    MYSQL_ALLOW_EMPTY_PASSWORD: true
                ports:
                    - 3306:3306
                options: --health-cmd "mysqladmin ping --silent"
        strategy:
            fail-fast: false
            matrix:
                include:
                    -   php: 7.3
                        test_make_target: test_phpunit_legacy
                    -   php: 7.4
                        composer_flags: --prefer-lowest
                        test_make_target: test_phpunit_legacy
                    -   php: 7.4
                        symfony_require: 5.4.*
                        test_make_target: test_phpunit_legacy
                    -   php: 8.0
                        test_make_target: test_phpunit_legacy
                    -   php: 8.1
                        symfony_require: 6.0.*
                        test_make_target: test
                    -   php: 8.1
                        symfony_require: 6.1.*
                        test_make_target: test
                    -   php: 8.2
                        symfony_require: 6.2.*
                        test_make_target: test

        steps:
            -   uses: actions/checkout@v2

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

            -   name: Configure Composer minimum stability
                if: matrix.stability
                run: composer config minimum-stability ${{ matrix.stability }}

            -   name: Install symfony/flex
                run: composer global config allow-plugins.symfony/flex true && composer global require symfony/flex

            -   name: Install dependencies
                run: composer update ${{ matrix.composer_flags }} --prefer-dist

            -   name: Phpunit
                run: make ${{ matrix.test_make_target }}

            -   name: Behat
                run: make behat

    php-stan:
        runs-on: ubuntu-latest
        name: php-stan

        steps:
            -   uses: actions/checkout@v2

            -   name: Setup PHP
                uses: shivammathur/setup-php@v2
                with:
                    php-version: "8.1"

            -   name: Install dependencies
                run: composer update --prefer-dist

            -   name: PHPStan
                run: make phpstan

    cs-fixer:
        runs-on: ubuntu-latest
        name: CS-Fixer

        steps:
            -   uses: actions/checkout@v2

            -   name: Setup PHP
                uses: shivammathur/setup-php@v2
                with:
                    php-version: "8.1"

            -   name: Install dependencies
                run: composer update --prefer-dist

            -   name: PHP CS Fixer
                run: make php_cs_fixer_check
