build: false
clone_folder: c:\projects\grumphp
clone_depth: 1
shallow_clone: false
platform:
  - x64

matrix:
  allow_failures:
    - php_version: 8.0

environment:
  matrix:
    - dependencies: highest
      php_version: 7.3
    - dependencies: highest
      php_version: 7.4.3  # OpenSSL issue will be resolved in 7.4.6
    - dependencies: highest
      php_version: 8.0

  project_directory: c:\projects\grumphp
  composer_directory: c:\tools\composer
  composer_executable: c:\tools\composer\composer.phar
  composer_installer: c:\tools\composer\installer.php
  php_root_directory: c:\tools\php

cache:
  - c:\ProgramData\chocolatey\bin -> appveyor.yml
  - c:\ProgramData\chocolatey\lib -> appveyor.yml
  - c:\tools\composer -> appveyor.yml
  - '%LOCALAPPDATA%\Composer -> appveyor.yml'
  - c:\tools\php -> appveyor.yml

init:
  - ps: $Env:php_directory = $Env:php_root_directory + '\' + $Env:php_version
  # TODO: This is a workaround for https://github.com/chocolatey/choco/issues/1843. Once this is fixed we
  #       should go back to latest version in appveyor saving ourselves test time
  - ps: choco install chocolatey -y --version 0.10.13 --allow-downgrade
  - ps: $Env:exact_php_version = (((choco search php --exact --all --limit-output | Select-String -pattern $Env:php_version) -replace '[php|]', '') | %{ New-Object System.Version $_ } | Sort-Object | Select-Object -Last 1).ToString()
  - ps: $Env:PATH = $Env:php_directory + ';' + $Env:composer_directory + ';' + $Env:PATH
  - ps: $Env:COMPOSER_NO_INTERACTION = 1
  - ps: $Env:ANSICON = '121x90 (121x90)'

install:
  # Install PHP
  - ps: If ((Test-Path $Env:php_directory) -eq $False) { New-Item -Path $Env:php_directory -ItemType 'directory' }
  - ps: $php_install_parameters = '"/DontAddToPath /InstallDir:' + $Env:php_directory + '"'
  - ps: Set-Service wuauserv -StartupType Manual
  - ps: appveyor-retry choco upgrade php --yes --version=$Env:exact_php_version --params=$php_install_parameters

  # Prepare PHP
  - ps: cd $Env:php_directory
  - ps: Copy-Item php.ini-production -Destination php.ini
  - ps: Add-Content -Path php.ini -Value 'memory_limit=1G'
  - ps: Add-Content -Path php.ini -Value 'date.timezone="UTC"'
  - ps: Add-Content -Path php.ini -Value 'extension_dir=ext'
  - ps: Add-Content -Path php.ini -Value 'extension=php_curl.dll'
  - ps: Add-Content -Path php.ini -Value 'extension=php_mbstring.dll'
  - ps: Add-Content -Path php.ini -Value 'extension=php_openssl.dll'
  - ps: php --version

  # Prepare composer
  - ps: If ((Test-Path $Env:composer_directory) -eq $False) { New-Item -Path $Env:composer_directory -ItemType 'directory' }
  - ps: If ((Test-Path $Env:composer_installer) -eq $False) { appveyor-retry appveyor DownloadFile https://getcomposer.org/installer -FileName $Env:composer_installer }
  - ps: If ((Test-Path $Env:composer_executable) -eq $False) { php $Env:composer_installer --install-dir=$Env:composer_directory }
  - ps: Set-Content -Path ($Env:composer_directory + '\composer.bat') -Value ('@php ' + $Env:composer_executable + ' %*')
  - ps: Copy-Item "$Env:composer_executable" "$Env:composer_directory\composer"

  # Install dependencies
  - ps: cd $Env:project_directory
  - IF %dependencies%==lowest composer update --prefer-dist --prefer-lowest --prefer-stable --no-progress --no-scripts --no-suggest --profile
  - IF %dependencies%==highest composer update --prefer-dist --no-progress --no-scripts --no-suggest --profile
  - git config --global user.email "doesntmatter@dispostable.com"
  - git config --global user.name "GrumPHP"

test_script:
  - ps: cd $Env:project_directory
  - php ./bin/grumphp run --testsuite=windows --no-interaction
