Skip to content

feat: add support for formatting functions to_char, to_date, to_number, to_timestamp #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

karpilin
Copy link
Contributor

@karpilin karpilin commented May 23, 2025

This pull request adds support for PostgreSQL data type formatting functions (to_char, to_date, to_number, and to_timestamp) in the Doctrine ORM library. The changes include new function implementations, updates to documentation, and corresponding unit and integration tests.

New Functionality: Data Type Formatting Functions

  • Added implementations for PostgreSQL functions to_char, to_date, to_number, and to_timestamp in the src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions directory. These classes extend BaseFunction and define the function prototypes and node mappings.

Documentation Updates

  • Updated README.md to include "Data Type Formatting Functions" as a new category of supported features.
  • Added entries for the new functions in docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md.
  • Updated integration guides for Doctrine, Laravel, and Symfony to include configuration examples for the new functions.

Testing

  • Added unit tests for each new function to validate SQL generation.
  • Added integration tests to verify the new functions' behaviour with actual database queries.

Summary by CodeRabbit

  • New Features

    • Added support for four new PostgreSQL data type formatting functions: TO_CHAR, TO_DATE, TO_NUMBER, and TO_TIMESTAMP, enabling advanced formatting and conversion in queries.
  • Documentation

    • Updated documentation to include details and integration examples for the new data type formatting functions across various frameworks (Doctrine, Laravel, Symfony).
  • Tests

    • Added comprehensive unit and integration tests to ensure correct behavior and error handling of the new formatting functions.

Copy link

coderabbitai bot commented May 23, 2025

Walkthrough

This update introduces support for PostgreSQL data type formatting functions (to_char, to_date, to_number, to_timestamp) in the Doctrine ORM query language. It adds new function classes, updates integration and feature documentation, and provides both unit and integration tests to verify the correct behavior and registration of these functions. Additionally, a new dateinterval1 property was added to the ContainsDates entity, and test fixtures were updated accordingly.

Changes

File(s) Change Summary
README.md Added "Data Type Formatting Functions" to the list of supported PostgreSQL functions in documentation.
docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md Listed to_char, to_date, to_number, to_timestamp as available DQL functions with class mappings.
docs/INTEGRATING-WITH-DOCTRINE.md
docs/INTEGRATING-WITH-LARAVEL.md
docs/INTEGRATING-WITH-SYMFONY.md
Updated integration guides to show registration of new data type formatting functions in Doctrine config.
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToChar.php
ToDate.php
ToNumber.php
ToTimestamp.php
Added new classes implementing DQL support for PostgreSQL formatting functions, each accepting two string args.
fixtures/MartinGeorgiev/Doctrine/Entity/ContainsDates.php Added new dateinterval1 property of type DATEINTERVAL to entity ContainsDates.
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateTestCase.php Updated test fixture schema and data to include dateinterval1 INTERVAL column and value.
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php
ToDateTest.php
ToNumberTest.php
ToTimestampTest.php
Added integration tests for each new function, verifying DQL-to-SQL translation, result correctness, and error handling.
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php
ToDateTest.php
ToNumberTest.php
ToTimestampTest.php
Added unit tests mapping DQL to expected SQL for each new data type formatting function and testing missing argument errors.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DoctrineORM
    participant DQLParser
    participant ToChar/ToDate/ToNumber/ToTimestamp
    participant PostgreSQL

    User->>DoctrineORM: Write DQL query using TO_CHAR/TO_DATE/TO_NUMBER/TO_TIMESTAMP
    DoctrineORM->>DQLParser: Parse DQL query
    DQLParser->>ToChar/ToDate/ToNumber/ToTimestamp: Map DQL function to SQL function
    ToChar/ToDate/ToNumber/ToTimestamp->>PostgreSQL: Execute SQL function (to_char, to_date, etc.)
    PostgreSQL-->>ToChar/ToDate/ToNumber/ToTimestamp: Return formatted result
    ToChar/ToDate/ToNumber/ToTimestamp-->>DoctrineORM: Return result
    DoctrineORM-->>User: Provide query result
Loading

Suggested labels

enhancement, dx

Poem

In the meadow of code, new functions appear,
Formatting data with PostgreSQL cheer!
From char to date, and number to time,
Doctrine now parses them all just fine.
With tests that hop and docs that bloom,
This update brings formatting magic to every room!

((\
( -.-)
o_(")(") — Hoppy coding!


📜 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 066acda and 93b5f8b.

📒 Files selected for processing (5)
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumberTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumberTest.php
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch DataTypeFormattingFunctions
  • Post Copyable Unit Tests in Comment

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 auto-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.

coderabbitai[bot]
coderabbitai bot previously approved these changes May 23, 2025
@martin-georgiev
Copy link
Owner

@coderabbitai, what test scenarios (integration or unit) may be missing here?

Copy link

coderabbitai bot commented May 23, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@martin-georgiev Let me analyze the current test coverage to identify potential gaps.

Based on my analysis of the current test coverage, here are the potentially missing test scenarios:

Missing Unit Test Scenarios:

  1. Error Handling Tests:

    • Invalid format strings (malformed patterns)
    • Null input values
    • Empty string inputs
    • Unsupported format characters
  2. Complex Format Patterns:

    • TO_CHAR with currency symbols, Roman numerals (RN, rn)
    • TO_DATE/TO_TIMESTAMP with timezone specifiers (TZ, OF)
    • TO_NUMBER with scientific notation patterns (EEEE)
    • Escaped format characters and literal text in patterns
  3. Multiple Functions in Single Query:

    • Combining different formatting functions
    • Nested function calls (e.g., TO_CHAR(TO_DATE(...), ...))

Missing Integration Test Scenarios:

  1. Edge Cases:

    • Very large numbers with TO_NUMBER
    • Date boundaries (leap years, month transitions)
    • Locale-specific formatting differences
    • Unicode characters in format strings
  2. Real-world Use Cases:

    • Financial reporting formats (currency, accounting)
    • Internationalization scenarios
    • Data migration/transformation patterns
  3. Performance Scenarios:

    • Long format strings
    • Large datasets
    • Complex nested queries

Recommended Additional Tests:

// Example missing test scenarios:

// Error handling
'SELECT TO_DATE(c.text1, \'\') FROM ContainsTexts c'  // Empty format
'SELECT TO_CHAR(null, \'DD/MM/YYYY\') FROM ContainsDates c'  // Null input

// Complex patterns  
'SELECT TO_CHAR(123456.789, \'$999G999D00\') FROM ContainsTexts c'  // Currency
'SELECT TO_DATE(\'2023-12-31\', \'YYYY-MM-DD\') FROM ContainsTexts c'  // ISO format

// Multiple functions
'SELECT TO_CHAR(TO_DATE(c.text1, \'DD Mon YYYY\'), \'YYYY-MM-DD\') FROM ContainsTexts c'

The current test coverage provides a solid foundation, but adding these scenarios would significantly improve robustness and real-world applicability.


🏁 Script executed:

#!/bin/bash
# First, let's examine the current test files to understand what's being tested
echo "=== Unit Test Coverage ==="
for file in tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/To*.php; do
    echo "--- $(basename "$file") ---"
    cat "$file"
    echo
done

Length of output: 12944


🏁 Script executed:

#!/bin/bash
echo "=== Integration Test Coverage ==="
for file in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/To*.php; do
    echo "--- $(basename "$file") ---"
    cat "$file"
    echo
done

Length of output: 4125


🏁 Script executed:

#!/bin/bash
# Let's also examine existing test patterns for error handling in similar functions
echo "=== Examining existing error handling patterns ==="
find tests -name "*.php" -exec grep -l "invalid\|error\|exception\|null" {} \; | head -5 | xargs cat

Length of output: 17415


🏁 Script executed:

#!/bin/bash
# Check if there are any existing tests that use multiple functions together
echo "=== Checking for multi-function usage patterns ==="
grep -r "TO_" tests/ | grep -v "class\|function\|namespace" | head -10

Length of output: 1438


Based on my analysis of the current test coverage, here are the missing test scenarios that would significantly improve robustness:

Critical Missing Unit Test Scenarios:

1. Error Handling & Edge Cases:

// Currently missing - these should be added to unit tests
'SELECT TO_DATE(e.text1, \'\') FROM ContainsTexts e'           // Empty format string
'SELECT TO_CHAR(null, \'DD/MM/YYYY\') FROM ContainsDates e'   // Null input values  
'SELECT TO_NUMBER(e.text1, \'invalid\') FROM ContainsTexts e' // Invalid format patterns

2. Complex Format Patterns:

// Advanced TO_CHAR patterns not tested
'SELECT TO_CHAR(e.decimal1, \'$999G999D00\') FROM ContainsDecimals e'     // Currency symbols
'SELECT TO_CHAR(e.datetime1, \'Day, DD Month YYYY\') FROM ContainsDates e' // Full names
'SELECT TO_CHAR(123, \'RN\') FROM ContainsDates e'                         // Roman numerals

// Advanced TO_DATE/TO_TIMESTAMP patterns  
'SELECT TO_DATE(e.text1, \'YYYY-MM-DD HH24:MI:SS\') FROM ContainsTexts e' // ISO formats
'SELECT TO_TIMESTAMP(e.text1, \'DD/MM/YYYY HH24:MI:SS TZ\') FROM ContainsTexts e' // Timezone

// Advanced TO_NUMBER patterns
'SELECT TO_NUMBER(e.text1, \'9.99EEEE\') FROM ContainsTexts e'            // Scientific notation

3. Function Composition (Missing Entirely):

// Nested function calls - not tested anywhere
'SELECT TO_CHAR(TO_DATE(e.text1, \'DD Mon YYYY\'), \'YYYY-MM-DD\') FROM ContainsTexts e'
'SELECT TO_NUMBER(TO_CHAR(e.decimal1, \'999D99\'), \'999D99\') FROM ContainsDecimals e'
'SELECT TO_CHAR(UPPER(e.text1), \'DD Mon YYYY\') FROM ContainsTexts e'

Critical Missing Integration Test Scenarios:

1. Real-world Edge Cases:

// Date boundaries and special cases
$dql = "SELECT to_date('29 Feb 2024', 'DD Mon YYYY') as result FROM ..."; // Leap year
$dql = "SELECT to_timestamp('31 Dec 2023 23:59:59', 'DD Mon YYYY HH24:MI:SS') as result FROM ..."; // Year boundary

// Large numbers and precision
$dql = "SELECT to_number('999999999.999999', '999999999D999999') as result FROM ..."; // Precision limits
$dql = "SELECT to_char(-999999.99, 'S999G999D99') as result FROM ..."; // Negative large numbers

2. Error Handling Integration Tests:

// These should test actual PostgreSQL error behavior
public function test_todate_with_invalid_format(): void
{
    $this->expectException(\Doctrine\DBAL\Exception::class);
    $dql = "SELECT to_date('invalid', 'invalid_format') FROM ContainsJsons t WHERE t.id = 1";
    $this->executeDqlQuery($dql);
}

3. Null Handling:

// Currently not tested - PostgreSQL behavior with nulls
$dql = "SELECT to_char(null, 'DD/MM/YYYY') as result FROM ContainsJsons t WHERE t.id = 1";
// Should expect null result

Pattern Comparison with Existing Functions:

Looking at ToTsqueryTest and ToTsvectorTest, they have significantly better coverage:

  • ✅ Multiple test cases per function
  • ✅ Exception testing for invalid arguments
  • ✅ Nested function calls (UPPER(e.text1))
  • ✅ Different argument patterns

The new formatting functions should follow this same comprehensive pattern.

Recommended Priority:

  1. High Priority: Add error handling integration tests
  2. High Priority: Add null value handling tests
  3. Medium Priority: Add complex format pattern tests
  4. Medium Priority: Add function composition tests
  5. Low Priority: Add boundary condition tests

The current coverage provides a solid foundation, but these additions would bring the new functions up to the same quality standard as the existing well-tested functions in the codebase.

@martin-georgiev
Copy link
Owner

martin-georgiev commented May 23, 2025

@karpilin CodeRabbit suggested some more test scenarios. Some of them are rather rubbish, but there are also valid points that can improve the quality :)

@coveralls
Copy link

coveralls commented May 23, 2025

Coverage Status

coverage: 94.37% (+0.05%) from 94.316%
when pulling 93b5f8b on karpilin:DataTypeFormattingFunctions
into 5541f7f on martin-georgiev:main.

@martin-georgiev martin-georgiev changed the title feat: add support for formatting functions 'to_char', 'to_date', 'to_number', 'to_timestamp' feat: add support for formatting functions to_char, to_date, to_number, to_timestamp May 23, 2025
Adds more comprehensive tests for the `to_char` function, covering various data types and formats.
This ensures the function correctly handles different scenarios, including numeric, timestamp, and interval types, and validates its behavior with valid and invalid inputs.
Also adds tests for to_timestamp, to_date and to_number to check invalid inputs and formats
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: 1

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

39-45: LGTM! Essential error handling validation.

The exception test properly validates that the TO_CHAR function requires a format argument, which is critical for function correctness.

Based on the PR objectives discussion about test coverage gaps, you might consider adding optional tests for:

  • Invalid format strings (e.g., unsupported format characters)
  • Complex format patterns (e.g., currency symbols, Roman numerals)
  • Null input handling
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c533b42 and 739c919.

📒 Files selected for processing (11)
  • fixtures/MartinGeorgiev/Doctrine/Entity/ContainsDates.php (1 hunks)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToChar.php (1 hunks)
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateTestCase.php (2 hunks)
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (1 hunks)
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php (1 hunks)
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumberTest.php (1 hunks)
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumberTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToChar.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumberTest.php
🧰 Additional context used
🧠 Learnings (4)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php (3)
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.926Z
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.
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (3)
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.926Z
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.
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php (1)
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.926Z
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.
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php (3)
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.926Z
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.
🧬 Code Graph Analysis (5)
fixtures/MartinGeorgiev/Doctrine/Entity/ContainsDates.php (1)
fixtures/MartinGeorgiev/Doctrine/Entity/Entity.php (1)
  • ORM (10-17)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumberTest.php (4)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumber.php (1)
  • ToNumber (12-20)
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumberTest.php (2)
  • ToNumberTest (11-41)
  • getStringFunctions (13-18)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TextTestCase.php (1)
  • TextTestCase (9-48)
tests/Integration/MartinGeorgiev/TestCase.php (1)
  • executeDqlQuery (236-250)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php (4)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestamp.php (1)
  • ToTimestamp (12-20)
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php (2)
  • ToTimestampTest (11-41)
  • getStringFunctions (13-18)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TextTestCase.php (1)
  • TextTestCase (9-48)
tests/Integration/MartinGeorgiev/TestCase.php (1)
  • executeDqlQuery (236-250)
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (3)
fixtures/MartinGeorgiev/Doctrine/Entity/ContainsDates.php (1)
  • ORM (10-33)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToChar.php (1)
  • ToChar (12-20)
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TestCase.php (1)
  • buildEntityManager (115-118)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php (4)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDate.php (1)
  • ToDate (12-20)
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php (2)
  • ToDateTest (11-41)
  • getStringFunctions (13-18)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TextTestCase.php (1)
  • TextTestCase (9-48)
tests/Integration/MartinGeorgiev/TestCase.php (1)
  • executeDqlQuery (236-250)
🔇 Additional comments (22)
fixtures/MartinGeorgiev/Doctrine/Entity/ContainsDates.php (1)

31-32:

❓ Verification inconclusive

Verify the property type mapping for INTERVAL columns.

The dateinterval1 property is typed as \DateTimeImmutable but annotated with Types::DATEINTERVAL. PostgreSQL INTERVAL type represents duration/period (like '15h 2m 12s'), which semantically should map to PHP's \DateInterval class, not \DateTimeImmutable (which represents a point in time).

Please verify this type mapping is correct and functional:


🏁 Script executed:

#!/bin/bash
# Verify how Types::DATEINTERVAL is handled in Doctrine DBAL
rg -A 10 -B 5 "DATEINTERVAL.*=.*" --type php
rg -A 10 -B 5 "class.*DateIntervalType" --type php

Length of output: 99


🏁 Script executed:

#!/bin/bash
# Search for the DATEINTERVAL constant definition in Doctrine DBAL
rg "const\s\+DATEINTERVAL" -n

# Search for the DateIntervalType class in the repository (including vendor)
rg "class\s\+DateIntervalType" -n

Length of output: 67


Verify Doctrine DBAL’s DATEINTERVAL mapping

I wasn’t able to locate any Types::DATEINTERVAL constant or DateIntervalType class in the checked codebase—likely because these live in your installed Doctrine DBAL dependency. Please confirm that in your DBAL version:

Types::DATEINTERVAL is defined in
vendor/doctrine/dbal/src/Types/Types.php
• It maps to a DateIntervalType (in
vendor/doctrine/dbal/src/Types/DateIntervalType.php)
whose PHP class handling uses \DateInterval and not \DateTimeImmutable.

If the mapping indeed uses \DateInterval, you’ll need to change your entity property to:

#[ORM\Column(type: Types::DATEINTERVAL)]
public \DateInterval $dateinterval1;

Otherwise, you’re risking a semantic mismatch between DB durations and PHP point-in-time objects.

tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateTestCase.php (2)

36-37: LGTM! Proper PostgreSQL INTERVAL column addition.

The schema update correctly adds the dateinterval1 column with PostgreSQL's INTERVAL type, which aligns with the entity property addition.


47-48: LGTM! Valid interval test data.

The INSERT statement correctly includes the interval value '15h 2m 12s' which is valid PostgreSQL interval syntax and provides good test data for the formatting functions.

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

1-11: LGTM! Proper imports and namespace setup.

The file header, imports, and namespace declaration follow the established patterns for unit tests in this codebase.


12-19: LGTM! Correct function registration pattern.

The getStringFunctions() method properly registers the TO_CHAR function following the established pattern used by other function tests in this codebase.


21-37: LGTM! Comprehensive DQL-to-SQL mapping tests.

The test cases cover different data types (datetime, interval, decimal) with appropriate PostgreSQL to_char format strings. The DQL statements correctly map to the expected SQL output.

tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumberTest.php (4)

11-18: LGTM! Function registration follows established pattern.

The function registration correctly maps the DQL function name to the implementation class, consistent with other formatting function tests.


20-25: LGTM! Basic functionality test is well-structured.

The test correctly validates the PostgreSQL to_number function with a properly formatted input string and verifies the expected numeric conversion result.


34-46: Error handling tests are comprehensive for type validation.

Both tests correctly validate that the function properly handles wrong argument types (null format and numeric input) by expecting QueryException, which is appropriate for DQL validation errors.


27-32:

❓ Verification inconclusive

Inconsistent error handling compared to other formatting functions.

This test expects a generic Exception for invalid format strings, while ToDateTest and ToTimestampTest don't expect exceptions for invalid formats at all. This inconsistency suggests different PostgreSQL behavior or testing approaches that should be aligned.

Verify PostgreSQL's actual behavior with invalid format strings across all formatting functions:


🏁 Script executed:

#!/bin/bash
# Test PostgreSQL behavior with invalid format strings for all formatting functions

# Create a temporary SQL file to test each function
cat > test_invalid_formats.sql << 'EOF'
\echo 'Testing TO_NUMBER with invalid format:'
SELECT to_number('12,454.8-', 'invalid_format');

\echo 'Testing TO_DATE with invalid format:'
SELECT to_date('05 Dec 2000', 'invalid_format');

\echo 'Testing TO_TIMESTAMP with invalid format:'
SELECT to_timestamp('05 Dec 2000', 'invalid_format');
EOF

echo "Execute this SQL against a PostgreSQL database to verify consistent error behavior:"
cat test_invalid_formats.sql

Length of output: 509


🌐 Web query:

PostgreSQL behavior of to_number, to_date, and to_timestamp functions when provided an invalid format string

💡 Result:

PostgreSQL's formatting functions to_number, to_date, and to_timestamp exhibit specific behaviors when facing invalid format strings or inputs that don't match the expected format. Understanding these behaviors is crucial for effective data conversion and error handling.

to_number Function Behavior

The to_number function converts string inputs to numeric values based on a specified format template. When encountering invalid formats or mismatches:

Format Mismatches

When the input string doesn't match the format template exactly, PostgreSQL may:

  1. Skip digits if separators in the format aren't present in the input. For example, to_number('34,50','999,99') returns 3450 because PostgreSQL ignores the separators[8].

  2. Return an error when the input string contains characters that can't be parsed according to the format. For instance, to_number cannot convert spaces or alphabets that aren't part of a recognized format pattern[9].

  3. Skip non-data characters in the input string when non-data template patterns (like L or TH) are used. For example, the TH pattern would skip two non-data characters in the input string[1].

Format String Restrictions

The format string in to_number has several constraints:

  • It cannot be an empty string ('')[4].
  • The input string must be shorter than or equal to the format string. For example, to_number('123','99') will return an error because the input has three digits but the format specifies only two[4].
  • Special format patterns like EEEE must be the last pattern used in the format string[3].

to_date and to_timestamp Functions Behavior

These functions convert strings to date/time values based on specified formats.

Whitespace Handling

By default, these functions are flexible with whitespace:

  • They skip multiple blank spaces at the beginning of the input string and around date/time values[1].
  • For example, to_timestamp(' 2000 JUN', 'YYYY MON') works despite the leading space[1].
  • However, when the FX option is used as the first item in the template, exact matching is enforced. For instance, to_timestamp('2000 JUN', 'FXYYYY MON') returns an error because it expects only a single space[1].

Separator Handling

The functions have specific rules for handling separators:

  • A separator in the template matches any single separator in the input or can be skipped[1].
  • For example, both to_timestamp('2000JUN', 'YYYY///MON') and to_timestamp('2000/JUN', 'YYYY MON') work correctly[1].
  • If the number of separators in the input exceeds those in the template, an error occurs. For example, to_timestamp('2000//JUN', 'YYYY/MON') returns an error[1].
  • With the FX option, a separator in the template must match exactly one character in the input, though it doesn't need to be the same character[1].

Format String Issues

Specific issues can occur with format strings:

  • When the format string has more whitespaces compared to the input string, unexpected results can occur[7].
  • For example, SELECT TO_TIMESTAMP('2016-06-13 15:43:36', 'YYYY/MM/DD HH24:MI:SS') can produce incorrect time values[7].
  • Time zone formats (TZ, tz, or OF) are not supported as input in the to_timestamp function[10].

Out-of-Range Values

For to_timestamp, there's an optional parameter to control error handling:

  • The is_strict parameter (when set to TRUE) causes the function to return an error if there are out-of-range values[10].
  • By default (is_strict is FALSE), overflow values are accepted, potentially producing unexpected results[10].
  • For example, TO_TIMESTAMP('2011-12-18 24:38:15', 'YYYY-MM-DD HH24:MI:SS') returns a timestamp for the next day due to hours exceeding 24, but with is_strict set to TRUE, it would return an error[10].

Understanding these behaviors helps in writing robust code that handles data conversion edge cases appropriately in PostgreSQL applications.

Citations:


Ensure consistent exception expectations for invalid format strings

Based on PostgreSQL’s formatting-function behavior, an invalid format template will result in a runtime error for all three conversion functions. We should therefore align the tests so that ToDateTest and ToTimestampTest also expect an exception when given an invalid format.

• In tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php, wrap the invalid‐format case with:

$this->expectException(Exception::class);

• In tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php, do the same for its invalid‐format scenario.

Please confirm by running these queries in your PostgreSQL environment and then update the two tests accordingly:

SELECT to_number('12,454.8-','invalid_format');
SELECT to_date('05 Dec 2000','invalid_format');
SELECT to_timestamp('05 Dec 2000','invalid_format');
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php (5)

11-18: LGTM! Function registration follows established pattern.

The function registration correctly maps the DQL function name to the implementation class.


20-25: LGTM! Basic functionality test validates correct date conversion.

The test correctly validates PostgreSQL's to_date function converting a formatted date string to ISO date format.


27-32: Appropriate exception handling for invalid date input.

Correctly expects DriverException when PostgreSQL cannot parse the date string, which is the appropriate exception type for database-level errors.


34-39: Verify PostgreSQL's behavior with invalid format strings.

This test doesn't expect an exception for invalid format strings and asserts a specific fallback result ('2005-01-01'). This differs from ToNumberTest which expects an exception. This inconsistency needs verification against actual PostgreSQL behavior.

The behavior differs from ToNumberTest.php line 29 which expects an exception for invalid formats. Please verify if this reflects actual PostgreSQL behavior or if the tests should be consistent.


41-53: Error handling tests are comprehensive for type validation.

Both tests correctly validate that the function handles wrong argument types by expecting QueryException, which is appropriate for DQL validation errors.

tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php (4)

11-18: LGTM! Function registration follows established pattern.

The function registration correctly maps the DQL function name to the implementation class.


20-25: Excellent test with complex format pattern.

The test uses a comprehensive format string that includes various PostgreSQL format elements (DD Mon YYYY tt HH24:MI ttt SS ttttttt), providing good coverage of the function's formatting capabilities.


27-32: Appropriate exception handling for invalid timestamp input.

Correctly expects DriverException when PostgreSQL cannot parse the timestamp string, consistent with ToDateTest.


41-53: Error handling tests are comprehensive for type validation.

Both tests correctly validate wrong argument types by expecting QueryException, consistent with other formatting function tests.

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

11-18: LGTM! Function registration follows established pattern.

The unit test correctly registers the TO_TIMESTAMP function for DQL-to-SQL conversion testing.


20-32: LGTM! SQL generation tests are properly structured.

The methods correctly define the expected SQL output and corresponding DQL input for validating the function's SQL generation, following the established unit test pattern in this codebase.


34-40: LGTM! Essential validation test for required parameters.

The test correctly validates that missing the required format parameter throws a QueryException, ensuring proper DQL validation. This aligns with the corresponding tests in other formatting function unit tests.

@karpilin
Copy link
Contributor Author

karpilin commented May 27, 2025

@martin-georgiev Let me know if there are more tests that you want me to add

@karpilin karpilin requested a review from martin-georgiev May 27, 2025 16:10
Copy link
Owner

@martin-georgiev martin-georgiev left a comment

Choose a reason for hiding this comment

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

Generally, if a test scenario is expected to throw, it is more readable and maintainable to reflect that in the method name. For example, JsonbBuildObjectTest::throws_exception_when_odd_number_of_arguments_given. Can you update this in the proposed test method names?

$this->executeDqlQuery($dql);
}

public function test_tochar_invalid_input(): void
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
public function test_tochar_invalid_input(): void
public function test_tochar_with_unsupported_null_input(): void

use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ToChar;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ToTimestamp;

class ToCharTest extends DateTestCase
Copy link
Owner

Choose a reason for hiding this comment

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

This is not a pure DateTestCase; It's better when you extend from Tests\Integration\MartinGeorgiev\TestCase and add entirely new data fixtures population for the date and numerical values that you propose in this test. Otherwise, this seems out of place and dirty.

$this->executeDqlQuery($dql);
}

public function test_todate_with_wrong_type_input(): void
Copy link
Owner

Choose a reason for hiding this comment

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

Similar comment about the null value and naming as in the other place.

Updates the documentation URL to reflect the latest PostgreSQL documentation (version 17).
Adds a `@since` tag to indicate the version in which these functions were introduced.

Minor corrections to tests
@karpilin karpilin requested a review from martin-georgiev May 29, 2025 09:11
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: 3

♻️ Duplicate comments (1)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (1)

86-86: Rename the method to better reflect what it tests.

The method name includes "unsupported" which might be misleading. Consider simplifying to test_tochar_with_null_input.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 739c919 and 800a8e6.

📒 Files selected for processing (12)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToChar.php (1 hunks)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDate.php (1 hunks)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumber.php (1 hunks)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestamp.php (1 hunks)
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (1 hunks)
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php (1 hunks)
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumberTest.php (1 hunks)
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumberTest.php (1 hunks)
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (11)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestamp.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumber.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDate.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToChar.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumberTest.php
  • tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToNumberTest.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestampTest.php
  • tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToDateTest.php
🧰 Additional context used
🧠 Learnings (1)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (2)
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.
🧬 Code Graph Analysis (1)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (5)
fixtures/MartinGeorgiev/Doctrine/Entity/ContainsDates.php (1)
  • ORM (10-33)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToChar.php (1)
  • ToChar (13-21)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTimestamp.php (1)
  • ToTimestamp (13-21)
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (2)
  • ToCharTest (13-48)
  • getStringFunctions (15-20)
tests/Integration/MartinGeorgiev/TestCase.php (3)
  • executeDqlQuery (236-250)
  • createTestSchema (149-154)
  • dropTestTableIfItExists (204-211)
🔇 Additional comments (7)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToCharTest.php (7)

15-28: LGTM!

The setup method properly initializes test data and the function registration is correct for the tests.


30-35: LGTM!

The test correctly validates timestamp formatting with the 12-hour format pattern.


37-42: LGTM!

The test properly validates interval formatting, correctly converting '15h 2m 12s' to '15:02:12'.


44-49: LGTM!

The test correctly validates numeric formatting with the sign indicator ('S') placing the minus sign at the end for negative values.


51-63: LGTM!

Both tests correctly validate numeric literal formatting, demonstrating how the 'S' format indicator displays '+' for positive and '-' for negative values at the end.


65-70: LGTM!

Excellent test case demonstrating function composition with to_char(to_timestamp(...)). This validates that the functions work correctly when nested.


93-123: LGTM!

The method properly creates a standalone test table with appropriate date/time columns and test data, following the integration test pattern.

@karpilin
Copy link
Contributor Author

@martin-georgiev I think I addressed all of the points here. Please let me know if I missed any or further tweaks are necessary.

coderabbitai[bot]
coderabbitai bot previously approved these changes May 29, 2025
@martin-georgiev martin-georgiev enabled auto-merge (squash) June 15, 2025 19:22
@martin-georgiev martin-georgiev merged commit 7a047e8 into martin-georgiev:main Jun 15, 2025
54 of 56 checks passed
@github-actions github-actions bot mentioned this pull request Jun 15, 2025
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