name: KnpTimeBundle Tests

on:
    push:
        branches:
            - master
    pull_request:
    release:

jobs:
    composer-validate:
        name: Validate composer.json
        runs-on: ubuntu-latest

        steps:
            -   name: Set PHP Version
                run: sudo update-alternatives --set php /usr/bin/php7.4

            -   name: Checkout
                uses: actions/checkout@v2

            -   name: Validate
                run: composer validate --strict

    stable-tests:
        name: Stable
        runs-on: ubuntu-18.04

        strategy:
            fail-fast: false
            matrix:
                php-versions: [ '7.2', '7.3', '7.4', '8.0', '8.1' ]

        steps:
            -   name: Set PHP Version
                run: sudo update-alternatives --set php /usr/bin/php${{ matrix.php-versions }}

            -   name: Get PHP Version
                run: |
                    ver=$(php -v | grep -oP '(?<=PHP )\d.\d')
                    echo "::set-output name=version::$ver"
                id: php-ver

            -   name: Using PHP Version from matrix
                run: |
                    echo "Runner is not using PHP Version defined in the php-versions matrix."
                    php -v
                    exit 1
                if: steps.php-ver.outputs.version != matrix.php-versions

            -   name: Checkout
                uses: actions/checkout@v2

            -   name: Require symfony/flex
                run: composer global require --no-progress --no-scripts --no-plugins symfony/flex >=1.x

            -   name: Install Composer Dependencies
                run: composer update --prefer-dist --no-progress

            -   name: PHPUnit
                run: vendor/bin/simple-phpunit

    lowest-tests:
        name: Lowest Dependencies
        runs-on: ubuntu-18.04

        env:
            SYMFONY_PHPUNIT_VERSION: 9.5

        strategy:
            fail-fast: false
            matrix:
                php-versions: [ '7.4', '8.1' ]

        steps:
            -   name: Set PHP Version
                run: sudo update-alternatives --set php /usr/bin/php${{ matrix.php-versions }}

            -   name: Get PHP Version
                run: |
                    ver=$(php -v | grep -oP '(?<=PHP )\d.\d')
                    echo "::set-output name=version::$ver"
                id: php-ver

            -   name: Using PHP Version from matrix
                run: |
                    echo "Runner is not using PHP Version defined in the php-versions matrix."
                    php -v
                    exit 1
                if: steps.php-ver.outputs.version != matrix.php-versions

            -   name: Checkout
                uses: actions/checkout@v2

            -   name: Require symfony/flex
                run: composer global require --no-progress --no-scripts --no-plugins symfony/flex >=1.x

            -   name: Install Composer Dependencies
                run: composer update --prefer-lowest --prefer-dist --no-progress

            -   name: PHPUnit
                run: vendor/bin/simple-phpunit
