<?php namespace GuzzleHttp\Tests; use Psr\Log\AbstractLogger; /** * Used for testing purposes. * * It records all records and gives you access to them for verification. */ class TestLogger extends AbstractLogger { public $records = []; public $recordsByLevel = []; public function log($level, $message, array $context = []): void { $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(static 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(static function ($rec) use ($message) { return strpos($rec['message'], $message) !== false; }, $level); } public function hasRecordThatMatches($regex, $level) { return $this->hasRecordThatPasses(static 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 ' . static::class . '::' . $method . '()'); } public function reset() { $this->records = []; $this->recordsByLevel = []; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Cookie | Folder | 0755 |
|
|
Exception | Folder | 0755 |
|
|
Handler | Folder | 0755 |
|
|
ClientTest.php | File | 30.54 KB | 0644 |
|
HandlerStackTest.php | File | 7.44 KB | 0644 |
|
Helpers.php | File | 975 B | 0644 |
|
HttplugIntegrationTest.php | File | 369 B | 0644 |
|
InternalUtilsTest.php | File | 569 B | 0644 |
|
MessageFormatterTest.php | File | 4.12 KB | 0644 |
|
MiddlewareTest.php | File | 9.87 KB | 0644 |
|
PoolTest.php | File | 6.41 KB | 0644 |
|
PrepareBodyMiddlewareTest.php | File | 5.34 KB | 0644 |
|
RedirectMiddlewareTest.php | File | 20.44 KB | 0644 |
|
RetryMiddlewareTest.php | File | 3 KB | 0644 |
|
Server.php | File | 6.12 KB | 0644 |
|
TestLogger.php | File | 2.8 KB | 0644 |
|
TransferStatsTest.php | File | 995 B | 0644 |
|
UtilsTest.php | File | 5.48 KB | 0644 |
|
bootstrap-phpstan.php | File | 173 B | 0644 |
|
bootstrap.php | File | 1.05 KB | 0644 |
|
server.js | File | 8.1 KB | 0644 |
|