|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Get the directory of this script |
| 5 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 6 | +PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" |
| 7 | + |
| 8 | +# Default test directories to scan |
| 9 | +TEST_DIRS=( |
| 10 | + "tests/MartinGeorgiev/Doctrine/DBAL/Types" |
| 11 | + "tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions" |
| 12 | + "tests/MartinGeorgiev/Utils" |
| 13 | +) |
| 14 | + |
| 15 | +# Parse command line arguments |
| 16 | +COVERAGE_ARGS="" |
| 17 | +if [[ "$@" == *"--coverage-clover"* ]]; then |
| 18 | + COVERAGE_ARGS="--coverage-clover=./var/logs/test-coverage/clover.xml" |
| 19 | +fi |
| 20 | + |
| 21 | +# Additional PHPUnit arguments |
| 22 | +PHPUNIT_ARGS="--testdox --display-deprecations --display-errors --display-incomplete" |
| 23 | + |
| 24 | +# Create a temporary directory for individual coverage reports if needed |
| 25 | +if [[ -n "$COVERAGE_ARGS" ]]; then |
| 26 | + mkdir -p "${PROJECT_ROOT}/var/logs/test-coverage/split" |
| 27 | +fi |
| 28 | + |
| 29 | +# Function to run tests for a specific file |
| 30 | +run_test_for_file() { |
| 31 | + local test_file=$1 |
| 32 | + local relative_path=${test_file#"$PROJECT_ROOT/"} |
| 33 | + |
| 34 | + echo "Running tests for: $relative_path" |
| 35 | + |
| 36 | + if [[ -n "$COVERAGE_ARGS" ]]; then |
| 37 | + # Generate a unique name for the coverage file |
| 38 | + local coverage_file="split/$(basename "$test_file" .php).xml" |
| 39 | + php "${PROJECT_ROOT}/vendor/bin/phpunit" --configuration="${PROJECT_ROOT}/ci/phpunit/config.xml" $PHPUNIT_ARGS --coverage-clover="${PROJECT_ROOT}/var/logs/test-coverage/$coverage_file" "$test_file" |
| 40 | + else |
| 41 | + php "${PROJECT_ROOT}/vendor/bin/phpunit" --configuration="${PROJECT_ROOT}/ci/phpunit/config.xml" $PHPUNIT_ARGS "$test_file" |
| 42 | + fi |
| 43 | + |
| 44 | + echo "Completed: $relative_path" |
| 45 | + echo "----------------------------------------" |
| 46 | +} |
| 47 | + |
| 48 | +# Find and run tests for each file |
| 49 | +for dir in "${TEST_DIRS[@]}"; do |
| 50 | + if [[ -d "${PROJECT_ROOT}/${dir}" ]]; then |
| 51 | + echo "Scanning directory: ${dir}" |
| 52 | + |
| 53 | + # Find all test files in the directory |
| 54 | + while IFS= read -r -d '' test_file; do |
| 55 | + run_test_for_file "$test_file" |
| 56 | + done < <(find "${PROJECT_ROOT}/${dir}" -name "*Test.php" -type f -print0) |
| 57 | + else |
| 58 | + echo "Warning: Directory ${dir} does not exist, skipping." |
| 59 | + fi |
| 60 | +done |
| 61 | + |
| 62 | +# If we're generating coverage, we need to merge the reports |
| 63 | +if [[ -n "$COVERAGE_ARGS" ]]; then |
| 64 | + echo "Merging coverage reports..." |
| 65 | + # You would need a tool like phpcov to merge the reports |
| 66 | + # For now, we'll just use the last generated report as the main one |
| 67 | + |
| 68 | + # Future enhancement: Install phpcov and use it to merge reports |
| 69 | + # vendor/bin/phpcov merge --clover="${PROJECT_ROOT}/var/logs/test-coverage/clover.xml" "${PROJECT_ROOT}/var/logs/test-coverage/split" |
| 70 | + |
| 71 | + echo "Note: Coverage reports are generated individually per test file." |
| 72 | + echo "To get a combined report, consider installing phpcov." |
| 73 | +fi |
| 74 | + |
| 75 | +echo "All tests completed!" |
0 commit comments