scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 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  
12 namespace Monolog\Handler;
13  
14 use Monolog\TestCase;
15 use Monolog\Logger;
16 use Monolog\Formatter\LineFormatter;
17  
18 class RedisHandlerTest extends TestCase
19 {
20 /**
21 * @expectedException InvalidArgumentException
22 */
23 public function testConstructorShouldThrowExceptionForInvalidRedis()
24 {
25 new RedisHandler(new \stdClass(), 'key');
26 }
27  
28 public function testConstructorShouldWorkWithPredis()
29 {
30 $redis = $this->getMock('Predis\Client');
31 $this->assertInstanceof('Monolog\Handler\RedisHandler', new RedisHandler($redis, 'key'));
32 }
33  
34 public function testConstructorShouldWorkWithRedis()
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 }