-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathBuildLoggerTest.php
More file actions
88 lines (67 loc) · 2.17 KB
/
Copy pathBuildLoggerTest.php
File metadata and controls
88 lines (67 loc) · 2.17 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
80
81
82
83
84
85
86
87
88
<?php
declare(strict_types=1);
namespace Tests\PHPCensor\Logging;
use Exception;
use PHPCensor\Logging\BuildLogger;
use PHPCensor\Model\Build;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
class BuildLoggerTest extends TestCase
{
use ProphecyTrait;
private BuildLogger $testedBuildLogger;
private $logger;
private $build;
protected function setUp(): void
{
parent::setUp();
$this->logger = $this->prophesize(LoggerInterface::class);
$this->build = $this->prophesize(Build::class);
$this->testedBuildLogger = new BuildLogger(
$this->logger->reveal(),
$this->build->reveal()
);
}
public function testLog_CallsWrappedLogger(): void
{
$level = LogLevel::NOTICE;
$message = "Testing";
$contextIn = [];
$this->logger
->log($level, $message, Argument::type('array'))
->shouldBeCalledTimes(1);
$this->testedBuildLogger->log($message, $level, $contextIn);
}
public function testLog_CallsWrappedLoggerForEachMessage(): void
{
$level = LogLevel::NOTICE;
$message = ["One", "Two", "Three"];
$contextIn = [];
$this->logger
->log($level, "One", Argument::type('array'))
->shouldBeCalledTimes(1);
$this->logger
->log($level, "Two", Argument::type('array'))
->shouldBeCalledTimes(1);
$this->logger
->log($level, "Three", Argument::type('array'))
->shouldBeCalledTimes(1);
$this->testedBuildLogger->log($message, $level, $contextIn);
}
public function testLogFailure_AddsExceptionContext(): void
{
$message = "Testing";
$exception = new Exception("Expected Exception");
$this->logger
->log(
Argument::type('string'),
Argument::type('string'),
Argument::withEntry('exception', $exception)
)
->shouldBeCalledTimes(1);
$this->testedBuildLogger->logFailure($message, $exception);
}
}