Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
uses: shivammathur/setup-php@cf4cade2721270509d5b1c766ab3549210a39a2a # v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
coverage: pcov
extensions: ctype, json, mbstring
tools: composer

Expand Down Expand Up @@ -113,7 +113,11 @@ jobs:
run: composer audit

- name: Run test suite
run: composer run-tests-with-clover
run: |
for file in $(find tests -name "*Test.php"); do
echo "Running tests from $file"
php ./bin/phpunit --configuration=./ci/phpunit/config.xml "$file"
done
Comment on lines +116 to +120
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace inline test loop with the centralized split-tests script
Duplicating loop logic here risks drift over time. Invoke the shared run-split-tests.sh script to ensure consistency between local and CI environments, and automatically handle coverage flags.

Proposed diff:

-      - name: Run test suite
-        run: |
-          for file in $(find tests -name "*Test.php"); do
-            echo "Running tests from $file"
-            php ./bin/phpunit --configuration=./ci/phpunit/config.xml "$file"
-          done
+      - name: Run split test suite (no coverage)
+        if: matrix.calculate-code-coverage != 'true'
+        run: bash ci/phpunit/run-split-tests.sh
+
+      - name: Run split test suite (with coverage)
+        if: matrix.calculate-code-coverage == 'true'
+        run: bash ci/phpunit/run-split-tests.sh --coverage-clover
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
run: |
for file in $(find tests -name "*Test.php"); do
echo "Running tests from $file"
php ./bin/phpunit --configuration=./ci/phpunit/config.xml "$file"
done
- name: Run split test suite (no coverage)
if: matrix.calculate-code-coverage != 'true'
run: bash ci/phpunit/run-split-tests.sh
- name: Run split test suite (with coverage)
if: matrix.calculate-code-coverage == 'true'
run: bash ci/phpunit/run-split-tests.sh --coverage-clover
🧰 Tools
🪛 actionlint (1.7.4)

116-116: shellcheck reported issue in this script: SC2044:warning:1:13: For loops over find output are fragile. Use find -exec or a while read loop

(shellcheck)


- name: Upload coverage results to Coveralls
if: matrix.calculate-code-coverage == true
Expand Down
75 changes: 75 additions & 0 deletions ci/phpunit/run-split-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash
set -e

# Get the directory of this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"

# Default test directories to scan
TEST_DIRS=(
"tests/MartinGeorgiev/Doctrine/DBAL/Types"
"tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions"
"tests/MartinGeorgiev/Utils"
)

# Parse command line arguments
COVERAGE_ARGS=""
if [[ "$@" == *"--coverage-clover"* ]]; then
COVERAGE_ARGS="--coverage-clover=./var/logs/test-coverage/clover.xml"
fi
Comment on lines +17 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace wildcard comparison on "$@" with explicit loop to parse flags
Shellcheck SC2199 warns about using [[ "$@" == *"--coverage-clover"* ]]. Instead of relying on wildcard matching over the entire argument string, iterate through the arguments to detect the coverage flag safely.

Proposed diff:

- if [[ "$@" == *"--coverage-clover"* ]]; then
-   COVERAGE_ARGS="--coverage-clover=./var/logs/test-coverage/clover.xml"
- fi
+ COVERAGE_ARGS=""
+ for arg in "$@"; do
+   if [ "$arg" = "--coverage-clover" ]; then
+     COVERAGE_ARGS="--coverage-clover=./var/logs/test-coverage/clover.xml"
+     break
+   fi
+ done
🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 17-17: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


# Additional PHPUnit arguments
PHPUNIT_ARGS="--testdox --display-deprecations --display-errors --display-incomplete"

# Create a temporary directory for individual coverage reports if needed
if [[ -n "$COVERAGE_ARGS" ]]; then
mkdir -p "${PROJECT_ROOT}/var/logs/test-coverage/split"
fi

# Function to run tests for a specific file
run_test_for_file() {
local test_file=$1
local relative_path=${test_file#"$PROJECT_ROOT/"}

echo "Running tests for: $relative_path"

if [[ -n "$COVERAGE_ARGS" ]]; then
# Generate a unique name for the coverage file
local coverage_file="split/$(basename "$test_file" .php).xml"
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"
else
php "${PROJECT_ROOT}/vendor/bin/phpunit" --configuration="${PROJECT_ROOT}/ci/phpunit/config.xml" $PHPUNIT_ARGS "$test_file"
fi

echo "Completed: $relative_path"
echo "----------------------------------------"
}

# Find and run tests for each file
for dir in "${TEST_DIRS[@]}"; do
if [[ -d "${PROJECT_ROOT}/${dir}" ]]; then
echo "Scanning directory: ${dir}"

# Find all test files in the directory
while IFS= read -r -d '' test_file; do
run_test_for_file "$test_file"
done < <(find "${PROJECT_ROOT}/${dir}" -name "*Test.php" -type f -print0)
else
echo "Warning: Directory ${dir} does not exist, skipping."
fi
done

# If we're generating coverage, we need to merge the reports
if [[ -n "$COVERAGE_ARGS" ]]; then
echo "Merging coverage reports..."
# You would need a tool like phpcov to merge the reports
# For now, we'll just use the last generated report as the main one

# Future enhancement: Install phpcov and use it to merge reports
# vendor/bin/phpcov merge --clover="${PROJECT_ROOT}/var/logs/test-coverage/clover.xml" "${PROJECT_ROOT}/var/logs/test-coverage/split"

echo "Note: Coverage reports are generated individually per test file."
echo "To get a combined report, consider installing phpcov."
fi

echo "All tests completed!"
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"phpstan analyse --configuration=./ci/phpstan/config.neon"
],
"phpunit": [
"XDEBUG_MODE=coverage phpunit --configuration=./ci/phpunit/config.xml"
"phpunit --configuration=./ci/phpunit/config.xml --testdox --display-deprecations --display-errors --display-incomplete"
],
"rector": [
"rector --config=./ci/rector/config.php --ansi --no-progress-bar"
Expand All @@ -94,6 +94,12 @@
],
"run-tests-with-clover": [
"@phpunit --coverage-clover=./var/logs/test-coverage/clover.xml"
],
"run-tests-split": [
"bash ./ci/phpunit/run-split-tests.sh"
],
"run-tests-split-with-clover": [
"bash ./ci/phpunit/run-split-tests.sh --coverage-clover=./var/logs/test-coverage/clover.xml"
]
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,9 @@

namespace Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Parser;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseVariadicFunction;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\ParserException;

abstract class BaseVariadicFunctionTestCase extends TestCase
{
abstract protected function createFixture(): BaseVariadicFunction;

/**
* @test
*/
public function throws_an_exception_when_lexer_is_not_populated_with_a_lookahead_type(): void
{
$this->expectException(ParserException::class);

$em = $this->createMock(EntityManager::class);
$em->expects($this->any())
->method('getConfiguration')
->willReturn(new Configuration());

$query = new Query($em);
$query->setDQL('TRUE');

$parser = new Parser($query);
$parser->getLexer()->moveNext();

$baseVariadicFunction = $this->createFixture();

$reflectionMethod = new \ReflectionMethod($baseVariadicFunction::class, 'feedParserWithNodesForNodeMappingPattern');
$reflectionMethod->setAccessible(true);
$reflectionMethod->invoke($baseVariadicFunction, $parser, 'ArithmeticPrimary');
}
}

This file was deleted.

Loading