name: test
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]
jobs:
  phpunit:
    name: PHP ${{ matrix.php-versions }}
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mariadb:10.3
        env:
          MYSQL_ROOT_PASSWORD: thelia
          MYSQL_DATABASE: thelia
        ports:
          - 3306/tcp
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
    strategy:
      fail-fast: false
      matrix:
        php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3']
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup Environment
        run: |
          sudo apt-get update
          sudo apt-get install sendmail
      - name: Setup PHP, with composer and extensions
        uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
        with:
          php-version: ${{ matrix.php-versions }}
          ini-values: post_max_size=20M
          extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, gd, zip
      - name: Start mysql service
        run: sudo /etc/init.d/mysql start
      - name: Get composer cache directory
        id: composercache
        run: echo "::set-output name=dir::$(composer config cache-files-dir)"
      - name: Cache composer dependencies
        uses: actions/cache@v2
        with:
          path: ${{ steps.composercache.outputs.dir }}
          # Use composer.json for key, if composer.lock is not committed.
          # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: ${{ runner.os }}-composer-
      - name: Install Composer dependencies
        run: |
          composer install --no-progress --prefer-dist --optimize-autoloader
          composer update --no-interaction --prefer-dist
      - name: Install Thelia
        run: |
          php Thelia thelia:install --db_host=127.0.0.1:${{ job.services.mysql.ports['3306'] }} --db_username=root --db_name=thelia --db_password=thelia
          php setup/faker.php -r 0
          php Thelia module:refresh
          php Thelia module:activate Colissimo
          php Thelia module:activate Cheque
          php Thelia module:activate HookTest
          php Thelia module:activate VirtualProductDelivery
          php Thelia admin:create --login_name thelia2 --password thelia2 --last_name thelia2 --first_name thelia2 --email thelia2@example.com
      - name: Run PHPUnit
        run: php bin/phpunit
