You are here

public function SmsFrameworkMessageResultEntityTest::testSaveResultWithoutParent in SMS Framework 8

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

Tests saving a message result without a parent SMS message.

File

tests/src/Kernel/SmsFrameworkMessageResultEntityTest.php, line 86

Class

SmsFrameworkMessageResultEntityTest
Tests the SMS message result entity.

Namespace

Drupal\Tests\sms\Kernel

Code

public function testSaveResultWithoutParent() {
  $this
    ->setExpectedException(EntityStorageException::class, 'No parent SMS message specified for SMS message result');

  /** @var \Drupal\sms\Entity\SmsMessageResult $result */
  $result = $this
    ->createMessageResult()
    ->setCreditsUsed(rand(5, 10))
    ->setCreditsBalance(rand(10, 20))
    ->setError(SmsMessageResultStatus::INVALID_SENDER)
    ->setErrorMessage('Invalid sender ID')
    ->setReports([
    SmsDeliveryReport::create()
      ->setRecipient('1234567890'),
  ]);
  $result
    ->save();
}