name: PHP CI
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  ci:
    name: PHP CI - test
    runs-on: ubuntu-latest

    strategy:
      matrix:
        php: [7.4, 8.0, 8.1, 8.2, 8.3]

    steps:
      - name: Checkout
        uses: actions/checkout@v3
    
      - name: Setup PHP
        uses: shivammathur/setup-php@8e2ac35f639d3e794c1da1f28999385ab6fdf0fc
        with:
          php-version: ${{ matrix.php }}
          coverage: xdebug
    
      - name: Composer install
        run: composer install
    
      - name: PHP Linting
        run: ./vendor/bin/phpcs --standard=.duo_linting.xml -n src/* tests

      - name: PHP tests
        run: ./vendor/bin/phpunit --process-isolation tests

      - name: Composer install example
        working-directory: example
        run: composer install

      - name: Inject dummy example config
        working-directory: example
        run: printf "[duo]\nclient_id=DIAAAAAAAAAAAAAAAAAA\nclient_secret=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\napi_hostname=example.duosecurity.com\nredirect_uri=http://localhost:8080\nfailmode=closed\n" > ./duo.conf

      - name: Ensure example runs
        working-directory: example
        run: php index.php
