Skip to content

Conversation

@martin-georgiev
Copy link
Owner

@martin-georgiev martin-georgiev commented Aug 3, 2025

Summary by CodeRabbit

  • Refactor

    • Improved clarity and consistency of test method names across multiple test classes.
    • Consolidated separate tests for invalid argument counts into single parameterized tests using data providers, reducing code duplication and centralizing test cases.
    • Updated test data arrays to use descriptive string keys for better readability and identification.
    • Expanded test coverage with additional cases for several functions, enhancing robustness.
    • Added precise error handling for functions requiring an exact number of arguments.
  • Tests

    • Enhanced test structure for exception handling, ensuring more maintainable and descriptive test coverage for argument validation scenarios.
    • Added new tests to verify specific exception messages for argument count and value validation.

@martin-georgiev martin-georgiev changed the title chore: improve test coverage and standardize style of unit tests in ORM\Functions namespace chore: improve test coverage and standardize style of unit tests in ORM\Query\AST\Functions namespace Aug 3, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 3, 2025

Walkthrough

This change refactors and standardizes exception-related unit test methods for various Doctrine ORM query AST functions. Many test methods are renamed for clarity and descriptiveness, while some are consolidated into parameterized tests using data providers to centralize and streamline invalid argument count checks. Test logic and exception expectations remain unchanged.

Changes

Cohort / File(s) Change Summary
Test Method Renaming (Descriptive Names)
.../ArrayToJsonTest.php, .../DateAddTest.php, .../GreatestTest.php, .../JsonBuildObjectTest.php, .../JsonbBuildObjectTest.php, .../JsonbInsertTest.php, .../JsonbPathExistsTest.php, .../JsonbPathMatchTest.php, .../JsonbPathQueryArrayTest.php, .../JsonbPathQueryFirstTest.php, .../JsonbPathQueryTest.php, .../JsonbSetTest.php, .../LeastTest.php, .../RegexpLikeTest.php, .../RegexpMatchTest.php, .../RowToJsonTest.php, .../ToCharTest.php, .../ToDateTest.php, .../ToNumberTest.php, .../ToTimestampTest.php, .../ToTsqueryTest.php, .../ToTsvectorTest.php, .../UnaccentTest.php
Test method names updated for clarity and descriptiveness; no logic changes.
Parameterized Invalid Argument Count Tests
.../ArrayPositionTest.php, .../DateSubtractTest.php, .../RegexpCountTest.php, .../RegexpInstrTest.php, .../RegexpReplaceTest.php, .../RegexpSubstrTest.php
Separate tests for invalid argument counts consolidated into parameterized tests using data providers.
Test Arrays Updated with Descriptive Keys
.../AllTest.php, .../CeilTest.php, .../FloorTest.php, .../RegexpTest.php, .../StartsWithTest.php, .../StringToArrayTest.php, .../UnaccentTest.php, .../ToCharTest.php, .../RandomTest.php, .../SimilarToTest.php, .../DateExtractTest.php, .../DateOverlapsTest.php, .../FlaggedRegexpMatchTest.php, .../FlaggedRegexpReplaceTest.php, .../IRegexpTest.php, .../IsContainedByTest.php, .../JsonValueTest.php, .../NotIRegexpTest.php, .../NotRegexpTest.php, .../NotSimilarToTest.php, .../OverlapsTest.php, .../StrConcatTest.php, .../ToJsonbTest.php, .../TsmatchTest.php, .../DistanceTest.php, .../FlaggedRegexpLikeTest.php, .../JsonGetObjectTest.php, .../ReturnsValueForJsonValueTest.php, .../TheRightExistsOnTheLeftTest.php
Test data arrays changed from numeric to descriptive string keys; test logic and statements unchanged.
Expanded Test Coverage with Additional Cases
.../SplitPartTest.php
Added new test cases with descriptive keys covering edge cases and variants for split_part function.
Additional Exception Tests Added
.../WidthBucketTest.php
Added tests for too few and too many arguments exceptions with specific messages for WidthBucket function.
BaseVariadicFunction Argument Count Validation Improved
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php
Added exact argument count validation and more precise exception messages when min and max argument counts match.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant DataProvider
    participant TestMethod

    TestRunner->>DataProvider: Fetch test cases (DQL, expected message)
    loop For each test case
        TestRunner->>TestMethod: Run test with DQL, expected message
        TestMethod->>TestMethod: Execute query, expect exception
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Suggested labels

enhancement, dx

Poem

In the garden of tests, where exceptions bloom bright,
Rabbits refactor with data providers' delight.
Gone are duplications, replaced with one hop,
Parameterized checks—no need to stop!
Now naming is clear, and the burrow runs deep,
With code that is tidy, and coverage to keep.
🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 56ae54d and 21dc61a.

📒 Files selected for processing (5)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php (2 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPositionTest.php (3 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateAddTest.php (2 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateSubtractTest.php (2 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WidthBucketTest.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPositionTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateAddTest.php
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#383
File: tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RadiansTest.php:1-9
Timestamp: 2025-05-23T11:11:57.951Z
Learning: Tests in the `Tests\Unit\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions` namespace extend a custom `TestCase` class from the same namespace (`Tests\Unit\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase`), rather than PHPUnit's TestCase directly, and therefore don't need an explicit import.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#318
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php:1-9
Timestamp: 2025-03-29T03:31:17.114Z
Learning: Tests in the `Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions` namespace extend a custom `TestCase` class from the same namespace (`Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase`), rather than PHPUnit's TestCase, and therefore don't need an explicit import.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#318
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php:1-9
Timestamp: 2025-03-29T03:31:17.114Z
Learning: Tests in the `Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions` namespace extend a custom `TestCase` class from the same namespace (`Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase`), not PHPUnit's TestCase, and therefore don't need an explicit import statement.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#357
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpMatchTest.php:28-62
Timestamp: 2025-04-22T00:03:37.733Z
Learning: This project focuses on providing Doctrine ORM interfaces to PostgreSQL functions. Tests should validate correct DQL-to-SQL translation rather than PostgreSQL functionality itself. Test cases should focus on parameter passing and SQL generation, not on testing specific PostgreSQL regex pattern behaviors.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#0
File: :0-0
Timestamp: 2025-04-17T12:29:38.149Z
Learning: All new features in this repository must include proper test coverage before approval.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#340
File: tests/MartinGeorgiev/Doctrine/DBAL/Types/InetArrayTest.php:145-145
Timestamp: 2025-04-11T11:23:44.192Z
Learning: In the PostgreSQL for Doctrine test cases, methods that test database-to-PHP conversions should use `mixed` type for parameter and include non-string test cases in their data providers, following the pattern in classes like InetTest, CidrTest, and MacaddrTest.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#0
File: :0-0
Timestamp: 2025-04-23T20:20:39.026Z
Learning: In this project, unit tests should avoid using reflection (ReflectionMethod) to test protected methods directly, and instead use fixtures to test through public interfaces, even if it means slightly lower test coverage.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#352
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpInstrTest.php:1-67
Timestamp: 2025-04-20T11:24:18.300Z
Learning: This PostgreSQL-for-Doctrine project is a translation layer only, focusing on correctly converting Doctrine DQL to PostgreSQL SQL syntax. It ensures arguments are passed in the expected format but does not test or handle PostgreSQL's actual function behavior or data handling. Test cases should focus on DQL-to-SQL translation and argument validation, not on PostgreSQL-specific behaviors.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#350
File: src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php:78-88
Timestamp: 2025-04-18T10:33:52.412Z
Learning: In SQL generation code for the postgresql-for-doctrine library, it's better to fail explicitly with clear errors than to use fallback behavior that makes assumptions about node types, as this could lead to functional bugs or security issues.
Learnt from: karpilin
PR: martin-georgiev/postgresql-for-doctrine#386
File: tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php:34-39
Timestamp: 2025-05-27T16:10:35.054Z
Learning: When reviewing PostgreSQL formatting function tests, the error handling behavior should match PostgreSQL's actual implementation rather than assuming consistency across all formatting functions, as different functions may handle invalid inputs differently.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#309
File: tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseTypeTest.php:0-0
Timestamp: 2025-03-26T23:51:33.709Z
Learning: The requiresSQLCommentHint() method is intentionally kept in tests to support backwards compatibility with older Doctrine DBAL versions, even though it's deprecated in newer versions and triggers static analysis warnings. The method isn't used in production code.
📚 Learning: when implementing node mapping patterns in basevariadicfunction subclasses, if all parameters should...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#371
File: src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Tsrange.php:25-27
Timestamp: 2025-05-13T00:08:41.638Z
Learning: When implementing node mapping patterns in BaseVariadicFunction subclasses, if all parameters should be of the same type, simply return an array with a single string element (e.g., ['StringPrimary']). This approach uses the same type for all parameters while min/max argument counts can be controlled separately.

Applied to files:

  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php
📚 Learning: in sql generation code for the postgresql-for-doctrine library, it's better to fail explicitly with ...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#350
File: src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php:78-88
Timestamp: 2025-04-18T10:33:52.412Z
Learning: In SQL generation code for the postgresql-for-doctrine library, it's better to fail explicitly with clear errors than to use fallback behavior that makes assumptions about node types, as this could lead to functional bugs or security issues.

Applied to files:

  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WidthBucketTest.php
📚 Learning: tests in the `tests\unit\martingeorgiev\doctrine\orm\query\ast\functions` namespace extend a custom ...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#383
File: tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RadiansTest.php:1-9
Timestamp: 2025-05-23T11:11:57.951Z
Learning: Tests in the `Tests\Unit\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions` namespace extend a custom `TestCase` class from the same namespace (`Tests\Unit\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase`), rather than PHPUnit's TestCase directly, and therefore don't need an explicit import.

Applied to files:

  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WidthBucketTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateSubtractTest.php
📚 Learning: tests in the `tests\martingeorgiev\doctrine\orm\query\ast\functions` namespace extend a custom `test...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#318
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php:1-9
Timestamp: 2025-03-29T03:31:17.114Z
Learning: Tests in the `Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions` namespace extend a custom `TestCase` class from the same namespace (`Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase`), rather than PHPUnit's TestCase, and therefore don't need an explicit import.

Applied to files:

  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WidthBucketTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateSubtractTest.php
📚 Learning: tests in the `tests\martingeorgiev\doctrine\orm\query\ast\functions` namespace extend a custom `test...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#318
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php:1-9
Timestamp: 2025-03-29T03:31:17.114Z
Learning: Tests in the `Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions` namespace extend a custom `TestCase` class from the same namespace (`Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase`), not PHPUnit's TestCase, and therefore don't need an explicit import statement.

Applied to files:

  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WidthBucketTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateSubtractTest.php
📚 Learning: in the postgresql-for-doctrine repository, postgresql range functions have distinct implementations ...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#263
File: src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Numrange.php:19-21
Timestamp: 2025-03-11T12:32:10.726Z
Learning: In the postgresql-for-doctrine repository, PostgreSQL range functions have distinct implementations for different data types. The `Numrange` function works with numeric/decimal values and is tested using the `ContainsDecimals` fixture with properties typed as `float`. In contrast, the `Int4range` function works with 32-bit integers and is tested using the `ContainsIntegers` fixture with properties typed as `int`. While the PHP implementations share a similar structure (extending `BaseFunction`), they are semantically different as they handle different PostgreSQL data types.

Applied to files:

  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WidthBucketTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateSubtractTest.php
📚 Learning: in the postgresql for doctrine test cases, methods that test database-to-php conversions should use ...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#340
File: tests/MartinGeorgiev/Doctrine/DBAL/Types/InetArrayTest.php:145-145
Timestamp: 2025-04-11T11:23:44.192Z
Learning: In the PostgreSQL for Doctrine test cases, methods that test database-to-PHP conversions should use `mixed` type for parameter and include non-string test cases in their data providers, following the pattern in classes like InetTest, CidrTest, and MacaddrTest.

Applied to files:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WidthBucketTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateSubtractTest.php
📚 Learning: this project focuses on providing doctrine orm interfaces to postgresql functions. tests should vali...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#357
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpMatchTest.php:28-62
Timestamp: 2025-04-22T00:03:37.733Z
Learning: This project focuses on providing Doctrine ORM interfaces to PostgreSQL functions. Tests should validate correct DQL-to-SQL translation rather than PostgreSQL functionality itself. Test cases should focus on parameter passing and SQL generation, not on testing specific PostgreSQL regex pattern behaviors.

Applied to files:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WidthBucketTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateSubtractTest.php
📚 Learning: when reviewing postgresql formatting function tests, the error handling behavior should match postgr...
Learnt from: karpilin
PR: martin-georgiev/postgresql-for-doctrine#386
File: tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php:34-39
Timestamp: 2025-05-27T16:10:35.054Z
Learning: When reviewing PostgreSQL formatting function tests, the error handling behavior should match PostgreSQL's actual implementation rather than assuming consistency across all formatting functions, as different functions may handle invalid inputs differently.

Applied to files:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WidthBucketTest.php
📚 Learning: this postgresql-for-doctrine project is a translation layer only, focusing on correctly converting d...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#352
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpInstrTest.php:1-67
Timestamp: 2025-04-20T11:24:18.300Z
Learning: This PostgreSQL-for-Doctrine project is a translation layer only, focusing on correctly converting Doctrine DQL to PostgreSQL SQL syntax. It ensures arguments are passed in the expected format but does not test or handle PostgreSQL's actual function behavior or data handling. Test cases should focus on DQL-to-SQL translation and argument validation, not on PostgreSQL-specific behaviors.

Applied to files:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WidthBucketTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateSubtractTest.php
📚 Learning: the requiressqlcommenthint() method is intentionally kept in tests to support backwards compatibilit...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#309
File: tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseTypeTest.php:0-0
Timestamp: 2025-03-26T23:51:33.709Z
Learning: The requiresSQLCommentHint() method is intentionally kept in tests to support backwards compatibility with older Doctrine DBAL versions, even though it's deprecated in newer versions and triggers static analysis warnings. The method isn't used in production code.

Applied to files:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WidthBucketTest.php
🧬 Code Graph Analysis (1)
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateSubtractTest.php (4)
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateAddTest.php (4)
  • getDqlStatements (38-45)
  • Test (47-55)
  • Test (57-65)
  • provideInvalidTimezoneValues (81-89)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Exception/InvalidArgumentForVariadicFunctionException.php (1)
  • InvalidArgumentForVariadicFunctionException (7-56)
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TestCase.php (1)
  • buildEntityManager (115-118)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Exception/InvalidTimezoneException.php (1)
  • InvalidTimezoneException (14-33)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: PostgreSQL 16 + PHP 8.4
  • GitHub Check: PostgreSQL 17 + PHP 8.3
  • GitHub Check: PostgreSQL 17 + PHP 8.2
  • GitHub Check: PostgreSQL 16 + PHP 8.2
  • GitHub Check: PostgreSQL 17 + PHP 8.1
  • GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest
  • GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest
  • GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
  • GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
  • GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2
  • GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest
  • GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest
  • GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest
  • GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest
  • GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
  • GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
  • GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0
  • GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0
  • GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
  • GitHub Check: sloth
🔇 Additional comments (16)
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WidthBucketTest.php (4)

8-8: LGTM! Appropriate imports added for new functionality.

The imports for InvalidArgumentForVariadicFunctionException and PHPUnit's Test attribute are correctly added to support the new argument validation tests.

Also applies to: 10-10


24-25: Excellent improvement in test readability.

Adding descriptive keys to the test data arrays significantly improves the clarity and maintainability of the test cases. This change aligns well with the broader standardization effort mentioned in the AI summary.

Also applies to: 32-33


37-45: Proper argument validation test for too few arguments.

The test correctly validates that WIDTH_BUCKET function throws an appropriate exception when called with fewer than the required 4 arguments. The test follows the established pattern in this codebase for testing DQL-to-SQL translation and argument validation.


47-55: Proper argument validation test for too many arguments.

The test correctly validates that WIDTH_BUCKET function throws an appropriate exception when called with more than the required 4 arguments. This complements the previous test to ensure comprehensive argument count validation.

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php (4)

84-86: LGTM! Enhanced exact argument count validation during parsing.

The conditional check for exact argument count improves error messaging by providing more specific feedback when a function requires an exact number of arguments rather than a range.


121-123: LGTM! Consistent exact argument count validation in final validation.

The implementation mirrors the parsing-phase validation and ensures consistent error messaging throughout the validation process.


84-86: LGTM! Improved error handling for exact argument count requirements.

This addition provides more specific exception messages when functions require an exact number of arguments, enhancing error clarity for developers.


121-123: LGTM! Consistent validation logic for exact argument counts.

This mirrors the parsing-phase logic and ensures comprehensive validation. The early return pattern prevents redundant range checks when exact counts are required.

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateSubtractTest.php (8)

12-12: LGTM! Added necessary import for data provider attributes.

The DataProvider attribute import is required for the parameterized test methods introduced in this refactoring.


32-34: LGTM! Enhanced test case descriptions and added WHERE clause coverage.

The more descriptive test case names and the addition of a "used in WHERE clause" test case improve test coverage and clarity. This aligns with the project's focus on DQL-to-SQL translation testing.

Also applies to: 41-43


47-72: LGTM! Well-structured parameterized test for argument count validation.

The consolidation of separate argument count tests into a parameterized test with a data provider reduces code duplication and improves maintainability. The exception messages correctly match the enhanced validation logic from BaseVariadicFunction.


74-96: LGTM! Parameterized timezone validation test with comprehensive test cases.

The refactored timezone validation test uses a data provider effectively and covers various invalid timezone scenarios. The exception expectations correctly reference the InvalidTimezoneException class and include proper message formatting.


12-12: LGTM! Required import for DataProvider attribute.

This import is necessary for the data provider refactoring that follows.


32-35: LGTM! Improved test case descriptions and added WHERE clause coverage.

The updated descriptions are more explicit about argument counts, and the new "used in WHERE clause" test case provides valuable coverage for different usage contexts.

Also applies to: 41-43


47-72: LGTM! Excellent consolidation of argument count validation tests.

The parameterized approach using data providers is much cleaner than separate test methods. The specific exception message assertions align perfectly with the enhanced error handling in BaseVariadicFunction.


74-96: LGTM! Consistent parameterization of timezone validation tests.

The data provider approach maintains comprehensive coverage of invalid timezone scenarios while following the same pattern as the argument count tests. The exception message assertion correctly uses the specific timezone value.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch more-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (15)
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpLikeTest.php (1)

53-55: Consider collapsing both “too few / too many” checks into a single data-provider test
Many other function tests now use one parameterised method fed by a data-provider to exercise invalid-argument scenarios, reducing duplication and streamlining future changes. This file still keeps two nearly identical test bodies. Migrating to a data-provider here would align with the newer pattern and cut a few lines of boilerplate.

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php (1)

45-52: Consider upgrading this single-case method to a data-provider test for suite-wide consistency

Across this PR most “invalid argument count” checks were consolidated into parameterized tests. Keeping a one-off method here breaks the emerging pattern and slightly increases boilerplate.
Migrating this assertion to a data provider (invalidArgumentCountProvider) would standardize structure and make adding more edge-cases trivial.

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbPathQueryFirstTest.php (1)

58-66: Minor duplication – consider a small DRY refactor

throws_exception_for_too_few_arguments() mirrors the same 3-line “arrange/act” block found in the other two negative-path tests. Extracting that snippet into a private helper (e.g. assertSqlGenerationThrows(string $dql): void) would shave a few lines and keep future tests tidy.

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpMatchTest.php (1)

54-61: Optional: collapse the two “argument-count” tests into a single data-provider test

Other function test classes in this PR consolidated the “too few / too many” cases via a data provider. Doing the same here would remove duplication while keeping coverage identical.

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbPathExistsTest.php (1)

68-76: Minor duplication remains – consider a data-provider refactor

All three negative-case tests differ only by input/expected message. A small data-provider would eliminate repetition and make future edge-case additions cheaper:

+#[DataProvider('invalidCalls')]
+public function throws_exception_for_invalid_calls(
+    string $dql,
+    string $expectedMessage,
+): void {
+    $this->expectException(InvalidArgumentForVariadicFunctionException::class);
+    $this->expectExceptionMessage($expectedMessage);
+    $this->buildEntityManager()->createQuery($dql)->getSQL();
+}
+
+public static function invalidCalls(): array
+{
+    $class = ContainsJsons::class;
+    return [
+        'too few'  => [
+            \sprintf('SELECT JSONB_PATH_EXISTS(e.object1) FROM %s e', $class),
+            'jsonb_path_exists() requires at least 2 arguments',
+        ],
+        'too many' => [
+            \sprintf("SELECT JSONB_PATH_EXISTS(e.object1, '$.items[*].id', '{\"strict\": false}', 'true', 'extra') FROM %s e", $class),
+            'jsonb_path_exists() requires between 2 and 4 arguments',
+        ],
+    ];
+}

Not mandatory, but it would align this class with other newly-parameterised tests in the suite.

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateAddTest.php (2)

48-56: Assertion on verbose exception message is brittle

The test already verifies the concrete exception class; additionally asserting the full exception message ties the test to an exact wording that may legitimately change in the future without altering behaviour.
Unless the message itself is part of the public contract, consider dropping expectExceptionMessage() here (and in the two following tests) to keep the test resilient to minor wording tweaks.


58-76: Combine the two argument-count tests into a single data-provider case

Across the PR you switched many too-few / too-many arguments checks to a parameterised test + data provider. Keeping throws_exception_for_too_few_arguments() and throws_exception_for_too_many_arguments() as separate methods breaks that freshly introduced pattern.

Suggestion: merge them into one throws_exception_for_invalid_argument_count method fed by a provider like:

public static function invalidArgumentCountCases(): iterable
{
    yield 'too few'  => ['SELECT DATE_ADD(e.datetimetz1) FROM %s e'];
    yield 'too many' => ["SELECT DATE_ADD(e.datetimetz1, '1 day', 'Europe/Sofia', 'extra') FROM %s e"];
}

#[Test]
#[DataProvider('invalidArgumentCountCases')]
public function throws_exception_for_invalid_argument_count(string $dqlTemplate): void
{
    $this->expectException(InvalidArgumentForVariadicFunctionException::class);
    $this->buildEntityManager()->createQuery(sprintf($dqlTemplate, ContainsDates::class))->getSQL();
}

This keeps the suite consistent with the rest of the refactor and removes duplication.

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RowToJsonTest.php (1)

56-64: Consistent naming; optional consolidation via data provider

The new throws_exception_for_too_many_arguments name aligns with the updated style.
If you plan additional cleanup, consider grouping “invalid argument count” cases for variadic functions into a single parameterised test (data provider) to reduce duplication across similar test classes.

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbPathQueryTest.php (1)

58-76: Consider folding the “too-few / too-many arguments” checks into a data-provider.

Both tests differ only in:

  • the DQL statement
  • the expected exception message

A tiny data-provider would eliminate duplication and keep future maintenance (e.g. message wording tweaks) in one place.

Example sketch:

/**
 * @return iterable<string,array{string,string}>
 */
public static function invalidArgumentCountProvider(): iterable
{
    yield 'too few'  => ['SELECT JSONB_PATH_QUERY(e.object1) FROM %s e', 'requires at least 2 arguments'];
    yield 'too many' => ["SELECT JSONB_PATH_QUERY(e.object1, '$.items[*].id', '{\"strict\": false}', 'true', 'extra') FROM %s e", 'requires between 2 and 4 arguments'];
}

#[Test]
#[DataProvider('invalidArgumentCountProvider')]
public function throws_exception_for_invalid_argument_count(string $dqlPattern, string $message): void
{
    $this->expectException(InvalidArgumentForVariadicFunctionException::class);
    $this->expectExceptionMessage($message);

    $dql = \sprintf($dqlPattern, ContainsJsons::class);
    $this->buildEntityManager()->createQuery($dql)->getSQL();
}

Not mandatory, yet it keeps the test file concise and consistent with other refactors in the PR.

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbPathQueryArrayTest.php (1)

48-76: Optionally consolidate the three exception checks via a data provider

The three methods differ only by:

  1. Expected exception message.
  2. DQL string.

You could eliminate duplication and tighten maintenance by parameterising them:

#[DataProvider('invalidArguments')]
public function test_exceptions(string $dql, string $expectedMessage): void
{
    $this->expectException(InvalidArgumentForVariadicFunctionException::class);
    $this->expectExceptionMessage($expectedMessage);

    $this->buildEntityManager()->createQuery($dql)->getSQL();
}

public static function invalidArguments(): array
{
    return [
        'too few'  => [
            \sprintf('SELECT JSONB_PATH_QUERY_ARRAY(e.object1) FROM %s e', ContainsJsons::class),
            'jsonb_path_query_array() requires at least 2 arguments',
        ],
        'too many' => [
            \sprintf("SELECT JSONB_PATH_QUERY_ARRAY(e.object1, '$.items[*].id', '{\"strict\": false}', 'true', 'extra_arg') FROM %s e", ContainsJsons::class),
            'jsonb_path_query_array() requires between 2 and 4 arguments',
        ],
        // keep the boolean-specific check in its own method because it throws a different exception class
    ];
}

This mirrors the consolidation approach already introduced in other updated tests within the PR, reduces boilerplate, and keeps future changes (e.g., message wording) centralised.

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbInsertTest.php (3)

38-46: Prefer expectExceptionMessageMatches() for future-proofing

The assertion locks the test to the entire exception string.
Any cosmetic tweak to the wording in InvalidBooleanException (capitalisation, punctuation, etc.) will break the test even though behaviour is unchanged.
Using a regex expectation is less brittle while still validating the essential part:

-        $this->expectExceptionMessage('Invalid boolean value "invalid" provided for jsonb_insert. Must be "true" or "false".');
+        $this->expectExceptionMessageMatches(
+            '/Invalid boolean value "invalid" provided .*jsonb_insert/i'
+        );

48-56: Consolidate argument-count checks via a data provider

Both too few and too many argument cases exercise identical mechanics (invalid arity ➜ same exception).
Merging them into a single parameterised test eliminates duplication and keeps new edge-cases in one place:

#[Test]
#[TestWith(['SELECT JSONB_INSERT(e.object1)'])]
#[TestWith(["SELECT JSONB_INSERT(e.object1, '{country}', '{\"iso\"}', 'true', 'extra')"])]
public function throws_exception_for_invalid_argument_count(string $dql): void
{
    $this->expectException(InvalidArgumentForVariadicFunctionException::class);
    $this->buildEntityManager()->createQuery(
        \sprintf($dql, ContainsJsons::class)
    )->getSQL();
}

58-66: Minor: keep DQL fixtures consistent

Elsewhere in the file you use uppercase "BGR" for the ISO code; here it is lowercase "bgr".
Uniform fixtures make diffing easier when failures occur.

No action required if intentional.

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbSetTest.php (1)

44-72: Consider folding the three exception-path tests into a data-provider for consistency

Elsewhere in this PR several function test classes (“ArrayPositionTest”, “DateSubtractTest”, “RegexpCountTest”, …) were migrated to parameterised tests that consume a data provider to cover the “too few / too many / invalid value” branches.
Replicating that pattern here would:

  • Remove method-level duplication (the arrange/act logic is identical).
  • Keep the naming style consistent across the Functions test suite.
  • Make it trivial to add additional invalid-input cases later.

Not blocking, but worth applying while you’re already standardising the suite.

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbPathMatchTest.php (1)

59-76: DRY up the two “argument-count” tests with a data provider
Both methods differ only in the DQL string and the expected message. A single parameterised test keeps intent clear while eliminating duplication.

-    #[Test]
-    public function throws_exception_for_too_few_arguments(): void
-    {
-        $this->expectException(InvalidArgumentForVariadicFunctionException::class);
-        $this->expectExceptionMessage('jsonb_path_match() requires at least 2 arguments');
-
-        $dql = \sprintf('SELECT JSONB_PATH_MATCH(e.object1) FROM %s e', ContainsJsons::class);
-        $this->buildEntityManager()->createQuery($dql)->getSQL();
-    }
-
-    #[Test]
-    public function throws_exception_for_too_many_arguments(): void
-    {
-        $this->expectException(InvalidArgumentForVariadicFunctionException::class);
-        $this->expectExceptionMessage('jsonb_path_match() requires between 2 and 4 arguments');
-
-        $dql = \sprintf("SELECT JSONB_PATH_MATCH(e.object1, '$.items[*].id', '{\"strict\": false}', 'true', 'extra_arg') FROM %s e", ContainsJsons::class);
-        $this->buildEntityManager()->createQuery($dql)->getSQL();
-    }
+    #[Test]
+    #[DataProvider('invalidArgumentCountProvider')]
+    public function throws_exception_for_invalid_argument_count(string $dql, string $expectedMessage): void
+    {
+        $this->expectException(InvalidArgumentForVariadicFunctionException::class);
+        $this->expectExceptionMessage($expectedMessage);
+
+        $this->buildEntityManager()->createQuery($dql)->getSQL();
+    }
    #[DataProvider('invalidArgumentCountProvider')]
    public static function invalidArgumentCountProvider(): array
    {
        return [
            'too few' => [
                \sprintf('SELECT JSONB_PATH_MATCH(e.object1) FROM %s e', ContainsJsons::class),
                'jsonb_path_match() requires at least 2 arguments',
            ],
            'too many' => [
                \sprintf("SELECT JSONB_PATH_MATCH(e.object1, '$.items[*].id', '{\"strict\": false}', 'true', 'extra_arg') FROM %s e", ContainsJsons::class),
                'jsonb_path_match() requires between 2 and 4 arguments',
            ],
        ];
    }

(Suggest also adding use PHPUnit\Framework\Attributes\DataProvider; at the top.)

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 3, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 3, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 3, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 3, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 3, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 3, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 3, 2025
@martin-georgiev martin-georgiev merged commit 9495e98 into main Aug 3, 2025
54 of 55 checks passed
@martin-georgiev martin-georgiev deleted the more-tests branch August 3, 2025 22:13
@coveralls
Copy link

Coverage Status

coverage: 94.298%. remained the same
when pulling ba7081b on more-tests
into 143c6a8 on main.

@coveralls
Copy link

Coverage Status

coverage: 94.298%. remained the same
when pulling d149bb6 on more-tests
into 143c6a8 on main.

@coveralls
Copy link

coveralls commented Aug 4, 2025

Coverage Status

coverage: 94.671% (+0.4%) from 94.298%
when pulling 21dc61a on more-tests
into 143c6a8 on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants