Skip to content

Commit 4fa7831

Browse files
no message
1 parent 34eb11b commit 4fa7831

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ jobs:
113113
run: composer audit
114114

115115
- name: Run test suite
116-
run: composer run-tests-with-clover
116+
run: |
117+
for file in tests/MartinGeorgiev/**/*Test.php; do
118+
echo "Running $file"
119+
php vendor/bin/phpunit --configuration=./ci/phpunit/config.xml "$file"
120+
done
117121
118122
- name: Upload coverage results to Coveralls
119123
if: matrix.calculate-code-coverage == true

ci/phpunit/run-split-tests.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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!"

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@
9494
],
9595
"run-tests-with-clover": [
9696
"@phpunit --coverage-clover=./var/logs/test-coverage/clover.xml"
97+
],
98+
"run-tests-split": [
99+
"bash ./ci/phpunit/run-split-tests.sh"
100+
],
101+
"run-tests-split-with-clover": [
102+
"bash ./ci/phpunit/run-split-tests.sh --coverage-clover=./var/logs/test-coverage/clover.xml"
97103
]
98104
},
99105

0 commit comments

Comments
 (0)