#!/bin/bash # PHPUnit test runner script for Docker environment # Usage: ./bin/phpunit [options] # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Get the directory of this script SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PROJECT_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )" # Change to project root cd "$PROJECT_ROOT" # Check if backend container is running if ! podman-compose -f docker-compose.dev.yml ps | grep "trip-planner-backend-dev" | grep -q "Up"; then echo -e "${RED}Error: Backend container is not running${NC}" echo -e "${YELLOW}Please start the containers first with: podman-compose -f docker-compose.dev.yml up -d${NC}" exit 1 fi # Run PHPUnit tests echo -e "${GREEN}Running PHPUnit tests...${NC}" # If no arguments provided, run all tests if [ $# -eq 0 ]; then echo -e "${BLUE}Running all tests...${NC}" podman-compose -f docker-compose.dev.yml exec backend php -d memory_limit=512M artisan test else # Pass all arguments to phpunit echo -e "${BLUE}Running tests with options: $*${NC}" podman-compose -f docker-compose.dev.yml exec backend php -d memory_limit=512M artisan test "$@" fi # Capture exit code EXIT_CODE=$? # Display result if [ $EXIT_CODE -eq 0 ]; then echo -e "${GREEN}✓ All tests passed successfully${NC}" else echo -e "${RED}✗ Some tests failed${NC}" fi echo -e "${YELLOW}Tip: You can also run specific tests:${NC}" echo -e " ${BLUE}./bin/phpunit --filter=PlannableItemTest${NC}" echo -e " ${BLUE}./bin/phpunit tests/Feature/PlannableItemTest.php${NC}" echo -e " ${BLUE}./bin/phpunit --coverage-html=coverage${NC}" exit $EXIT_CODE