You are here

class SmsTestEventSubscriber in SMS Framework 8

Same name and namespace in other branches
  1. 2.x tests/modules/sms_test/src/EventSubscriber/SmsTestEventSubscriber.php \Drupal\sms_test\EventSubscriber\SmsTestEventSubscriber
  2. 2.1.x tests/modules/sms_test/src/EventSubscriber/SmsTestEventSubscriber.php \Drupal\sms_test\EventSubscriber\SmsTestEventSubscriber

Test event subscriber.

Hierarchy

  • class \Drupal\sms_test\EventSubscriber\SmsTestEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of SmsTestEventSubscriber

1 string reference to 'SmsTestEventSubscriber'
sms_test.services.yml in tests/modules/sms_test/sms_test.services.yml
tests/modules/sms_test/sms_test.services.yml
1 service uses SmsTestEventSubscriber
sms_test.event_subscriber in tests/modules/sms_test/sms_test.services.yml
Drupal\sms_test\EventSubscriber\SmsTestEventSubscriber

File

tests/modules/sms_test/src/EventSubscriber/SmsTestEventSubscriber.php, line 14

Namespace

Drupal\sms_test\EventSubscriber
View source
class SmsTestEventSubscriber implements EventSubscriberInterface {

  /**
   * Adds a gateway with ID 'test_gateway_200', with weight '200'.
   *
   * @param \Drupal\sms\Event\RecipientGatewayEvent $event
   *   The RecipientGatewayEvent event.
   */
  public function testAddGateway200(RecipientGatewayEvent $event) {
    if (\Drupal::state()
      ->get('sms_test_event_subscriber__test_gateway_200', FALSE)) {
      $gateway = SmsGateway::load('test_gateway_200');
      $event
        ->addGateway($gateway, 200);
    }
  }

  /**
   * Adds a gateway with ID 'test_gateway_400', with weight '400'.
   *
   * @param \Drupal\sms\Event\RecipientGatewayEvent $event
   *   The RecipientGatewayEvent event.
   */
  public function testAddGateway400(RecipientGatewayEvent $event) {
    if (\Drupal::state()
      ->get('sms_test_event_subscriber__test_gateway_400', FALSE)) {
      $gateway = SmsGateway::load('test_gateway_400');
      $event
        ->addGateway($gateway, 400);
    }
  }

  /**
   * Adds event name to execution order when a message is processed.
   *
   * @param \Symfony\Component\EventDispatcher\Event $event
   *   The event.
   * @param string $eventName
   *   The event name.
   */
  public function testExecutionOrder(Event $event, $eventName) {
    $execution_order = \Drupal::state()
      ->get('sms_test_event_subscriber__execution_order', []);
    $execution_order[] = $eventName;
    \Drupal::state()
      ->set('sms_test_event_subscriber__execution_order', $execution_order);
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[SmsEvents::MESSAGE_GATEWAY][] = [
      'testAddGateway200',
    ];
    $events[SmsEvents::MESSAGE_GATEWAY][] = [
      'testAddGateway400',
    ];
    $events[SmsEvents::MESSAGE_PRE_PROCESS][] = [
      'testExecutionOrder',
    ];
    $events[SmsEvents::MESSAGE_POST_PROCESS][] = [
      'testExecutionOrder',
    ];
    $events[SmsEvents::MESSAGE_QUEUE_PRE_PROCESS][] = [
      'testExecutionOrder',
    ];
    $events[SmsEvents::MESSAGE_QUEUE_POST_PROCESS][] = [
      'testExecutionOrder',
    ];
    $events[SmsEvents::MESSAGE_INCOMING_PRE_PROCESS][] = [
      'testExecutionOrder',
    ];
    $events[SmsEvents::MESSAGE_INCOMING_POST_PROCESS][] = [
      'testExecutionOrder',
    ];
    $events[SmsEvents::MESSAGE_OUTGOING_PRE_PROCESS][] = [
      'testExecutionOrder',
    ];
    $events[SmsEvents::MESSAGE_OUTGOING_POST_PROCESS][] = [
      'testExecutionOrder',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SmsTestEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
SmsTestEventSubscriber::testAddGateway200 public function Adds a gateway with ID 'test_gateway_200', with weight '200'.
SmsTestEventSubscriber::testAddGateway400 public function Adds a gateway with ID 'test_gateway_400', with weight '400'.
SmsTestEventSubscriber::testExecutionOrder public function Adds event name to execution order when a message is processed.