FIx TODO in Drupal\entity_test\Plugin\Field\FieldType\ChangedTestItem

Created on 12 September 2017, over 7 years ago
Updated 21 February 2024, 10 months ago

Problem/Motivation

There's following TODO in the code

  public function preSave() {
    parent::preSave();

    if ($this->value == \Drupal::time()->getRequestTime()) {
      // During a test the request time is immutable. To allow tests of the
      // algorithm of
      // Drupal\Core\Field\Plugin\Field\FieldType\ChangedItem::preSave() we need
      // to set a real time value here. For the stability of the test, set the
      // time of the original language to the current time plus just over one
      // second to simulate two different request times.
      // @todo mock the time service in https://www.drupal.org/node/2908210.
      if ($this->getEntity()->language()->isDefault()) {
        // Wait 1.1 seconds because time_sleep_until() is not reliable.
        time_sleep_until(time() + 1.1);
      }
      $this->value = time();
    }
  }

Proposed resolution

Use the time service rather than time_sleep_until().

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

11.0 🔥

Component
PHPUnit 

Last updated about 4 hours ago

Created by

🇬🇧United Kingdom jofitz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024