image: registry.gitlab.tugraz.at/dbp/dbp-api/api-core-bundle/main:v1

before_script:
  - 'git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.tugraz.at/".insteadOf "git@gitlab.tugraz.at:"'

variables:
  COMPOSER_CACHE_DIR: "$CI_PROJECT_DIR/_composer_cache"

cache:
  key: ${CI_PROJECT_PATH}
  paths:
    - _composer_cache

stages:
  - test

.test_defaults: &test_defaults
  script:
    - sudo update-alternatives --set php "/usr/bin/${PHP}"
    - composer install
    - composer test

test-php7.3:
  stage: test
  variables:
    PHP: "php7.3"
  <<: *test_defaults

test-php7.4:
  stage: test
  variables:
    PHP: "php7.4"
  <<: *test_defaults

test-php8.0:
  stage: test
  variables:
    PHP: "php8.0"
  <<: *test_defaults

psalm:
  stage: test
  allow_failure: true
  script:
    - sudo update-alternatives --set php /usr/bin/php7.4
    - composer install
    - composer run psalm

phpstan:
  stage: test
  allow_failure: true
  script:
    - sudo update-alternatives --set php /usr/bin/php7.4
    - composer install
    - composer run phpstan

cs-fixer:
  stage: test
  allow_failure: true
  script:
    - sudo update-alternatives --set php /usr/bin/php7.4
    - composer install
    - composer run cs
