workflows:
  version: 2
  main:
    jobs:
      - php74-build
      - php80-build
      - php81-build
      - php82-build
      - php83-build
      - php84-build

version: 2

job-references:
  mysql_image: &mysql_image
    cimg/mysql:5.7

  setup_environment: &setup_environment
    name: "Setup Environment Variables"
    command: |
      echo "export PATH=$HOME/.composer/vendor/bin:$PATH" >> $BASH_ENV
      source /home/circleci/.bashrc

  install_dependencies: &install_dependencies
    name: "Install Dependencies"
    command: |
      sudo apt-get update && sudo apt-get install subversion mariadb-client
      sudo -E install-php-extensions mysqli gd bcmath
      sudo -E composer selfupdate

  php_job: &php_job
    environment:
      - WP_TESTS_DIR: "/tmp/wordpress-tests-lib"
      - WP_CORE_DIR: "/tmp/wordpress/"
    steps:
      - checkout
      - run: *setup_environment
      - run: *install_dependencies
      - run:
          name: "Run Tests"
          command: |
            composer install
            rm -rf $WP_TESTS_DIR $WP_CORE_DIR
            bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest
            vendor/bin/phpunit

jobs:
  php74-build:
    <<: *php_job
    docker:
      - image: cimg/php:7.4
      - image: *mysql_image
  php80-build:
    <<: *php_job
    docker:
      - image: cimg/php:8.0
      - image: *mysql_image
  php81-build:
    <<: *php_job
    docker:
      - image: cimg/php:8.1
      - image: *mysql_image
  php82-build:
    <<: *php_job
    docker:
      - image: cimg/php:8.2
      - image: *mysql_image
  php83-build:
    <<: *php_job
    docker:
      - image: cimg/php:8.3
      - image: *mysql_image
  php84-build:
    <<: *php_job
    docker:
      - image: cimg/php:8.4
      - image: *mysql_image
