Debian Codegraph @

vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Formatter/StatsDFormatterTest.php

raw
1 <?php
2
3 namespace Liuggio\StatsdClient\Tests\Monolog\Formatter;
4
5 use Monolog\Logger;
6 use Liuggio\StatsdClient\Monolog\Formatter\StatsDFormatter;
7
8 /**
9 * @covers Liuggio\StatsdClient\Monolog\Formatter\StatsDFormatter
10 */
11 class StatsDFormatterTest extends \PHPUnit_Framework_TestCase
12 {
13 public function testBatchFormat()
14 {
15 $formatter = new StatsDFormatter(null, 2);
16 $message = $formatter->formatBatch(array(
17 array(
18 'level_name' => 'CRITICAL',
19 'channel' => 'test',
20 'message' => 'bar',
21 'context' => array(),
22 'datetime' => new \DateTime,
23 'extra' => array(),
24 ),
25 array(
26 'level_name' => 'WARNING',
27 'channel' => 'log',
28 'message' => 'foo',
29 'context' => array(),
30 'datetime' => new \DateTime,
31 'extra' => array(),
32 ),
33 ));
34
35 $this->assertEquals(array('test.CRITICAL.bar', 'log.WARNING.foo'), $message);
36 }
37
38 public function testDefFormatWithString()
39 {
40 $formatter = new StatsDFormatter(StatsDFormatter::SIMPLE_FORMAT);
41 $message = $formatter->format(array(
42 'level_name' => 'WARNING',
43 'channel' => 'log',
44 'context' => array(),
45 'message' => 'foo',
46 'datetime' => new \DateTime,
47 'extra' => array(),
48 ));
49 $this->assertEquals(array('log.WARNING.foo'), $message);
50 }
51
52 public function testDefFormatWithArrayContext()
53 {
54 $formatter = new StatsDFormatter();
55 $message = $formatter->format(array(
56 'level_name' => 'ERROR',
57 'channel' => 'meh',
58 'message' => 'foo',
59 'datetime' => new \DateTime,
60 'extra' => array(),
61 'context' => array(
62 'foo' => 'bar',
63 'baz' => 'qux',
64 )
65 ));
66
67 $assert = array('meh.ERROR.foo',
68 'meh.ERROR.foo.context.foo.bar',
69 'meh.ERROR.foo.context.baz.qux');
70
71 $this->assertEquals($assert, $message);
72 }
73
74 public function testDefFormatWithArrayContextAndExtra()
75 {
76 $formatter = new StatsDFormatter();
77 $message = $formatter->format(array(
78 'level_name' => 'ERROR',
79 'channel' => 'meh',
80 'message' => 'foo',
81 'datetime' => new \DateTime,
82 'extra' => array('extra'=>'woow'),
83 'context' => array(
84 'foo' => 'bar',
85 'baz' => 'qux',
86 )
87 ));
88
89 $assert = array('meh.ERROR.foo',
90 'meh.ERROR.foo.context.foo.bar',
91 'meh.ERROR.foo.context.baz.qux',
92 'meh.ERROR.foo.extra.extra.woow');
93
94 $this->assertEquals($assert, $message);
95
96 }
97
98 public function testDefLongFormat()
99 {
100 $formatter = new StatsDFormatter();
101 $message = $formatter->format(array(
102 'level_name' => 'DEBUG',
103 'channel' => 'doctrine',
104 'message' => 'INSERT INTO viaggio_calendar (enable, viaggio_id, calendar_id) VALUES (?, ?, ?)',
105 'datetime' => new \DateTime,
106 'extra' => array(),
107 'context' => array(
108 'foo' => 'bar',
109 'baz' => 'qux',
110 )
111 ));
112 $this->assertEquals(array("doctrine.DEBUG.INSERT-INTO",
113 "doctrine.DEBUG.INSERT-INTO.context.foo.bar",
114 "doctrine.DEBUG.INSERT-INTO.context.baz.qux"), $message);
115 }
116
117 public function testDefLongFormatWith3WordsNoContextAndNoExtra()
118 {
119 $formatter = new StatsDFormatter(null, false, false, 3);
120 $message = $formatter->format(array(
121 'level_name' => 'DEBUG',
122 'channel' => 'doctrine',
123 'message' => 'INSERT INTO viaggio_calendar (enable, viaggio_id, calendar_id) VALUES (?, ?, ?)',
124 'datetime' => new \DateTime,
125 'extra' => array(),
126 'context' => array(
127 'foo' => 'bar',
128 'baz' => 'qux',
129 )
130 ));
131 $this->assertEquals(array("doctrine.DEBUG.INSERT-INTO-viaggio-calendar"), $message);
132 }
133 public function testDefRouteException()
134 {
135 $formatter = new StatsDFormatter();
136 $message = $formatter->format(array(
137 'level_name' => 'DEBUG',
138 'channel' => 'doctrine',
139 'message' => 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /ddd" (uncaught exception) at /xxxx/classes.php line 5062',
140 'datetime' => new \DateTime,
141 'extra' => array(),
142 ));
143 $this->assertEquals(array('doctrine.DEBUG.Symfony-Component-HttpKernel-Exception-NotFoundHttpException--No'), $message);
144 }
145
146 public function testDefKernelException()
147 {
148 $formatter = new StatsDFormatter();
149 $message = $formatter->format(array(
150 'level_name' => 'DEBUG',
151 'channel' => 'doctrine',
152 'message' => 'Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException"',
153 'datetime' => new \DateTime,
154 'extra' => array(),
155 'context' => array(
156 'foo' => 'bar',
157 'baz' => 'qux',
158 )
159 ));
160
161 $assert = array('doctrine.DEBUG.Notified-event',
162 'doctrine.DEBUG.Notified-event.context.foo.bar',
163 'doctrine.DEBUG.Notified-event.context.baz.qux');
164
165 $this->assertEquals($assert, $message);
166
167
168 }
169 }