mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Package operations: 2 installs, 23 updates, 0 removals - Updating psr/log (1.1.0 => 1.1.2) - Updating symfony/debug (v3.4.30 => v3.4.35) - Updating symfony/console (v3.4.30 => v3.4.35) - Updating symfony/dotenv (v3.4.30 => v3.4.35) - Updating symfony/routing (v3.4.30 => v3.4.35) - Updating symfony/finder (v3.4.30 => v3.4.35) - Updating symfony/filesystem (v3.4.30 => v3.4.35) - Installing symfony/polyfill-util (v1.12.0) - Installing symfony/polyfill-php56 (v1.12.0) - Updating symfony/http-foundation (v3.4.30 => v3.4.35) - Updating symfony/event-dispatcher (v3.4.30 => v3.4.35) - Updating symfony/http-kernel (v3.4.30 => v3.4.35) - Updating symfony/config (v3.4.30 => v3.4.35) - Updating symfony/dependency-injection (v3.4.30 => v3.4.35) - Updating symfony/class-loader (v3.4.30 => v3.4.35) - Updating symfony/cache (v3.4.30 => v3.4.35) - Updating symfony/framework-bundle (v3.4.30 => v3.4.35) - Updating twig/twig (v1.42.2 => v1.42.4) - Updating symfony/twig-bridge (v3.4.30 => v3.4.35) - Updating symfony/twig-bundle (v3.4.30 => v3.4.35) - Updating symfony/yaml (v3.4.30 => v3.4.35) - Updating symfony/stopwatch (v3.4.30 => v3.4.35) - Updating symfony/var-dumper (v3.4.30 => v3.4.35) - Updating symfony/web-profiler-bundle (v3.4.30 => v3.4.35) - Updating symfony/css-selector (v3.4.30 => v3.4.35)
148 lines
4.4 KiB
PHP
148 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace Psr\Log\Test;
|
|
|
|
use Psr\Log\AbstractLogger;
|
|
|
|
/**
|
|
* Used for testing purposes.
|
|
*
|
|
* It records all records and gives you access to them for verification.
|
|
*
|
|
* @method bool hasEmergency($record)
|
|
* @method bool hasAlert($record)
|
|
* @method bool hasCritical($record)
|
|
* @method bool hasError($record)
|
|
* @method bool hasWarning($record)
|
|
* @method bool hasNotice($record)
|
|
* @method bool hasInfo($record)
|
|
* @method bool hasDebug($record)
|
|
*
|
|
* @method bool hasEmergencyRecords()
|
|
* @method bool hasAlertRecords()
|
|
* @method bool hasCriticalRecords()
|
|
* @method bool hasErrorRecords()
|
|
* @method bool hasWarningRecords()
|
|
* @method bool hasNoticeRecords()
|
|
* @method bool hasInfoRecords()
|
|
* @method bool hasDebugRecords()
|
|
*
|
|
* @method bool hasEmergencyThatContains($message)
|
|
* @method bool hasAlertThatContains($message)
|
|
* @method bool hasCriticalThatContains($message)
|
|
* @method bool hasErrorThatContains($message)
|
|
* @method bool hasWarningThatContains($message)
|
|
* @method bool hasNoticeThatContains($message)
|
|
* @method bool hasInfoThatContains($message)
|
|
* @method bool hasDebugThatContains($message)
|
|
*
|
|
* @method bool hasEmergencyThatMatches($message)
|
|
* @method bool hasAlertThatMatches($message)
|
|
* @method bool hasCriticalThatMatches($message)
|
|
* @method bool hasErrorThatMatches($message)
|
|
* @method bool hasWarningThatMatches($message)
|
|
* @method bool hasNoticeThatMatches($message)
|
|
* @method bool hasInfoThatMatches($message)
|
|
* @method bool hasDebugThatMatches($message)
|
|
*
|
|
* @method bool hasEmergencyThatPasses($message)
|
|
* @method bool hasAlertThatPasses($message)
|
|
* @method bool hasCriticalThatPasses($message)
|
|
* @method bool hasErrorThatPasses($message)
|
|
* @method bool hasWarningThatPasses($message)
|
|
* @method bool hasNoticeThatPasses($message)
|
|
* @method bool hasInfoThatPasses($message)
|
|
* @method bool hasDebugThatPasses($message)
|
|
*/
|
|
class TestLogger extends AbstractLogger
|
|
{
|
|
/**
|
|
* @var array
|
|
*/
|
|
public $records = [];
|
|
|
|
public $recordsByLevel = [];
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function log($level, $message, array $context = [])
|
|
{
|
|
$record = [
|
|
'level' => $level,
|
|
'message' => $message,
|
|
'context' => $context,
|
|
];
|
|
|
|
$this->recordsByLevel[$record['level']][] = $record;
|
|
$this->records[] = $record;
|
|
}
|
|
|
|
public function hasRecords($level)
|
|
{
|
|
return isset($this->recordsByLevel[$level]);
|
|
}
|
|
|
|
public function hasRecord($record, $level)
|
|
{
|
|
if (is_string($record)) {
|
|
$record = ['message' => $record];
|
|
}
|
|
return $this->hasRecordThatPasses(function ($rec) use ($record) {
|
|
if ($rec['message'] !== $record['message']) {
|
|
return false;
|
|
}
|
|
if (isset($record['context']) && $rec['context'] !== $record['context']) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}, $level);
|
|
}
|
|
|
|
public function hasRecordThatContains($message, $level)
|
|
{
|
|
return $this->hasRecordThatPasses(function ($rec) use ($message) {
|
|
return strpos($rec['message'], $message) !== false;
|
|
}, $level);
|
|
}
|
|
|
|
public function hasRecordThatMatches($regex, $level)
|
|
{
|
|
return $this->hasRecordThatPasses(function ($rec) use ($regex) {
|
|
return preg_match($regex, $rec['message']) > 0;
|
|
}, $level);
|
|
}
|
|
|
|
public function hasRecordThatPasses(callable $predicate, $level)
|
|
{
|
|
if (!isset($this->recordsByLevel[$level])) {
|
|
return false;
|
|
}
|
|
foreach ($this->recordsByLevel[$level] as $i => $rec) {
|
|
if (call_user_func($predicate, $rec, $i)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function __call($method, $args)
|
|
{
|
|
if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/', $method, $matches) > 0) {
|
|
$genericMethod = $matches[1] . ('Records' !== $matches[3] ? 'Record' : '') . $matches[3];
|
|
$level = strtolower($matches[2]);
|
|
if (method_exists($this, $genericMethod)) {
|
|
$args[] = $level;
|
|
return call_user_func_array([$this, $genericMethod], $args);
|
|
}
|
|
}
|
|
throw new \BadMethodCallException('Call to undefined method ' . get_class($this) . '::' . $method . '()');
|
|
}
|
|
|
|
public function reset()
|
|
{
|
|
$this->records = [];
|
|
$this->recordsByLevel = [];
|
|
}
|
|
}
|