class TestMessenger in Rules 8.3
Mock class to replace the messenger service in unit tests.
Hierarchy
- class \Drupal\Tests\rules\Unit\TestMessenger implements MessengerInterface
Expanded class hierarchy of TestMessenger
1 file declares its use of TestMessenger
- RulesIntegrationTestBase.php in tests/
src/ Unit/ Integration/ RulesIntegrationTestBase.php
File
- tests/
src/ Unit/ TestMessenger.php, line 10
Namespace
Drupal\Tests\rules\UnitView source
class TestMessenger implements MessengerInterface {
/**
* Array of messages.
*
* @var array
*/
protected $messages = NULL;
/**
* {@inheritdoc}
*/
public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE) {
if (!empty($message)) {
$this->messages[$type] = isset($this->messages[$type]) ? $this->messages[$type] : [];
if ($repeat || !in_array($message, $this->messages[$type])) {
$this->messages[$type][] = $message;
}
}
}
/**
* {@inheritdoc}
*/
public function addStatus($message, $repeat = FALSE) {
return $this
->addMessage($message, static::TYPE_STATUS, $repeat);
}
/**
* {@inheritdoc}
*/
public function addError($message, $repeat = FALSE) {
return $this
->addMessage($message, static::TYPE_ERROR, $repeat);
}
/**
* {@inheritdoc}
*/
public function addWarning($message, $repeat = FALSE) {
return $this
->addMessage($message, static::TYPE_WARNING, $repeat);
}
/**
* {@inheritdoc}
*/
public function all() {
return $this->messages;
}
/**
* {@inheritdoc}
*/
public function messagesByType($type) {
if (!empty($type)) {
return isset($this->messages[$type]) ? $this->messages[$type] : [];
}
}
/**
* {@inheritdoc}
*/
public function deleteAll() {
return $this->messages = NULL;
}
/**
* {@inheritdoc}
*/
public function deleteByType($type) {
if (!empty($type) && isset($this->messages[$type])) {
$this->messages[$type] = NULL;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MessengerInterface:: |
constant | An error. | ||
MessengerInterface:: |
constant | A status message. | ||
MessengerInterface:: |
constant | A warning. | ||
TestMessenger:: |
protected | property | Array of messages. | |
TestMessenger:: |
public | function |
Adds a new error message to the queue. Overrides MessengerInterface:: |
|
TestMessenger:: |
public | function |
Adds a new message to the queue. Overrides MessengerInterface:: |
|
TestMessenger:: |
public | function |
Adds a new status message to the queue. Overrides MessengerInterface:: |
|
TestMessenger:: |
public | function |
Adds a new warning message to the queue. Overrides MessengerInterface:: |
|
TestMessenger:: |
public | function |
Gets all messages. Overrides MessengerInterface:: |
|
TestMessenger:: |
public | function |
Deletes all messages. Overrides MessengerInterface:: |
|
TestMessenger:: |
public | function |
Deletes all messages of a certain type. Overrides MessengerInterface:: |
|
TestMessenger:: |
public | function |
Gets all messages of a certain type. Overrides MessengerInterface:: |