-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestLogger.php
64 lines (55 loc) · 1.41 KB
/
TestLogger.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace VStelmakh\PsrTestLogger;
use Psr\Log\AbstractLogger;
use VStelmakh\PsrTestLogger\Log\Collection;
use VStelmakh\PsrTestLogger\Log\Log;
use VStelmakh\PsrTestLogger\Match\Assert;
use VStelmakh\PsrTestLogger\Match\Filter;
class TestLogger extends AbstractLogger
{
private Collection $logs;
public function __construct()
{
$this->logs = new Collection();
}
/**
* @param $level
* @param \Stringable|string $message
* @param array<mixed> $context
* @return void
*/
public function log($level, \Stringable|string $message, array $context = []): void
{
$log = new Log($level, $message, $context);
$this->logs->add($log);
}
/**
* Returns all logs containing in logger.
*
* @return array<Log>
*/
public function getLogs(): array
{
return $this->logs->toArray();
}
/**
* Fluent interface to assert logger contains logs with specified conditions.
*
* @param string $message Custom assertation error message.
* @return Assert
*/
public function assert(string $message = ''): Assert
{
return new Assert(clone $this->logs, $message);
}
/**
* Fluent interface to filter logs by conditions.
*
* @return Filter
*/
public function filter(): Filter
{
return new Filter(clone $this->logs);
}
}