You are here

class SmsTestTime in SMS Framework 2.1.x

Same name and namespace in other branches
  1. 2.x tests/modules/sms_test_time/src/SmsTestTime.php \Drupal\sms_test_time\SmsTestTime

Time service with a predictable time.

Hierarchy

Expanded class hierarchy of SmsTestTime

1 string reference to 'SmsTestTime'
sms_test_time.services.yml in tests/modules/sms_test_time/sms_test_time.services.yml
tests/modules/sms_test_time/sms_test_time.services.yml
1 service uses SmsTestTime
sms_test_time.time in tests/modules/sms_test_time/sms_test_time.services.yml
Drupal\sms_test_time\SmsTestTime

File

tests/modules/sms_test_time/src/SmsTestTime.php, line 12

Namespace

Drupal\sms_test_time
View source
class SmsTestTime implements TimeInterface {

  /**
   * Original time service.
   *
   * @var \Drupal\Component\Datetime\TimeInterface
   */
  protected $original;

  /**
   * Date for testing.
   *
   * @var \DateTime
   */
  protected $date;

  /**
   * SmsTestTime constructor.
   *
   * @param \Drupal\Component\Datetime\TimeInterface $original
   *   Original time service.
   */
  public function __construct(TimeInterface $original) {
    $this->original = $original;
    $this->date = new \DateTimeImmutable('2:30pm 17 October 1997', new \DateTimeZone('UTC'));
  }

  /**
   * {@inheritdoc}
   */
  public function getRequestTime() {
    return $this->date
      ->format('U');
  }

  /**
   * {@inheritdoc}
   */
  public function getRequestMicroTime() {
    return $this->date
      ->format('U.u');
  }

  /**
   * {@inheritdoc}
   */
  public function getCurrentTime() {
    return $this->date
      ->format('U');
  }

  /**
   * {@inheritdoc}
   */
  public function getCurrentMicroTime() {
    return $this->date
      ->format('U.u');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SmsTestTime::$date protected property Date for testing.
SmsTestTime::$original protected property Original time service.
SmsTestTime::getCurrentMicroTime public function Returns the current system time with microsecond precision. Overrides TimeInterface::getCurrentMicroTime
SmsTestTime::getCurrentTime public function Returns the current system time as an integer. Overrides TimeInterface::getCurrentTime
SmsTestTime::getRequestMicroTime public function Returns the timestamp for the current request with microsecond precision. Overrides TimeInterface::getRequestMicroTime
SmsTestTime::getRequestTime public function Returns the timestamp for the current request. Overrides TimeInterface::getRequestTime
SmsTestTime::__construct public function SmsTestTime constructor.