Skip to content

Conversation

@martin-georgiev
Copy link
Owner

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

Summary by CodeRabbit

  • New Features
    • Enhanced support for PostgreSQL CAST syntax, including array type casting (e.g., integer[], text[], decimal(10,2)[]).
  • Bug Fixes
    • Improved parsing logic to correctly handle array type casts and parameterized types.
  • Tests
    • Added comprehensive integration and unit tests covering various casting scenarios, including arrays, parameterized types, and error handling.

@coderabbitai
Copy link

coderabbitai bot commented Aug 3, 2025

Walkthrough

The changes enhance the PostgreSQL CAST function in Doctrine to support array type casts and parameterized types. A utility method is added for Doctrine Lexer version compatibility. Comprehensive integration and unit tests are introduced and expanded to verify array type casting, parameterized types, error handling, and SQL generation in various scenarios.

Changes

Cohort / File(s) Change Summary
CAST Function Array Type Parsing
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php
Enhanced the parse method to recognize and handle array type syntax ([]) in CAST expressions, allowing parsing of array casts.
Doctrine Lexer Utility
src/MartinGeorgiev/Utils/DoctrineLexer.php
Added static method getLookaheadValue to abstract lookahead token value retrieval for Doctrine Lexer versions pre- and post-2.0.0.
Integration Tests for CAST
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
Introduced a new integration test suite for the CAST function, covering array types, parameterized types, error cases, and edge cases.
Unit Tests for Array Casts
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
Expanded unit tests to cover SQL generation for array type casts, including integer, text, boolean, and decimal arrays.
PHPStan Baseline Update
ci/phpstan/baselines/lexer-variations.neon
Added a new ignored error pattern for deprecated T_NONE class constant in Doctrine Lexer to suppress static analysis warnings.

Sequence Diagram(s)

sequenceDiagram
    participant DQLUser as DQL User
    participant Doctrine as Doctrine ORM
    participant CastFunc as Cast Function Parser
    participant Lexer as Doctrine Lexer

    DQLUser->>Doctrine: Submit DQL with CAST(... AS type[])
    Doctrine->>CastFunc: Parse CAST expression
    CastFunc->>Lexer: Get next token
    CastFunc->>Lexer: Use getLookaheadValue()
    alt Array type detected
        CastFunc->>CastFunc: Parse '[' and ']' tokens
        CastFunc->>CastFunc: Append '[]' to type
    end
    CastFunc->>Doctrine: Return parsed CAST expression
    Doctrine->>DQLUser: Execute and return results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related PRs

Poem

A CAST of arrays hops into view,
With brackets parsed and types anew.
Lexer checks the tokens twice,
To make sure every cast is nice.
Tests abound, both big and small—
This rabbit’s work now covers all!
🐇✨


📜 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 8273d19 and b017002.

📒 Files selected for processing (2)
  • ci/phpstan/baselines/lexer-variations.neon (1 hunks)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • ci/phpstan/baselines/lexer-variations.neon
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch issue-399

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 (1)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php (1)

65-78: Array type parsing implementation is sound but consider edge case handling.

The implementation correctly uses lookahead to detect square brackets and appends '[]' to the type string. The approach is necessary since brackets aren't tokenized separately.

However, consider what happens if only an opening bracket is found without a closing bracket. The current implementation will consume the '[' but not append '[]' to the type, which might lead to confusing behavior.

Consider adding explicit error handling for malformed bracket syntax:

 // Handle array types by checking if the next token is '['
 // Since brackets are not recognized as specific tokens, we need to check the token value
 $nextTokenValue = DoctrineLexer::getLookaheadValue($lexer);
 if ($nextTokenValue === '[') {
     // Consume the '[' token
     $parser->match($shouldUseLexer ? Lexer::T_NONE : TokenType::T_NONE);

     // Check for the closing ']' token
     $nextTokenValue = DoctrineLexer::getLookaheadValue($lexer);
     if ($nextTokenValue === ']') {
         $parser->match($shouldUseLexer ? Lexer::T_NONE : TokenType::T_NONE);
         $type .= '[]';
+    } else {
+        throw new \InvalidArgumentException('Expected closing bracket \']\' for array type syntax');
     }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9495e98 and 6d3712a.

📒 Files selected for processing (4)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php (2 hunks)
  • src/MartinGeorgiev/Utils/DoctrineLexer.php (1 hunks)
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php (2 hunks)
🧰 Additional context used
🧠 Learnings (17)
📓 Common learnings
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#366
File: tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPositionsTest.php:1-36
Timestamp: 2025-05-03T00:18:09.078Z
Learning: Always check the current official PostgreSQL documentation at https://www.postgresql.org/docs/ to verify function signatures and behaviors before suggesting improvements or additional tests. The `array_positions` function specifically has a fixed signature with exactly two parameters (array and search value), while `array_position` is variadic with 2-3 parameters.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#366
File: tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPositionsTest.php:1-36
Timestamp: 2025-05-03T00:18:09.078Z
Learning: Always check the current official PostgreSQL documentation at https://www.postgresql.org/docs/ to verify function signatures and behaviors before suggesting improvements or additional tests. The `array_positions` function specifically has a fixed signature with exactly two parameters (array and search value), while `array_position` is variadic with 2-3 parameters.
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#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#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#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.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#0
File: :0-0
Timestamp: 2025-03-26T02:46:12.804Z
Learning: The PR "preserve the type of floats and integers when transforming back and forth between PostgreSQL and PHP" improves type handling by ensuring that integers remain integers, floats remain floats, numeric strings stay as strings, and booleans are properly converted through the transformation process.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#0
File: :0-0
Timestamp: 2025-03-11T17:02:51.971Z
Learning: The PostgreSQL-for-doctrine library implements the JSON array element existence check using the `RIGHT_EXISTS_ON_LEFT` DQL function, which maps to PostgreSQL's `?` operator. This is used for checking if a specific value exists in a JSONB array column.
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: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#277
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonValueTest.php:19-35
Timestamp: 2025-03-13T15:00:16.619Z
Learning: The JsonValue implementation in postgres-for-doctrine has documented limitations: it does not support RETURNING type, DEFAULT clause, ON ERROR clause, ON EMPTY clause, and other advanced PostgreSQL JSON_VALUE features due to DQL limitations.
📚 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:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.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:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.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:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.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/CastTest.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.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/CastTest.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.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:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.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/CastTest.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
📚 Learning: the pr "preserve the type of floats and integers when transforming back and forth between postgresql...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#0
File: :0-0
Timestamp: 2025-03-26T02:46:12.804Z
Learning: The PR "preserve the type of floats and integers when transforming back and forth between PostgreSQL and PHP" improves type handling by ensuring that integers remain integers, floats remain floats, numeric strings stay as strings, and booleans are properly converted through the transformation process.

Applied to files:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.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:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
📚 Learning: the postgresql-for-doctrine library implements the json array element existence check using the `rig...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#0
File: :0-0
Timestamp: 2025-03-11T17:02:51.971Z
Learning: The PostgreSQL-for-doctrine library implements the JSON array element existence check using the `RIGHT_EXISTS_ON_LEFT` DQL function, which maps to PostgreSQL's `?` operator. This is used for checking if a specific value exists in a JSONB array column.

Applied to files:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
📚 Learning: in postgresql text arrays, backslashes must be escaped with triple backslashes. a single backslash i...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#304
File: src/MartinGeorgiev/Utils/DataStructure.php:152-168
Timestamp: 2025-03-25T01:23:29.749Z
Learning: In PostgreSQL text arrays, backslashes must be escaped with triple backslashes. A single backslash in PHP like 'path\to\file' becomes "path\\\to\\\file" in PostgreSQL format.

Applied to files:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
📚 Learning: when using operator-like functions in postgresql-for-doctrine, they must be used as boolean function...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#0
File: :0-0
Timestamp: 2025-03-11T17:02:51.971Z
Learning: When using operator-like functions in PostgreSQL-for-doctrine, they must be used as boolean functions with `= TRUE` rather than as direct operators (e.g., `RIGHT_EXISTS_ON_LEFT(column, value) = TRUE` instead of `column RIGHT_EXISTS_ON_LEFT value`).

Applied to files:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
📚 Learning: always check the current official postgresql documentation at https://www.postgresql.org/docs/ to ve...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#366
File: tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPositionsTest.php:1-36
Timestamp: 2025-05-03T00:18:09.078Z
Learning: Always check the current official PostgreSQL documentation at https://www.postgresql.org/docs/ to verify function signatures and behaviors before suggesting improvements or additional tests. The `array_positions` function specifically has a fixed signature with exactly two parameters (array and search value), while `array_position` is variadic with 2-3 parameters.

Applied to files:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php
📚 Learning: the jsonvalue implementation in postgres-for-doctrine has documented limitations: it does not suppor...
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#277
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonValueTest.php:19-35
Timestamp: 2025-03-13T15:00:16.619Z
Learning: The JsonValue implementation in postgres-for-doctrine has documented limitations: it does not support RETURNING type, DEFAULT clause, ON ERROR clause, ON EMPTY clause, and other advanced PostgreSQL JSON_VALUE features due to DQL limitations.

Applied to files:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
📚 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:

  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.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/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php
🔇 Additional comments (10)
src/MartinGeorgiev/Utils/DoctrineLexer.php (1)

40-52: LGTM! Version compatibility utility method implemented correctly.

The getLookaheadValue method follows the established pattern of other utility methods in this class, correctly handling the differences between Doctrine Lexer versions. The use of null coalescing operator for pre-2.0.0 versions and nullable property access for 2.0.0+ versions is appropriate.

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

28-31: Comprehensive array type test coverage added.

The new test cases properly cover casting to various array types including integer[], text[], boolean[], and parameterized decimal arrays. The expected SQL generation correctly includes PostgreSQL array syntax with square brackets.


44-47: DQL statements correctly mirror the array syntax.

The DQL statements properly include the array type syntax with square brackets, ensuring the parser can handle the new array casting functionality.

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php (1)

48-48: Good documentation of parameterized type handling.

The comment clearly explains the purpose of the parameterized type handling section.

tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/CastTest.php (6)

14-20: Well-structured test setup with comprehensive fixture creation.

The setUp method properly creates all necessary test tables for different data types, ensuring comprehensive test coverage.


57-71: Array casting tests properly validate PostgreSQL array behavior.

The tests correctly expect string results for array operations, which aligns with how PostgreSQL returns array representations in result sets. The assertions using assertStringContainsString for checking array format markers are appropriate.


91-91: Accurate comment about PostgreSQL rounding behavior.

The comment correctly notes that PostgreSQL rounds 10.5 to 11, demonstrating good understanding of PostgreSQL's rounding behavior in CAST operations.


101-113: Proper error handling validation for edge cases.

The tests appropriately validate error scenarios for invalid types and null inputs, ensuring robust error handling.


115-137: Excellent coverage of case sensitivity and parameterized array types.

The tests verify that array type names are handled case-insensitively and that parameterized types work correctly with array syntax (e.g., DECIMAL(10, 2)[]). This ensures the parser is robust and flexible.


139-219: Comprehensive test data setup with proper PostgreSQL syntax.

The table creation and data insertion methods use proper PostgreSQL syntax and create realistic test scenarios for all casting operations. The data choices are appropriate for testing various casting behaviors.

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 changed the title feat(#399): support array types for CAST fix(#399): support array types for CAST Aug 3, 2025
@martin-georgiev martin-georgiev merged commit 465963e into main Aug 3, 2025
54 of 55 checks passed
@martin-georgiev martin-georgiev deleted the issue-399 branch August 3, 2025 22:59
@github-actions github-actions bot mentioned this pull request Aug 3, 2025
@coveralls
Copy link

Coverage Status

coverage: 94.65% (-0.02%) from 94.671%
when pulling b017002 on issue-399
into 9495e98 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