You are here

public function SmsFrameworkSmsSendTest::testDefaultGatewayChange in SMS Framework 8

Same name and namespace in other branches
  1. 2.x tests/src/Kernel/SmsFrameworkSmsSendTest.php \Drupal\Tests\sms\Kernel\SmsFrameworkSmsSendTest::testDefaultGatewayChange()
  2. 2.1.x tests/src/Kernel/SmsFrameworkSmsSendTest.php \Drupal\Tests\sms\Kernel\SmsFrameworkSmsSendTest::testDefaultGatewayChange()

Test default gateway change in same request.

File

tests/src/Kernel/SmsFrameworkSmsSendTest.php, line 54

Class

SmsFrameworkSmsSendTest
Tests sending SMS messages.

Namespace

Drupal\Tests\sms\Kernel

Code

public function testDefaultGatewayChange() {
  $gateways = [];
  $message_counts = [];
  for ($a = 0; $a < 3; $a++) {
    $gateways[$a] = $this
      ->createMemoryGateway([
      'skip_queue' => TRUE,
    ]);
    $message_counts[$a] = 0;
  }
  $message_counts = [
    0,
    0,
    0,
  ];
  for ($a = 0; $a < 3; $a++) {
    foreach ($gateways as $i => &$gateway) {
      $this
        ->setFallbackGateway($gateway);
      $sms_message = (new SmsMessage())
        ->addRecipients($this
        ->randomPhoneNumbers(1))
        ->setMessage($this
        ->randomString())
        ->setDirection(Direction::OUTGOING);
      $this->defaultSmsProvider
        ->queue($sms_message);
      $message_counts[$i]++;
      foreach ($gateways as $k => $gateway2) {
        $this
          ->assertEquals($message_counts[$k], count($this
          ->getTestMessages($gateway2)));
      }
    }
  }
}