class RecipientGatewayEventTest in SMS Framework 8
Same name and namespace in other branches
- 2.x tests/src/Unit/Event/RecipientGatewayEventTest.php \Drupal\Tests\sms\Unit\Event\RecipientGatewayEventTest
- 2.1.x tests/src/Unit/Event/RecipientGatewayEventTest.php \Drupal\Tests\sms\Unit\Event\RecipientGatewayEventTest
Unit Tests for SmsMessage.
@group SMS Framework @coversDefaultClass \Drupal\sms\Event\RecipientGatewayEvent
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\sms\Unit\Event\RecipientGatewayEventTest uses SmsFrameworkTestTrait
Expanded class hierarchy of RecipientGatewayEventTest
File
- tests/
src/ Unit/ Event/ RecipientGatewayEventTest.php, line 16
Namespace
Drupal\Tests\sms\Unit\EventView source
class RecipientGatewayEventTest extends UnitTestCase {
use SmsFrameworkTestTrait;
/**
* Tests gateway sort.
*
* @covers ::getGatewaysSorted
*/
public function testSortFunction() {
$number = $this
->randomPhoneNumbers()[0];
$event = $this
->createEvent($number);
$gateway = $this
->getMock(SmsGatewayInterface::class);
$gateway
->expects($this
->any())
->method('id')
->willReturn('gateway_first');
$event
->addGateway($gateway, 100);
$gateway = $this
->getMock(SmsGatewayInterface::class);
$gateway
->expects($this
->any())
->method('id')
->willReturn('gateway_second');
$event
->addGateway($gateway, 200);
$sorted = $event
->getGatewaysSorted();
$this
->assertEquals(2, count($sorted));
$this
->assertEquals('gateway_second', $sorted[0]
->id());
$this
->assertEquals('gateway_first', $sorted[1]
->id());
}
/**
* Tests recipient constructor.
*
* @covers ::getRecipient
*/
public function testRecipientConstructor() {
$number = $this
->randomPhoneNumbers()[0];
$event = $this
->createEvent($number);
$this
->assertEquals($number, $event
->getRecipient(), 'Constructor recipient is set');
}
/**
* Tests recipient methods.
*
* @covers ::getRecipient
* @covers ::setRecipient
*/
public function testRecipient() {
$event = $this
->createEvent($this
->randomPhoneNumbers()[0]);
$number = $this
->randomPhoneNumbers()[0];
$event
->setRecipient($number);
$this
->assertEquals($number, $event
->getRecipient(), 'Recipient is set via setRecipient');
}
/**
* Tests gateway add and getter.
*
* @covers ::addGateway
* @covers ::getGateways
*/
public function testGetGateways() {
$event = $this
->createEvent($this
->randomPhoneNumbers()[0]);
$gateway = $this
->getMock(SmsGatewayInterface::class);
$gateway
->expects($this
->any())
->method('id')
->willReturn('gateway_1');
$event
->addGateway($gateway, 200);
$gateway = $this
->getMock(SmsGatewayInterface::class);
$gateway
->expects($this
->any())
->method('id')
->willReturn('gateway_2');
$event
->addGateway($gateway, 400);
$gateways = $event
->getGateways();
$this
->assertEquals('gateway_1', $gateways[0][0]
->id());
$this
->assertEquals(200, $gateways[0][1]);
$this
->assertEquals('gateway_2', $gateways[1][0]
->id());
$this
->assertEquals(400, $gateways[1][1]);
}
/**
* Tests removing gateway with both ID and priority.
*
* @covers ::removeGateway
*/
public function testGatewayRemove() {
$event = $this
->createEvent($this
->randomPhoneNumbers()[0]);
$gateway = $this
->getMock(SmsGatewayInterface::class);
$gateway
->expects($this
->any())
->method('id')
->willReturn('gateway_1');
$event
->addGateway($gateway, 200);
$gateway = $this
->getMock(SmsGatewayInterface::class);
$gateway
->expects($this
->any())
->method('id')
->willReturn('gateway_1');
$event
->addGateway($gateway, 400);
$gateway = $this
->getMock(SmsGatewayInterface::class);
$gateway
->expects($this
->any())
->method('id')
->willReturn('gateway_2');
$event
->addGateway($gateway, 600);
$this
->assertEquals(3, count($event
->getGateways()), 'There are three gateways.');
$event
->removeGateway('gateway_1', 400);
$this
->assertEquals(2, count($event
->getGateways()), 'One gateways was removed.');
}
/**
* Tests removing gateways with same identifier.
*
* @covers ::removeGateway
*/
public function testGatewayRemoveAllSameId() {
$event = $this
->createEvent($this
->randomPhoneNumbers()[0]);
$gateway = $this
->getMock(SmsGatewayInterface::class);
$gateway
->expects($this
->any())
->method('id')
->willReturn('gateway_1');
$event
->addGateway($gateway, 200);
$gateway = $this
->getMock(SmsGatewayInterface::class);
$gateway
->expects($this
->any())
->method('id')
->willReturn('gateway_1');
$event
->addGateway($gateway, 400);
$gateway = $this
->getMock(SmsGatewayInterface::class);
$gateway
->expects($this
->any())
->method('id')
->willReturn('gateway_2');
$event
->addGateway($gateway, 600);
$this
->assertEquals(3, count($event
->getGateways()), 'There are three gateways.');
$event
->removeGateway('gateway_1');
$this
->assertEquals(1, count($event
->getGateways()), 'Two gateways were removed.');
}
/**
* Create a new event for testing.
*
* @param string $recipient
* The recipient phone number.
*
* @return \Drupal\sms\Event\RecipientGatewayEvent
* A new recipient gateway event instance.
*/
public function createEvent($recipient) {
return new RecipientGatewayEvent($recipient);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RecipientGatewayEventTest:: |
public | function | Create a new event for testing. | |
RecipientGatewayEventTest:: |
public | function | Tests removing gateway with both ID and priority. | |
RecipientGatewayEventTest:: |
public | function | Tests removing gateways with same identifier. | |
RecipientGatewayEventTest:: |
public | function | Tests gateway add and getter. | |
RecipientGatewayEventTest:: |
public | function | Tests recipient methods. | |
RecipientGatewayEventTest:: |
public | function | Tests recipient constructor. | |
RecipientGatewayEventTest:: |
public | function | Tests gateway sort. | |
SmsFrameworkTestTrait:: |
protected | function | Creates an entity, and optionally adds phone numbers. | |
SmsFrameworkTestTrait:: |
protected | function | Creates a memory gateway. | |
SmsFrameworkTestTrait:: |
protected | function | Create a result and reports for a message. | |
SmsFrameworkTestTrait:: |
protected | function | Get all messages received by a gateway. | |
SmsFrameworkTestTrait:: |
protected | function | Get the last message sent to gateway. | |
SmsFrameworkTestTrait:: |
public | function | Get the last SMS message sent to 'Memory' gateway. | |
SmsFrameworkTestTrait:: |
protected | function | Gets the last SMS report for messages sent to 'Memory' gateway. | |
SmsFrameworkTestTrait:: |
protected | function | Gets the last phone number verification that was created. | |
SmsFrameworkTestTrait:: |
protected | function | Gets an SMS report for message with message ID. | |
SmsFrameworkTestTrait:: |
protected | function | Gets all SMS reports for messages sent to 'Memory' gateway. | |
SmsFrameworkTestTrait:: |
public | function | Get all SMS messages sent to a 'Memory' gateway. | |
SmsFrameworkTestTrait:: |
protected | function | Generates random phone numbers for tests. | |
SmsFrameworkTestTrait:: |
protected | function | Generates a random SMS message by the specified user. | |
SmsFrameworkTestTrait:: |
protected | function | Resets incoming messages stored in memory by gateway. | |
SmsFrameworkTestTrait:: |
protected | function | Resets the SMS reports stored in memory by 'Memory' gateway. | |
SmsFrameworkTestTrait:: |
public | function | Resets SMS messages stored in memory by 'Memory' gateway. | |
SmsFrameworkTestTrait:: |
protected | function | Sets the fallback gateway. | |
SmsFrameworkTestTrait:: |
protected | function | Forces verification of a phone number for an entity. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |