name: Tests (PHP)

on: [pull_request]

jobs:
  tests:
    name: Run tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1

      - name: Setup PHP, with composer and extensions
        uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
        with:
          php-version: '7.4'
          extensions: mbstring, dom, fileinfo, mysql, libxml, xml, xmlwriter, dom, tokenizer, filter, json, phar, pcre, openssl, pdo, intl, curl

      - name: Cache composer dependencies
        uses: actions/cache@v1
        with:
          path: vendor
          key: composer-${{ hashFiles('composer.lock') }}

      - name: Run composer install
        run: composer install -n --prefer-dist
        env:
          APP_ENV: testing

      - name: Prepare Laravel Application
        run: |
          cp .env.example .env
          php artisan key:generate

      - name: Cache yarn dependencies
        uses: actions/cache@v1
        with:
          path: node_modules
          key: yarn-${{ hashFiles('yarn.lock') }}

      - name: Run yarn
        run: yarn && yarn dev

      - name: Run ESLint
        run: yarn lint

      - name: Run tests
        run: php artisan test
        env:
          APP_ENV: testing

      - name: Php code sniffer
        run: ./vendor/bin/phpcs

      - name: Upload artifacts
        uses: actions/upload-artifact@master
        if: failure()
        with:
          name: Logs
          path: ./storage/logs