TestMessenger.php in Rules 8.3
File
tests/src/Unit/TestMessenger.php
View source
<?php
namespace Drupal\Tests\rules\Unit;
use Drupal\Core\Messenger\MessengerInterface;
class TestMessenger implements MessengerInterface {
protected $messages = NULL;
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;
}
}
}
public function addStatus($message, $repeat = FALSE) {
return $this
->addMessage($message, static::TYPE_STATUS, $repeat);
}
public function addError($message, $repeat = FALSE) {
return $this
->addMessage($message, static::TYPE_ERROR, $repeat);
}
public function addWarning($message, $repeat = FALSE) {
return $this
->addMessage($message, static::TYPE_WARNING, $repeat);
}
public function all() {
return $this->messages;
}
public function messagesByType($type) {
if (!empty($type)) {
return isset($this->messages[$type]) ? $this->messages[$type] : [];
}
}
public function deleteAll() {
return $this->messages = NULL;
}
public function deleteByType($type) {
if (!empty($type) && isset($this->messages[$type])) {
$this->messages[$type] = NULL;
}
}
}
Classes
Name |
Description |
TestMessenger |
Mock class to replace the messenger service in unit tests. |