Skip to content

Fixes changeset being empty when datetime change is sub second #2676

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
merged 7 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/Doctrine/ODM/MongoDB/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Doctrine\Persistence\NotifyPropertyChanged;
use Doctrine\Persistence\PropertyChangedListener;
use InvalidArgumentException;
use MongoDB\BSON\UTCDateTime;

Check failure on line 27 in lib/Doctrine/ODM/MongoDB/UnitOfWork.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Type MongoDB\BSON\UTCDateTime is not used in this file.
use MongoDB\Driver\Exception\RuntimeException;
use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern;
Expand Down Expand Up @@ -835,10 +835,7 @@
$dbOrgValue = $dateType->convertToDatabaseValue($orgValue);
$dbActualValue = $dateType->convertToDatabaseValue($actualValue);

$orgTimestamp = $dbOrgValue instanceof UTCDateTime ? $dbOrgValue->toDateTime()->getTimestamp() : null;
$actualTimestamp = $dbActualValue instanceof UTCDateTime ? $dbActualValue->toDateTime()->getTimestamp() : null;

if ($orgTimestamp === $actualTimestamp) {
if ($dbOrgValue == $dbActualValue) {

Check failure on line 838 in lib/Doctrine/ODM/MongoDB/UnitOfWork.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Operator == is disallowed, use === instead.
continue;
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ public static function provideEquivalentDates(): array
];
}

public function testDateInstanceChangeWhenValueDifferenceIsSubSecond(): void
{
$user = new User();
$user->setCreatedAt(new UTCDateTime(100000000000));
$this->dm->persist($user);
$this->dm->flush();
$this->dm->clear();

$user = $this->dm->getRepository($user::class)->findOneBy([]);
$user->setCreatedAt(new UTCDateTime(100000000123));
$this->dm->getUnitOfWork()->computeChangeSets();
$changeset = $this->dm->getUnitOfWork()->getDocumentChangeSet($user);
self::assertNotEmpty($changeset);
}

public function testDateInstanceValueChangeDoesCauseUpdateIfValueIsTheSame(): void
{
$user = new User();
Expand Down
Loading