diff --git a/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/ChangedTestItem.php b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/ChangedTestItem.php index 1425588..6238356 100644 --- a/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/ChangedTestItem.php +++ b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/ChangedTestItem.php @@ -33,6 +33,10 @@ public function preSave() { // Drupal\Core\Field\Plugin\Field\FieldType\ChangedItem::preSave() we need // to set a real time value here. $this->value = time(); + + // And we need to round microseconds to avoid a difference of 1 second at + // the boundary of second. + $this->value += round((float) explode(' ', microtime())[0]); } } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php index 66e1abb..dc1384b 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php @@ -78,7 +78,7 @@ public function testChanged() { // between the created time and now. $this->assertTrue( ($entity->getChangedTime() >= $entity->get('created')->value) && - (($entity->getChangedTime() - $entity->get('created')->value) <= time() - REQUEST_TIME), + (($entity->getChangedTime() - $entity->get('created')->value) <= $this->time() - REQUEST_TIME), 'Changed and created time of original language can be assumed to be identical.' ); @@ -306,7 +306,7 @@ public function testRevisionChanged() { // timestamp every time. $this->assertTrue( ($entity->getChangedTime() >= $entity->get('created')->value) && - (($entity->getChangedTime() - $entity->get('created')->value) <= time() - REQUEST_TIME), + (($entity->getChangedTime() - $entity->get('created')->value) <= $this->time() - REQUEST_TIME), 'Changed and created time of original language can be assumed to be identical.' ); @@ -561,4 +561,14 @@ protected function getRevisionTranslationAffectedFlag(EntityTestMulRevChanged $e return (bool) ($id == $entity->id()); } + /** + * The time value with round microseconds. + * + * @return int + * The time value with round microseconds. + */ + protected function time() { + return time() + round((float) explode(' ', microtime())[0]); + } + }