ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Monolog\Handler\SwiftMailerHandlerTest Class Reference
+ Inheritance diagram for Monolog\Handler\SwiftMailerHandlerTest:
+ Collaboration diagram for Monolog\Handler\SwiftMailerHandlerTest:

Public Member Functions

 setUp ()
 
 testMessageCreationIsLazyWhenUsingCallback ()
 
 testMessageCanBeCustomizedGivenLoggedData ()
 
 testMessageSubjectFormatting ()
 
 testMessageHaveUniqueId ()
 

Private Attributes

 $mailer
 

Additional Inherited Members

- Protected Member Functions inherited from Monolog\TestCase
 getRecord ($level=Logger::WARNING, $message='test', $context=array())
 
 getMultipleRecords ()
 
 getIdentityFormatter ()
 

Detailed Description

Definition at line 17 of file SwiftMailerHandlerTest.php.

Member Function Documentation

◆ setUp()

Monolog\Handler\SwiftMailerHandlerTest::setUp ( )

Definition at line 22 of file SwiftMailerHandlerTest.php.

23  {
24  $this->mailer = $this
25  ->getMockBuilder('Swift_Mailer')
26  ->disableOriginalConstructor()
27  ->getMock();
28  }

◆ testMessageCanBeCustomizedGivenLoggedData()

Monolog\Handler\SwiftMailerHandlerTest::testMessageCanBeCustomizedGivenLoggedData ( )

Definition at line 47 of file SwiftMailerHandlerTest.php.

References $handler, $records, array, Monolog\Logger\EMERGENCY, and Monolog\TestCase\getRecord().

48  {
49  // Wire Mailer to expect a specific Swift_Message with a customized Subject
50  $expectedMessage = new \Swift_Message();
51  $this->mailer->expects($this->once())
52  ->method('send')
53  ->with($this->callback(function ($value) use ($expectedMessage) {
54  return $value instanceof \Swift_Message
55  && $value->getSubject() === 'Emergency'
56  && $value === $expectedMessage;
57  }));
58 
59  // Callback dynamically changes subject based on number of logged records
60  $callback = function ($content, array $records) use ($expectedMessage) {
61  $subject = count($records) > 0 ? 'Emergency' : 'Normal';
62  $expectedMessage->setSubject($subject);
63 
64  return $expectedMessage;
65  };
66  $handler = new SwiftMailerHandler($this->mailer, $callback);
67 
68  // Logging 1 record makes this an Emergency
69  $records = array(
71  );
72  $handler->handleBatch($records);
73  }
$records
Definition: simple_test.php:22
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
Create styles array
The data for the language used.
$handler
+ Here is the call graph for this function:

◆ testMessageCreationIsLazyWhenUsingCallback()

Monolog\Handler\SwiftMailerHandlerTest::testMessageCreationIsLazyWhenUsingCallback ( )

Definition at line 30 of file SwiftMailerHandlerTest.php.

References $handler, $records, array, Monolog\Logger\DEBUG, Monolog\TestCase\getRecord(), and Monolog\Logger\INFO.

31  {
32  $this->mailer->expects($this->never())
33  ->method('send');
34 
35  $callback = function () {
36  throw new \RuntimeException('Swift_Message creation callback should not have been called in this test');
37  };
38  $handler = new SwiftMailerHandler($this->mailer, $callback);
39 
40  $records = array(
41  $this->getRecord(Logger::DEBUG),
42  $this->getRecord(Logger::INFO),
43  );
44  $handler->handleBatch($records);
45  }
const DEBUG
Detailed debug information.
Definition: Logger.php:32
$records
Definition: simple_test.php:22
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
Create styles array
The data for the language used.
$handler
const INFO
Interesting events.
Definition: Logger.php:39
+ Here is the call graph for this function:

◆ testMessageHaveUniqueId()

Monolog\Handler\SwiftMailerHandlerTest::testMessageHaveUniqueId ( )

Definition at line 99 of file SwiftMailerHandlerTest.php.

References $handler, and array.

100  {
101  $messageTemplate = \Swift_Message::newInstance();
102  $handler = new SwiftMailerHandler($this->mailer, $messageTemplate);
103 
104  $method = new \ReflectionMethod('Monolog\Handler\SwiftMailerHandler', 'buildMessage');
105  $method->setAccessible(true);
106  $method->invokeArgs($handler, array($messageTemplate, array()));
107 
108  $builtMessage1 = $method->invoke($handler, $messageTemplate, array());
109  $builtMessage2 = $method->invoke($handler, $messageTemplate, array());
110 
111  $this->assertFalse($builtMessage1->getId() === $builtMessage2->getId(), 'Two different messages have the same id');
112  }
Create styles array
The data for the language used.
$handler

◆ testMessageSubjectFormatting()

Monolog\Handler\SwiftMailerHandlerTest::testMessageSubjectFormatting ( )

Definition at line 75 of file SwiftMailerHandlerTest.php.

References $handler, $records, array, Monolog\Logger\EMERGENCY, and Monolog\TestCase\getRecord().

76  {
77  // Wire Mailer to expect a specific Swift_Message with a customized Subject
78  $messageTemplate = new \Swift_Message();
79  $messageTemplate->setSubject('Alert: %level_name% %message%');
80  $receivedMessage = null;
81 
82  $this->mailer->expects($this->once())
83  ->method('send')
84  ->with($this->callback(function ($value) use (&$receivedMessage) {
85  $receivedMessage = $value;
86  return true;
87  }));
88 
89  $handler = new SwiftMailerHandler($this->mailer, $messageTemplate);
90 
91  $records = array(
93  );
94  $handler->handleBatch($records);
95 
96  $this->assertEquals('Alert: EMERGENCY test', $receivedMessage->getSubject());
97  }
$records
Definition: simple_test.php:22
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
Create styles array
The data for the language used.
$handler
+ Here is the call graph for this function:

Field Documentation

◆ $mailer

Monolog\Handler\SwiftMailerHandlerTest::$mailer
private

Definition at line 20 of file SwiftMailerHandlerTest.php.


The documentation for this class was generated from the following file: