defaults: &defaults
  working_directory: ~/USDLRegex
  docker:
    - image: circleci/php:7

composer_cache_key: &composer_cache_key composer-dependencies-{{ checksum "composer.lock" }}
restore_composer_cache: &restore_composer_cache
  keys:
    - *composer_cache_key
composer_install: &composer_install
  name: install dependencies
  command: composer install
save_composer_cache: &save_composer_cache
  key: *composer_cache_key
  paths:
    - ~/.composer/cache/

version: 2
jobs:
  test_json:
    << : *defaults
    steps:
      - checkout
      - restore_cache: *restore_composer_cache
      - run: *composer_install
      - save_cache: *save_composer_cache
      - run:
          name: run tests
          command: |
            ./vendor/bin/behat -f pretty,junit --out /dev/stdout,behat --ansi
      - store_test_results:
          path: behat

  test_php:
    << : *defaults
    steps:
      - checkout
      - restore_cache: *restore_composer_cache
      - run: *composer_install
      - save_cache: *save_composer_cache
      - run:
          name: run tests
          command: |
            mkdir -p phpunit
            ./vendor/bin/phpunit --coverage-clover=coverage.xml --log-junit=phpunit/junit.xml
      - run:
          name: upload coverage
          command: bash <(curl -s https://codecov.io/bash)
      - store_test_results:
          path: phpunit

workflows:
  version: 2
  test:
    jobs:
      - test_php
      - test_json
