# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/php:7.1.5-browsers
      
      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/mysql:9.4

    working_directory: ~/repo

    install_composer: &install_composer
        command: |
            cd /tmp
            EXPECTED_SIGNATURE=$(curl -q https://composer.github.io/installer.sig)
            php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
            ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
            if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
            then
                >&2 echo 'ERROR: Invalid installer signature'
                rm composer-setup.php
                exit 1
            fi

            sudo php composer-setup.php --quiet --install-dir /usr/local/bin --filename composer
            RESULT=$?
            rm composer-setup.php
            exit $RESULT

    steps:
      - checkout

      - run:
          <<: *install_composer

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "composer.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: composer install -n --prefer-dist

      - save_cache:
          paths:
            - ./vendor
          key: v1-dependencies-{{ checksum "composer.json" }}
        
      # run tests!
      - run: phpunit
version: 2
jobs:
  build:
    working_directory: /var/www/html
    docker:
      - image: php:7.1-nginx
        environment:
          APP_ENV: test
    steps:
      - run:
          name: Install system packages
          command: apt-get update && apt-get -y install git
      - run:
          name: Install PHP extensions
          command: docker-php-ext-install pdo
      - checkout
      - 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: Display PHP information
          command: |
            php -v
            php composer.phar --version
      - run:
          name: Install project dependencies
          command: php composer.phar install
      - run:
          name: Run CS tests
          command: vendor/bin/phpcs
      - run:
          name: Run Unit tests
          command: vendor/bin/phpunit
Test default docker CircleCI image
Test default docker CircleCI image
