1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use SimpleLog\Log as SimpleLog; |
7
|
|
|
use BlueRegister\Log; |
8
|
|
|
|
9
|
|
|
class LogTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* name of test event log file |
13
|
|
|
*/ |
14
|
|
|
const REGISTER_LOG_NAME = '/debug.log'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $logPath; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* actions launched before test starts |
23
|
|
|
*/ |
24
|
|
|
protected function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->logPath = __DIR__ . '/log'; |
27
|
|
|
|
28
|
|
|
$this->clearLog(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @expectedException \LogicException |
33
|
|
|
* @expectedExceptionMessage Log should be instance of SimpleLog\LogInterface: Test\TestClass\SimpleClass |
34
|
|
|
*/ |
35
|
|
|
public function testIncorrectLogObject() |
36
|
|
|
{ |
37
|
|
|
new Log(TestClass\SimpleClass::class); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @expectedException \LogicException |
42
|
|
|
* @expectedExceptionMessage Class don't exists: SomeClass |
43
|
|
|
*/ |
44
|
|
|
public function testIncorrectLogObjectFromNoneExistingClass() |
45
|
|
|
{ |
46
|
|
|
new Log('SomeClass'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @expectedException \LogicException |
51
|
|
|
* @expectedExceptionMessage Cannot create Log instance: Test\TestClass\SimpleClass |
52
|
|
|
*/ |
53
|
|
|
public function testCreateLogInstanceFromIncorrectObject() |
54
|
|
|
{ |
55
|
|
|
new Log(new \Test\TestClass\SimpleClass); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testCreateLogObject() |
59
|
|
|
{ |
60
|
|
|
$log1 = new Log(new SimpleLog); |
61
|
|
|
$log2 = new Log(SimpleLog::class); |
62
|
|
|
|
63
|
|
|
$this->assertInstanceOf(Log::class, $log1); |
64
|
|
|
$this->assertInstanceOf(Log::class, $log2); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testLogMessages() |
68
|
|
|
{ |
69
|
|
|
$this->clearLog(); |
70
|
|
|
$simpleLog = new SimpleLog; |
71
|
|
|
$simpleLog->setOption('log_path', $this->logPath) |
72
|
|
|
->setOption('level', 'debug'); |
73
|
|
|
|
74
|
|
|
$log = new Log($simpleLog); |
75
|
|
|
$log->makeLog('Test log message'); |
76
|
|
|
|
77
|
|
|
$this->assertFileExists($this->logFile()); |
78
|
|
|
$this->clearLog(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
protected function logFile() |
85
|
|
|
{ |
86
|
|
|
return $this->logPath . self::REGISTER_LOG_NAME; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
protected function clearLog() |
90
|
|
|
{ |
91
|
|
|
if (file_exists($this->logFile())) { |
92
|
|
|
unlink($this->logFile()); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* actions launched after test was finished |
98
|
|
|
*/ |
99
|
|
|
protected function tearDown() |
100
|
|
|
{ |
101
|
|
|
$this->clearLog(); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|