ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
TestHandler.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
15
69{
70 protected $records = array();
71 protected $recordsByLevel = array();
72
73 public function getRecords()
74 {
75 return $this->records;
76 }
77
78 protected function hasRecordRecords($level)
79 {
80 return isset($this->recordsByLevel[$level]);
81 }
82
83 protected function hasRecord($record, $level)
84 {
85 if (is_array($record)) {
86 $record = $record['message'];
87 }
88
89 return $this->hasRecordThatPasses(function($rec) use ($record) {
90 return $rec['message'] === $record;
91 }, $level);
92 }
93
94 public function hasRecordThatContains($message, $level)
95 {
96 return $this->hasRecordThatPasses(function($rec) use ($message) {
97 return strpos($rec['message'], $message) !== false;
98 }, $level);
99 }
100
101 public function hasRecordThatMatches($regex, $level)
102 {
103 return $this->hasRecordThatPasses(function($rec) use ($regex) {
104 return preg_match($regex, $rec['message']) > 0;
105 }, $level);
106 }
107
108 public function hasRecordThatPasses($predicate, $level)
109 {
110 if (!is_callable($predicate)) {
111 throw new \InvalidArgumentException("Expected a callable for hasRecordThatSucceeds");
112 }
113
114 if (!isset($this->recordsByLevel[$level])) {
115 return false;
116 }
117
118 foreach ($this->recordsByLevel[$level] as $i => $rec) {
119 if (call_user_func($predicate, $rec, $i)) {
120 return true;
121 }
122 }
123
124 return false;
125 }
126
130 protected function write(array $record)
131 {
132 $this->recordsByLevel[$record['level']][] = $record;
133 $this->records[] = $record;
134 }
135
136
137 public function __call($method, $args)
138 {
139 if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/', $method, $matches) > 0) {
140 $genericMethod = $matches[1] . 'Record' . $matches[3];
141 $level = constant('Monolog\Logger::' . strtoupper($matches[2]));
142 if (method_exists($this, $genericMethod)) {
143 $args[] = $level;
144 return call_user_func_array(array($this, $genericMethod), $args);
145 }
146 }
147
148 throw new \BadMethodCallException('Call to undefined method ' . get_class($this) . '::' . $method . '()');
149 }
150}
Base Handler class providing the Handler structure.
Used for testing purposes.
Definition: TestHandler.php:69
write(array $record)
{Writes the record down to the log of the implementing handler.void}
hasRecord($record, $level)
Definition: TestHandler.php:83
hasRecordThatContains($message, $level)
Definition: TestHandler.php:94
hasRecordThatMatches($regex, $level)
hasRecordThatPasses($predicate, $level)
Monolog log channel.
Definition: Logger.php:28