headless_cms-1.0.3/modules/headless_cms_notify/tests/modules/headless_cms_notify_test/src/NotifyTestTrait.php

modules/headless_cms_notify/tests/modules/headless_cms_notify_test/src/NotifyTestTrait.php
<?php

declare(strict_types=1);

namespace Drupal\headless_cms_notify_test;

use Drupal\headless_cms_notify\NotifyMessage\HeadlessNotifyMessageInterface;
use Drupal\headless_cms_notify_test\Plugin\HeadlessNotifyTransport\MemoryTransport;

/**
 * Provides methods for testing notifications.
 */
trait NotifyTestTrait {

  /**
   * Asserts that a notification was sent.
   *
   * @param string $message
   *   The assertion message.
   */
  protected function assertNotificationSent(string $message = ''): void {
    $this->assertNotEmpty(MemoryTransport::getMessages(), $message ?: 'A notification should have been sent.');
  }

  /**
   * Asserts that no notification was sent.
   *
   * @param string $message
   *   The assertion message.
   */
  protected function assertNoNotificationSent(string $message = ''): void {
    $this->assertEmpty(MemoryTransport::getMessages(), $message ?: 'No notification should have been sent.');
  }

  /**
   * Asserts the number of notifications sent.
   *
   * @param int $count
   *   The expected number of notifications.
   * @param string $message
   *   The assertion message.
   */
  protected function assertNotificationCount(int $count, string $message = ''): void {
    $this->assertCount($count, MemoryTransport::getMessages(), $message ?: sprintf('%d notification(s) should have been sent.', $count));
  }

  /**
   * Gets the last sent notification message.
   *
   * @return \Drupal\headless_cms_notify\NotifyMessage\HeadlessNotifyMessageInterface|null
   *   The last sent notification message, or NULL if no messages were sent.
   */
  protected function getLastNotification(): ?HeadlessNotifyMessageInterface {
    $messages = MemoryTransport::getMessages();
    return empty($messages) ? NULL : end($messages);
  }

  /**
   * Resets the notification history.
   */
  protected function resetNotifications(): void {
    MemoryTransport::reset();
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc