name: queues

on:
  push:
    branches:
      - master
      - '*.x'
  pull_request:

jobs:
  sync:
    runs-on: ubuntu-24.04

    strategy:
      fail-fast: true

    name: Sync Driver

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.2
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
          tools: composer:v2
          coverage: none

      - name: Set Framework version
        run: composer config version "12.x-dev"

      - name: Install dependencies
        uses: nick-fields/retry@v3
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

      - name: Execute tests
        run: vendor/bin/phpunit tests/Integration/Queue
        env:
          QUEUE_CONNECTION: sync

  database:
    runs-on: ubuntu-24.04

    strategy:
      fail-fast: true

    name: Database Driver

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.2
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
          tools: composer:v2
          coverage: none

      - name: Set Framework version
        run: composer config version "12.x-dev"

      - name: Install dependencies
        uses: nick-fields/retry@v3
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

      - name: Setup SQLite Database
        run: php vendor/bin/testbench package:create-sqlite-db

      - name: Execute tests
        run: vendor/bin/phpunit tests/Integration/Queue
        env:
          DB_CONNECTION: sqlite
          QUEUE_CONNECTION: database

  redis:
    runs-on: ubuntu-24.04

    services:
      redis:
        image: redis:7.0
        ports:
          - 6379:6379
        options: --entrypoint redis-server

    strategy:
      fail-fast: true
      matrix:
        client: ['phpredis', 'predis']

    name: Redis (${{ matrix.client}}) Driver

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.2
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
          tools: composer:v2
          coverage: none

      - name: Set Framework version
        run: composer config version "12.x-dev"

      - name: Install dependencies
        uses: nick-fields/retry@v3
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

      - name: Execute tests
        run: vendor/bin/phpunit tests/Integration/Queue
        env:
          REDIS_CLIENT: ${{ matrix.client }}
          QUEUE_CONNECTION: redis

  redis-cluster:
    runs-on: ubuntu-24.04

    strategy:
      fail-fast: true
      matrix:
        client: ['phpredis', 'predis']

    name: Redis Cluster (${{ matrix.client}}) Driver

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.2
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
          tools: composer:v2
          coverage: none

      - name: Set Framework version
        run: composer config version "12.x-dev"

      - name: Install dependencies
        uses: nick-fields/retry@v3
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

      - name: Create Redis Cluster
        run: |
          sudo apt-get install -y redis-server
          sudo service redis-server stop
          redis-server --daemonize yes --port 7000 --appendonly yes --cluster-enabled yes --cluster-config-file nodes-7000.conf
          redis-server --daemonize yes --port 7001 --appendonly yes --cluster-enabled yes --cluster-config-file nodes-7001.conf
          redis-server --daemonize yes --port 7002 --appendonly yes --cluster-enabled yes --cluster-config-file nodes-7002.conf
          redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 --cluster-replicas 0 --cluster-yes

      - name: Execute tests
        run: vendor/bin/phpunit tests/Integration/Queue
        env:
          REDIS_CLIENT: ${{ matrix.client }}
          REDIS_CLUSTER_HOSTS_AND_PORTS: 127.0.0.1:7000,127.0.0.1:7001,127.0.0.1:7002
          REDIS_QUEUE: '{default}'

  beanstalkd:
    runs-on: ubuntu-24.04

    strategy:
      fail-fast: true
      matrix:
        include:
          - php: 8.2
            pheanstalk: 5
          - php: 8.3
            pheanstalk: 7

    name: Beanstalkd Driver (pda/pheanstalk:^${{ matrix.pheanstalk }})

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Download & Extract beanstalkd
        run: curl -L https://github.com/beanstalkd/beanstalkd/archive/refs/tags/v1.13.tar.gz | tar xz

      - name: Make beanstalkd
        run: make
        working-directory: beanstalkd-1.13

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
          tools: composer:v2
          coverage: none

      - name: Set Framework version
        run: composer config version "12.x-dev"

      - name: Install dependencies
        uses: nick-fields/retry@v3
        with:
          timeout_minutes: 5
          max_attempts: 5
          command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress --with="pda/pheanstalk:^${{ matrix.pheanstalk }}"

      - name: Daemonize beanstalkd
        run: ./beanstalkd-1.13/beanstalkd &

      - name: Execute tests
        run: vendor/bin/phpunit tests/Integration/Queue
        env:
          QUEUE_CONNECTION: beanstalkd
