Skip to content

Conversation

@ccurdt
Copy link

@ccurdt ccurdt commented Jul 9, 2025

Patch Summary

This patch improves the value comparison logic in Doctrine’s UnitOfWork class during change detection.

Key Changes

  • Introduces a private method valuesAreEqual() that compares values with special handling for:

    • null values,
    • DateTimeInterface instances using the spaceship operator (<=>),
    • arrays recursively, checking keys and values,
    • and falls back to strict comparison (===) for other types.
  • Replaces existing strict equality checks with valuesAreEqual() to prevent false positives.

Benefit

Enhances reliability in detecting changes for entities with DateTime and array fields.

ccurdt added 2 commits July 9, 2025 11:17
- Introduced a new private method `valuesAreEqual` in UnitOfWork to perform value comparisons.
- This method correctly compares null values, DateTimeInterface instances (using the spaceship operator),
  and arrays recursively to ensure deep equality.
- Replaced existing strict equality checks (===) with `valuesAreEqual` in change detection logic.
- Added recursive array comparison method `arraysAreEqual` to verify keys and values match exactly.
- These changes prevent false positives in Doctrine change tracking caused by naive comparisons.
- Improves accuracy and stability in detecting entity changes, especially for date and array fields.
@gseidel
Copy link
Contributor

gseidel commented Aug 21, 2025

May you provide some test, where the uow doesn't detect changes or it detect changes that aren't changes and that are covered by your code now?

@github-actions
Copy link
Contributor

There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
If you want to continue working on it, please leave a comment.

@github-actions github-actions bot added the Stale label Nov 20, 2025
…fWork

Introduces a complete set of tests validating the new valuesAreEqual() and 
arraysAreEqual() methods in UnitOfWork. These tests cover all relevant cases 
including null handling, primitive strict comparison, object identity, nested 
arrays, key and order sensitivity, and DateTime comparisons (including 
cross-timezone equality).

The tests use reflection to access the private comparison methods and ensure 
the new deep-equality logic behaves correctly and fixes previous false 
positives in change detection.

All tests are annotated with group tag doctrine#12066 for selective execution.
Resolve several PHP_CodeSniffer violations in UnitOfWorkTest to ensure
full coding-style compliance.

Changes include:
- Removed trailing whitespace on multiple test lines.
- Converted a multi-line single-content docblock to a one-line comment.
- Added missing native type hint `mixed ...$args` to invokePrivate().
- Removed unused import `DateTimeInterface`.
- Sorted use statements alphabetically according to project rules.

These adjustments address all PHPCS warnings and restore test suite
coding-standard conformity.
@github-actions github-actions bot removed the Stale label Nov 21, 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.

2 participants