version: 2
jobs:
  build:
    working_directory: /srv
    docker:
      - image: lastcallmedia/php:7.0-dev
    steps:
      - checkout
      - restore_cache:
          key: composer-v1-{{ checksum "composer.json" }}
      - run: composer install
      - save_cache:
          key: composer-v1-{{ checksum "composer.json" }}
          paths: [vendor, composer.lock]
      - run: |
          COMMIT_RANGE=`echo $CIRCLE_COMPARE_URL | cut -d/ -f7`
          IFS=$'\n'; COMMIT_SCA_FILES=($(git diff --name-only --diff-filter=ACMRTUXB "${COMMIT_RANGE}")); unset IFS
          vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no --path-mode=intersection -- "${COMMIT_SCA_FILES[@]}"
      - run: |
          composer validate
      - run: mkdir -p /phpunit
      - run: vendor/bin/phpunit --log-junit=/phpunit/junit.xml
      - store_test_results:
          path: /phpunit