Requests icon indicating copy to clipboard operation
Requests copied to clipboard

Streamline local test environment setup

Open schlessera opened this issue 1 year ago • 4 comments

Refactored the test environment setup to make it more robust and user-friendly. This consolidates multiple test commands and improves process management for local development.

Fixes #819

What Changed

  • Added shell scripts to manage test environment lifecycle
  • Consolidated PHPUnit commands to auto-detect version and config
  • Improved process management with proper PID tracking
  • Added mitmproxy version verification (≥11.0.2 required)
  • Adapted CONTRIBUTING.md to explain the new setup

The main improvement is the simplified test workflow. Instead of juggling different commands for PHPUnit versions and remembering to start/stop test servers, everything is now handled through clear, single-purpose commands.

New Scripts

  • scripts/start-test-environment.sh - Boots test and proxy servers - should be sourced to set environment vairables
  • scripts/stop-test-environment.sh - Clean shutdown of all processes
  • scripts/run-phpunit.sh - Version-agnostic PHPUnit runner

Usage

Basic testing is now simpler:

composer test # Run tests (auto-detects PHPUnit version)
composer coverage # Same, but with coverage

For development with local test servers:

# Direct usage (sets env vars in your shell)
source scripts/start-test-environment.sh
scripts/run-phpunit.sh
scripts/stop-test-environment.sh

# Or through composer (automated start/stop)
composer test:withserver
composer coverage:withserver

schlessera avatar Dec 11 '24 11:12 schlessera

Future scope: add a Docker config file to get up & running with even less effort (and which would work on Windows too).

jrfnl avatar Dec 11 '24 12:12 jrfnl

Just noticed, just running the script on my machine created some .test-pids/*.pid files. You may want to add those to the .gitignore file ?

jrfnl avatar Dec 11 '24 12:12 jrfnl

I changed the folder where PIDs are stored and added that location to .gitignore: tests/utils/pids

schlessera avatar Dec 11 '24 14:12 schlessera

Just checking - this PR relates to #819 (and closes it ?)

jrfnl avatar Jan 22 '25 10:01 jrfnl