ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Monolog\Handler\PushoverHandlerTest Class Reference

Almost all examples (expected header, titles, messages) taken from https://www.pushover.net/api. More...

+ Inheritance diagram for Monolog\Handler\PushoverHandlerTest:
+ Collaboration diagram for Monolog\Handler\PushoverHandlerTest:

Public Member Functions

 testWriteHeader ()
 
 testWriteContent ($content)
 testWriteHeader More...
 
 testWriteWithComplexTitle ()
 
 testWriteWithComplexMessage ()
 
 testWriteWithTooLongMessage ()
 
 testWriteWithHighPriority ()
 
 testWriteWithEmergencyPriority ()
 
 testWriteToMultipleUsers ()
 

Private Member Functions

 createHandler ($token='myToken', $user='myUser', $title='Monolog')
 

Private Attributes

 $res
 
 $handler
 

Additional Inherited Members

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

Detailed Description

Almost all examples (expected header, titles, messages) taken from https://www.pushover.net/api.

Author
Sebastian Göttschkes sebas.nosp@m.tian.nosp@m..goet.nosp@m.tsch.nosp@m.kes@g.nosp@m.oogl.nosp@m.email.nosp@m..com
See also
https://www.pushover.net/api

Definition at line 23 of file PushoverHandlerTest.php.

Member Function Documentation

◆ createHandler()

Monolog\Handler\PushoverHandlerTest::createHandler (   $token = 'myToken',
  $user = 'myUser',
  $title = 'Monolog' 
)
private

Definition at line 115 of file PushoverHandlerTest.php.

References $title, array, and Monolog\TestCase\getIdentityFormatter().

Referenced by Monolog\Handler\PushoverHandlerTest\testWriteHeader(), Monolog\Handler\PushoverHandlerTest\testWriteToMultipleUsers(), Monolog\Handler\PushoverHandlerTest\testWriteWithComplexMessage(), Monolog\Handler\PushoverHandlerTest\testWriteWithComplexTitle(), Monolog\Handler\PushoverHandlerTest\testWriteWithEmergencyPriority(), Monolog\Handler\PushoverHandlerTest\testWriteWithHighPriority(), and Monolog\Handler\PushoverHandlerTest\testWriteWithTooLongMessage().

116  {
117  $constructorArgs = array($token, $user, $title);
118  $this->res = fopen('php://memory', 'a');
119  $this->handler = $this->getMock(
120  '\Monolog\Handler\PushoverHandler',
121  array('fsockopen', 'streamSetTimeout', 'closeSocket'),
122  $constructorArgs
123  );
124 
125  $reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
126  $reflectionProperty->setAccessible(true);
127  $reflectionProperty->setValue($this->handler, 'localhost:1234');
128 
129  $this->handler->expects($this->any())
130  ->method('fsockopen')
131  ->will($this->returnValue($this->res));
132  $this->handler->expects($this->any())
133  ->method('streamSetTimeout')
134  ->will($this->returnValue(true));
135  $this->handler->expects($this->any())
136  ->method('closeSocket')
137  ->will($this->returnValue(true));
138 
139  $this->handler->setFormatter($this->getIdentityFormatter());
140  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testWriteContent()

Monolog\Handler\PushoverHandlerTest::testWriteContent (   $content)

testWriteHeader

Definition at line 44 of file PushoverHandlerTest.php.

45  {
46  $this->assertRegexp('/token=myToken&user=myUser&message=test1&title=Monolog&timestamp=\d{10}$/', $content);
47  }

◆ testWriteHeader()

Monolog\Handler\PushoverHandlerTest::testWriteHeader ( )

Definition at line 28 of file PushoverHandlerTest.php.

References Monolog\Handler\PushoverHandlerTest\createHandler(), Monolog\Logger\CRITICAL, Monolog\Logger\EMERGENCY, and Monolog\TestCase\getRecord().

29  {
30  $this->createHandler();
31  $this->handler->setHighPriorityLevel(Logger::EMERGENCY); // skip priority notifications
32  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
33  fseek($this->res, 0);
34  $content = fread($this->res, 1024);
35 
36  $this->assertRegexp('/POST \/1\/messages.json HTTP\/1.1\\r\\nHost: api.pushover.net\\r\\nContent-Type: application\/x-www-form-urlencoded\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content);
37 
38  return $content;
39  }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
createHandler($token='myToken', $user='myUser', $title='Monolog')
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteToMultipleUsers()

Monolog\Handler\PushoverHandlerTest::testWriteToMultipleUsers ( )

Definition at line 104 of file PushoverHandlerTest.php.

References array, Monolog\Handler\PushoverHandlerTest\createHandler(), Monolog\Logger\EMERGENCY, and Monolog\TestCase\getRecord().

105  {
106  $this->createHandler('myToken', array('userA', 'userB'));
107  $this->handler->handle($this->getRecord(Logger::EMERGENCY, 'test1'));
108  fseek($this->res, 0);
109  $content = fread($this->res, 1024);
110 
111  $this->assertRegexp('/token=myToken&user=userA&message=test1&title=Monolog&timestamp=\d{10}&priority=2&retry=30&expire=25200POST/', $content);
112  $this->assertRegexp('/token=myToken&user=userB&message=test1&title=Monolog&timestamp=\d{10}&priority=2&retry=30&expire=25200$/', $content);
113  }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
createHandler($token='myToken', $user='myUser', $title='Monolog')
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testWriteWithComplexMessage()

Monolog\Handler\PushoverHandlerTest::testWriteWithComplexMessage ( )

Definition at line 59 of file PushoverHandlerTest.php.

References Monolog\Handler\PushoverHandlerTest\createHandler(), Monolog\Logger\CRITICAL, Monolog\Logger\EMERGENCY, and Monolog\TestCase\getRecord().

60  {
61  $this->createHandler();
62  $this->handler->setHighPriorityLevel(Logger::EMERGENCY); // skip priority notifications
63  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'Backup of database "example" finished in 16 minutes.'));
64  fseek($this->res, 0);
65  $content = fread($this->res, 1024);
66 
67  $this->assertRegexp('/message=Backup\+of\+database\+%22example%22\+finished\+in\+16\+minutes\./', $content);
68  }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
createHandler($token='myToken', $user='myUser', $title='Monolog')
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteWithComplexTitle()

Monolog\Handler\PushoverHandlerTest::testWriteWithComplexTitle ( )

Definition at line 49 of file PushoverHandlerTest.php.

References Monolog\Handler\PushoverHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

50  {
51  $this->createHandler('myToken', 'myUser', 'Backup finished - SQL1');
52  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
53  fseek($this->res, 0);
54  $content = fread($this->res, 1024);
55 
56  $this->assertRegexp('/title=Backup\+finished\+-\+SQL1/', $content);
57  }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
createHandler($token='myToken', $user='myUser', $title='Monolog')
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteWithEmergencyPriority()

Monolog\Handler\PushoverHandlerTest::testWriteWithEmergencyPriority ( )

Definition at line 94 of file PushoverHandlerTest.php.

References Monolog\Handler\PushoverHandlerTest\createHandler(), Monolog\Logger\EMERGENCY, and Monolog\TestCase\getRecord().

95  {
96  $this->createHandler();
97  $this->handler->handle($this->getRecord(Logger::EMERGENCY, 'test1'));
98  fseek($this->res, 0);
99  $content = fread($this->res, 1024);
100 
101  $this->assertRegexp('/token=myToken&user=myUser&message=test1&title=Monolog&timestamp=\d{10}&priority=2&retry=30&expire=25200$/', $content);
102  }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
createHandler($token='myToken', $user='myUser', $title='Monolog')
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
+ Here is the call graph for this function:

◆ testWriteWithHighPriority()

Monolog\Handler\PushoverHandlerTest::testWriteWithHighPriority ( )

Definition at line 84 of file PushoverHandlerTest.php.

References Monolog\Handler\PushoverHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

85  {
86  $this->createHandler();
87  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
88  fseek($this->res, 0);
89  $content = fread($this->res, 1024);
90 
91  $this->assertRegexp('/token=myToken&user=myUser&message=test1&title=Monolog&timestamp=\d{10}&priority=1$/', $content);
92  }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
createHandler($token='myToken', $user='myUser', $title='Monolog')
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteWithTooLongMessage()

Monolog\Handler\PushoverHandlerTest::testWriteWithTooLongMessage ( )

Definition at line 70 of file PushoverHandlerTest.php.

References Monolog\Handler\PushoverHandlerTest\createHandler(), Monolog\Logger\CRITICAL, Monolog\Logger\EMERGENCY, and Monolog\TestCase\getRecord().

71  {
72  $message = str_pad('test', 520, 'a');
73  $this->createHandler();
74  $this->handler->setHighPriorityLevel(Logger::EMERGENCY); // skip priority notifications
75  $this->handler->handle($this->getRecord(Logger::CRITICAL, $message));
76  fseek($this->res, 0);
77  $content = fread($this->res, 1024);
78 
79  $expectedMessage = substr($message, 0, 505);
80 
81  $this->assertRegexp('/message=' . $expectedMessage . '&title/', $content);
82  }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
createHandler($token='myToken', $user='myUser', $title='Monolog')
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

Field Documentation

◆ $handler

Monolog\Handler\PushoverHandlerTest::$handler
private

Definition at line 26 of file PushoverHandlerTest.php.

◆ $res

Monolog\Handler\PushoverHandlerTest::$res
private

Definition at line 25 of file PushoverHandlerTest.php.


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