|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Amesplash\CampaignMonitorLog\Unit; |
|
4
|
|
|
|
|
5
|
|
|
use Psr\Log\LoggerInterface; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use Eloquent\Phony\Phpunit\Phony; |
|
8
|
|
|
use Amesplash\CampaignMonitorLog\LogDecorator; |
|
9
|
|
|
use Amesplash\CampaignMonitorLog\Exception\InvalidArgumentException; |
|
10
|
|
|
|
|
11
|
|
|
class LogDecoratorTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function invalidLogLevels() : array |
|
14
|
|
|
{ |
|
15
|
|
|
return [ |
|
16
|
|
|
['extreme'], |
|
17
|
|
|
['systemdown'], |
|
18
|
|
|
['100.00'], |
|
19
|
|
|
[600], |
|
20
|
|
|
['SERVER_ERROR'] |
|
21
|
|
|
]; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param mixed $ttl |
|
26
|
|
|
* @dataProvider invalidLogLevels |
|
27
|
|
|
* @throws \Exception |
|
28
|
|
|
*/ |
|
29
|
|
|
public function testItThrowsAnExceptionWithInvalidLogLevels($level) |
|
30
|
|
|
{ |
|
31
|
|
|
$psrLogHandle = Phony::partialMock(LoggerInterface::class, null); |
|
32
|
|
|
$psrLogMock = $psrLogHandle->get(); |
|
33
|
|
|
$psrLogDecorator = new LogDecorator($psrLogMock); |
|
34
|
|
|
|
|
35
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
36
|
|
|
$psrLogDecorator->log_message('Log Message', 'PHPUnit Test', $level); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testItLogsAMessageWithGivenDefaultContext() |
|
40
|
|
|
{ |
|
41
|
|
|
$defaultContext = [ |
|
42
|
|
|
'Test Method' => 'test_it_logs_a_message_with_given_context', |
|
43
|
|
|
'Parent Module' => 'PHPUnit' |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
$psrLogHandle = Phony::partialMock(LoggerInterface::class, null); |
|
47
|
|
|
|
|
48
|
|
|
$psrLogMock = $psrLogHandle->get(); |
|
49
|
|
|
$psrLogDecorator = new LogDecorator($psrLogMock, $defaultContext); |
|
50
|
|
|
|
|
51
|
|
|
$psrLogDecorator->log_message('PHPunit Log Message', 'PHPUnit', 1000); |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
$psrLogHandle->log->calledWith( |
|
55
|
|
|
'debug', |
|
56
|
|
|
'PHPunit Log Message', |
|
57
|
|
|
$defaultContext + ['module' => 'PHPUnit'] |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|