ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
RedisHandlerTest.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog\Handler;
13
17
19{
24 {
25 new RedisHandler(new \stdClass(), 'key');
26 }
27
29 {
30 $redis = $this->getMock('Predis\Client');
31 $this->assertInstanceof('Monolog\Handler\RedisHandler', new RedisHandler($redis, 'key'));
32 }
33
35 {
36 $redis = $this->getMock('Redis');
37 $this->assertInstanceof('Monolog\Handler\RedisHandler', new RedisHandler($redis, 'key'));
38 }
39
40 public function testPredisHandle()
41 {
42 $redis = $this->getMock('Predis\Client', array('rpush'));
43
44 // Predis\Client uses rpush
45 $redis->expects($this->once())
46 ->method('rpush')
47 ->with('key', 'test');
48
49 $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
50
51 $handler = new RedisHandler($redis, 'key');
52 $handler->setFormatter(new LineFormatter("%message%"));
53 $handler->handle($record);
54 }
55
56 public function testRedisHandle()
57 {
58 $redis = $this->getMock('Redis', array('rpush'));
59
60 // Redis uses rPush
61 $redis->expects($this->once())
62 ->method('rPush')
63 ->with('key', 'test');
64
65 $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
66
67 $handler = new RedisHandler($redis, 'key');
68 $handler->setFormatter(new LineFormatter("%message%"));
69 $handler->handle($record);
70 }
71
72 public function testRedisHandleCapped()
73 {
74 $redis = $this->getMock('Redis', array('multi', 'rpush', 'ltrim', 'exec'));
75
76 // Redis uses multi
77 $redis->expects($this->once())
78 ->method('multi')
79 ->will($this->returnSelf());
80
81 $redis->expects($this->once())
82 ->method('rpush')
83 ->will($this->returnSelf());
84
85 $redis->expects($this->once())
86 ->method('ltrim')
87 ->will($this->returnSelf());
88
89 $redis->expects($this->once())
90 ->method('exec')
91 ->will($this->returnSelf());
92
93 $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
94
95 $handler = new RedisHandler($redis, 'key', Logger::DEBUG, true, 10);
96 $handler->setFormatter(new LineFormatter("%message%"));
97 $handler->handle($record);
98 }
99
100 public function testPredisHandleCapped()
101 {
102 $redis = $this->getMock('Predis\Client', array('transaction'));
103
104 $redisTransaction = $this->getMock('Predis\Client', array('rpush', 'ltrim'));
105
106 $redisTransaction->expects($this->once())
107 ->method('rpush')
108 ->will($this->returnSelf());
109
110 $redisTransaction->expects($this->once())
111 ->method('ltrim')
112 ->will($this->returnSelf());
113
114 // Redis uses multi
115 $redis->expects($this->once())
116 ->method('transaction')
117 ->will($this->returnCallback(function ($cb) use ($redisTransaction) {
118 $cb($redisTransaction);
119 }));
120
121 $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
122
123 $handler = new RedisHandler($redis, 'key', Logger::DEBUG, true, 10);
124 $handler->setFormatter(new LineFormatter("%message%"));
125 $handler->handle($record);
126 }
127}
An exception for terminatinating execution or to throw for unit testing.
Formats incoming records into a one-line string.
testConstructorShouldThrowExceptionForInvalidRedis()
@expectedException InvalidArgumentException
Logs to a Redis key using rpush.
Monolog log channel.
Definition: Logger.php:28
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
const DEBUG
Detailed debug information.
Definition: Logger.php:32
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
$handler