Repository navigation
Expand file tree
/
Copy pathLogTest.php
More file actions
79 lines (57 loc) · 2.29 KB
/
Copy pathLogTest.php
File metadata and controls
79 lines (57 loc) · 2.29 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Phprest\Test\ErrorHandler\Handler;
use ErrorException;
use Exception;
use Phprest\ErrorHandler\Handler\Log;
use Phprest\Exception\BadRequest;
use PHPUnit\Framework\TestCase;
use Monolog\Handler\TestHandler;
use Monolog\Logger;
class LogTest extends TestCase
{
protected TestHandler $monologHandler;
protected Logger $monolog;
protected Log $logHandler;
public function setUp(): void
{
$this->monologHandler = new TestHandler();
$this->monolog = new Logger('test', [$this->monologHandler]);
$this->logHandler = new Log($this->monolog);
}
public function testSimpleException(): void
{
$this->assertFalse($this->monologHandler->hasCriticalRecords());
$this->logHandler->handle(new Exception('test exception'));
$this->assertTrue($this->monologHandler->hasCriticalRecords());
}
public function testPhprestException(): void
{
$this->assertFalse($this->monologHandler->hasCriticalRecords());
$this->logHandler->handle(new BadRequest(9, ['a detail']));
$this->assertTrue($this->monologHandler->hasCriticalRecords());
}
public function testErrorExceptionErrorLog(): void
{
$this->assertFalse($this->monologHandler->hasErrorRecords());
$this->logHandler->handle(new ErrorException('test exception', 0, E_ERROR));
$this->assertTrue($this->monologHandler->hasErrorRecords());
}
public function testWarningExceptionErrorLog(): void
{
$this->assertFalse($this->monologHandler->hasWarningRecords());
$this->logHandler->handle(new ErrorException('test exception', 0, E_WARNING));
$this->assertTrue($this->monologHandler->hasWarningRecords());
}
public function testNoticeExceptionErrorLog(): void
{
$this->assertFalse($this->monologHandler->hasNoticeRecords());
$this->logHandler->handle(new ErrorException('test exception', 0, E_NOTICE));
$this->assertTrue($this->monologHandler->hasNoticeRecords());
}
public function testInfoExceptionErrorLog(): void
{
$this->assertFalse($this->monologHandler->hasInfoRecords());
$this->logHandler->handle(new ErrorException('test exception', 0, E_STRICT));
$this->assertTrue($this->monologHandler->hasInfoRecords());
}
}