ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
67{
68 protected $records = array();
69 protected $recordsByLevel = array();
70
71 public function getRecords()
72 {
73 return $this->records;
74 }
75
76 public function clear()
77 {
78 $this->records = array();
79 $this->recordsByLevel = array();
80 }
81
82 public function hasRecords($level)
83 {
84 return isset($this->recordsByLevel[$level]);
85 }
86
91 public function hasRecord($record, $level)
92 {
93 if (is_string($record)) {
94 $record = array('message' => $record);
95 }
96
97 return $this->hasRecordThatPasses(function ($rec) use ($record) {
98 if ($rec['message'] !== $record['message']) {
99 return false;
100 }
101 if (isset($record['context']) && $rec['context'] !== $record['context']) {
102 return false;
103 }
104 return true;
105 }, $level);
106 }
107
109 {
110 return $this->hasRecordThatPasses(function ($rec) use ($message) {
111 return strpos($rec['message'], $message) !== false;
112 }, $level);
113 }
114
115 public function hasRecordThatMatches($regex, $level)
116 {
117 return $this->hasRecordThatPasses(function ($rec) use ($regex) {
118 return preg_match($regex, $rec['message']) > 0;
119 }, $level);
120 }
121
122 public function hasRecordThatPasses($predicate, $level)
123 {
124 if (!is_callable($predicate)) {
125 throw new \InvalidArgumentException("Expected a callable for hasRecordThatSucceeds");
126 }
127
128 if (!isset($this->recordsByLevel[$level])) {
129 return false;
130 }
131
132 foreach ($this->recordsByLevel[$level] as $i => $rec) {
133 if (call_user_func($predicate, $rec, $i)) {
134 return true;
135 }
136 }
137
138 return false;
139 }
140
144 protected function write(array $record)
145 {
146 $this->recordsByLevel[$record['level']][] = $record;
147 $this->records[] = $record;
148 }
149
150 public function __call($method, $args)
151 {
152 if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/', $method, $matches) > 0) {
153 $genericMethod = $matches[1] . ('Records' !== $matches[3] ? 'Record' : '') . $matches[3];
154 $level = constant('Monolog\Logger::' . strtoupper($matches[2]));
155 if (method_exists($this, $genericMethod)) {
156 $args[] = $level;
157
158 return call_user_func_array(array($this, $genericMethod), $args);
159 }
160 }
161
162 throw new \BadMethodCallException('Call to undefined method ' . get_class($this) . '::' . $method . '()');
163 }
164}
An exception for terminatinating execution or to throw for unit testing.
Base Handler class providing the Handler structure.
Used for testing purposes.
Definition: TestHandler.php:67
write(array $record)
{Writes the record down to the log of the implementing handler.void}
hasRecord($record, $level)
Definition: TestHandler.php:91
hasRecordThatContains($message, $level)
hasRecordThatMatches($regex, $level)
hasRecordThatPasses($predicate, $level)
$i
Definition: disco.tpl.php:19
catch(Exception $e) $message