image: tobiasb/php-cli:7.3-debian
clone:
  depth: full
options:
  size: 2x
pipelines:
  default:
    - step:
        name: Build and test
        caches:
          - composer
        script:
          - apt-get update
          - apt-get install -y screen
          - curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh -o install_nvm.sh
          - bash install_nvm.sh
          - source ~/.profile
          - nvm install 9.11.1
          - export PATH="$HOME/.composer/vendor/bin:$PATH"
          - cd ..
          - mkdir permissions_by_term/
          - mv build/* permissions_by_term/
          - mv permissions_by_term/ build/
          - cd build
          - composer create-project drupal/recommended-project:~9.0.0 drupal --no-interaction
          - (cd drupal && composer require behat/behat:^3.0 behat/mink-extension:^2.2 drupal/drupal-extension:^4.1 phpunit/phpunit:^7.0 mikey179/vfsstream:^1.6 drush/drush:^10.0 phpstan/phpstan:~0.12.75 phpstan/extension-installer:~1.1.0 mglaman/phpstan-drupal:~0.12.8 --dev)
          - mv permissions_by_term drupal/web/modules/
          - (cd drupal && cp web/modules/permissions_by_term/tests/phpstan* . && vendor/bin/phpstan analyse web/modules/permissions_by_term/)
          - (cd drupal/web/modules/permissions_by_term/tests/ && ../../../../vendor/bin/phpunit --testdox)
          - (cd drupal/web/modules/permissions_by_term/js/ && npm install && npm run bat)
          - (cd drupal/web && ../vendor/drush/drush/drush si standard --db-url=mysql://root:testing@127.0.01/testing -y && ../vendor/drush/drush/drush en permissions_by_term -y)
          - (cd drupal/web && screen -dmS php-server php -S localhost:80 .ht.router.php)
          - (cd drupal/web && ../vendor/drush/drush/drush pm:uninstall page_cache -y && ../vendor/drush/drush/drush en dynamic_page_cache -y)
          - (cd drupal/web && cp modules/permissions_by_term/tests/src/Behat/behat.yml.dist behat.yml && ../vendor/bin/behat --strict)
        services:
          - testing
          - mysql
definitions:
  services:
    testing:
      image: darksolar/selenium-chrome-headless
    mysql:
      image: mechtecs/docker_big_mysql
      environment:
        MYSQL_ROOT_PASSWORD: testing
        MYSQL_DATABASE: testing
