version: 2
jobs:
  build:
    docker:
      - image: circleci/php:latest
    working_directory: ~/build
    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "composer.json" }}
          - v1-dependencies-
      - run:
          name: Install Composer
          command: |
            php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
            php -r "if (hash_file('SHA384', 'composer-setup.php') === trim(file_get_contents('https://composer.github.io/installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer invalid'; unlink('composer-setup.php'); } echo PHP_EOL;"
            php composer-setup.php
            php -r "unlink('composer-setup.php');"
      - run:
          name: Install dependencies
          command: php composer.phar install -n --prefer-dist
      - save_cache:
          paths:
            - ./vendor
          key: v1-dependencies-{{ checksum "composer.json" }}
      - run:
          name: Install Xdebug
          command: sudo docker-php-ext-enable xdebug
      - run:
          name: Run tests
          command: vendor/bin/phpunit
      - run:
          name: Upload Code Coverage Report
          command: bash <(curl -s https://codecov.io/bash)
