#!/bin/bash # FFR Regression Test Suite Runner # Comprehensive test runner for the FFR application set -e echo "๐Ÿงช Starting FFR Regression Test Suite" echo "======================================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Function to print colored output print_status() { echo -e "${BLUE}โ„น๏ธ $1${NC}" } print_success() { echo -e "${GREEN}โœ… $1${NC}" } print_warning() { echo -e "${YELLOW}โš ๏ธ $1${NC}" } print_error() { echo -e "${RED}โŒ $1${NC}" } # Check if we're in the right directory if [ ! -f "composer.json" ] || [ ! -f "phpunit.xml" ]; then print_error "This script must be run from the project root directory" exit 1 fi # Set test environment export APP_ENV=testing print_status "Setting up test environment..." # Clear configuration cache php artisan config:clear --env=testing # Ensure database is set up for testing print_status "Preparing test database..." php artisan migrate:fresh --env=testing --force # Run database seeders for testing if they exist if [ -f "database/seeders/TestSeeder.php" ]; then php artisan db:seed --class=TestSeeder --env=testing fi echo "" print_status "Running regression tests..." echo "" # Track test results TOTAL_TESTS=0 FAILED_TESTS=0 # Function to run test suite and track results run_test_suite() { local suite_name="$1" local test_path="$2" local description="$3" echo "" print_status "Running $suite_name..." echo "Description: $description" if php artisan test "$test_path" --env=testing; then print_success "$suite_name passed" else print_error "$suite_name failed" FAILED_TESTS=$((FAILED_TESTS + 1)) fi TOTAL_TESTS=$((TOTAL_TESTS + 1)) } # Run individual test suites run_test_suite "API Endpoint Tests" "tests/Feature/ApiEndpointRegressionTest.php" "Tests all HTTP endpoints and routes" run_test_suite "Database Integration Tests" "tests/Feature/DatabaseIntegrationTest.php" "Tests models, relationships, and database operations" run_test_suite "Article Discovery Tests" "tests/Feature/ArticleDiscoveryCommandTest.php" "Tests article discovery command functionality" run_test_suite "Article Publishing Tests" "tests/Feature/ArticlePublishingTest.php" "Tests article publishing workflow" run_test_suite "Jobs and Events Tests" "tests/Feature/JobsAndEventsTest.php" "Tests queue jobs and event handling" run_test_suite "Authentication & Authorization Tests" "tests/Feature/AuthenticationAndAuthorizationTest.php" "Tests security and access control" run_test_suite "New Article Fetched Event Tests" "tests/Feature/NewArticleFetchedEventTest.php" "Tests new article event handling" run_test_suite "Validate Article Listener Tests" "tests/Feature/ValidateArticleListenerTest.php" "Tests article validation logic" # Run Unit Tests echo "" print_status "Running Unit Tests..." run_test_suite "Article Fetcher Unit Tests" "tests/Unit/Services/ArticleFetcherTest.php" "Tests article fetching service" run_test_suite "Validation Service Unit Tests" "tests/Unit/Services/ValidationServiceTest.php" "Tests article validation service" run_test_suite "Dashboard Stats Service Unit Tests" "tests/Unit/Services/DashboardStatsServiceTest.php" "Tests dashboard statistics service" # Run full test suite for coverage echo "" print_status "Running complete test suite for coverage..." if php artisan test --coverage-text --min=70 --env=testing; then print_success "Test coverage meets minimum requirements" else print_warning "Test coverage below 70% - consider adding more tests" fi # Performance Tests echo "" print_status "Running performance checks..." # Test database query performance php artisan test tests/Feature/DatabaseIntegrationTest.php --env=testing --stop-on-failure # Memory usage test if php -d memory_limit=128M artisan test --env=testing --stop-on-failure; then print_success "Memory usage within acceptable limits" else print_warning "High memory usage detected during tests" fi # Final Results echo "" echo "======================================" print_status "Test Suite Complete" echo "======================================" if [ $FAILED_TESTS -eq 0 ]; then print_success "All $TOTAL_TESTS test suites passed! ๐ŸŽ‰" echo "" echo "Regression test suite completed successfully." echo "The application is ready for deployment." exit 0 else print_error "$FAILED_TESTS out of $TOTAL_TESTS test suites failed" echo "" echo "Please review the failing tests before proceeding." echo "Run individual test suites with:" echo " php artisan test tests/Feature/[TestFile].php" echo " php artisan test tests/Unit/[TestFile].php" exit 1 fi