1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BlueEventTest; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use BlueEvent\Event\Base\EventLog; |
7
|
|
|
use BlueEvent\Event\Base\EventDispatcher; |
8
|
|
|
|
9
|
|
|
class EventLogTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* store generated log file path |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $logPath; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* test that log file was created correctly |
20
|
|
|
*/ |
21
|
|
|
public function testEventLog() |
22
|
|
|
{ |
23
|
|
|
$instance = new EventLog([ |
24
|
|
|
'log_object' => false, |
25
|
|
|
'log_all_events' => false, |
26
|
|
|
'log_events' => true, |
27
|
|
|
'log_config' => [ |
28
|
|
|
'log_path' => $this->logPath, |
29
|
|
|
'level' => 'debug', |
30
|
|
|
], |
31
|
|
|
]); |
32
|
|
|
|
33
|
|
|
$instance->logEvents[] = 'some_name'; |
34
|
|
|
|
35
|
|
|
$this->assertFileDoesNotExist($this->logPath . EventDispatcherTest::EVENT_LOG_NAME); |
36
|
|
|
$instance->makeLogEvent('some_name', 'some_listener', EventDispatcher::EVENT_STATUS_OK); |
37
|
|
|
$this->assertFileExists($this->logPath . EventDispatcherTest::EVENT_LOG_NAME); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* test that log file was created correctly |
43
|
|
|
*/ |
44
|
|
|
public function testEventLogWithAllEvents() |
45
|
|
|
{ |
46
|
|
|
$instance = new EventLog([ |
47
|
|
|
'log_object' => false, |
48
|
|
|
'log_all_events' => true, |
49
|
|
|
'log_events' => true, |
50
|
|
|
'log_config' => [ |
51
|
|
|
'log_path' => $this->logPath, |
52
|
|
|
'level' => 'debug', |
53
|
|
|
], |
54
|
|
|
]); |
55
|
|
|
|
56
|
|
|
$instance->logEvents[] = 'some_name'; |
57
|
|
|
$instance->logEvents[] = 'some_name_2'; |
58
|
|
|
|
59
|
|
|
$this->assertFileDoesNotExist($this->logPath . EventDispatcherTest::EVENT_LOG_NAME); |
60
|
|
|
$instance->makeLogEvent('some_name', 'some_listener', EventDispatcher::EVENT_STATUS_OK); |
61
|
|
|
$instance->makeLogEvent( |
62
|
|
|
'some_name_2', |
63
|
|
|
function () { |
64
|
|
|
}, |
65
|
|
|
EventDispatcher::EVENT_STATUS_OK |
66
|
|
|
); |
67
|
|
|
$this->assertFileExists($this->logPath . EventDispatcherTest::EVENT_LOG_NAME); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testEventLogWithGivenLogObject() |
71
|
|
|
{ |
72
|
|
|
$instance = new EventLog([ |
73
|
|
|
'log_object' => false, |
74
|
|
|
'log_all_events' => false, |
75
|
|
|
'log_events' => true, |
76
|
|
|
'log_config' => [ |
77
|
|
|
'log_path' => $this->logPath, |
78
|
|
|
'level' => 'debug', |
79
|
|
|
'storage' => \SimpleLog\Storage\File::class, |
80
|
|
|
], |
81
|
|
|
]); |
82
|
|
|
|
83
|
|
|
$instance->logEvents[] = 'some_name'; |
84
|
|
|
|
85
|
|
|
$this->assertFileDoesNotExist($this->logPath . EventDispatcherTest::EVENT_LOG_NAME); |
86
|
|
|
$instance->makeLogEvent('some_name', ['class', 'method'], EventDispatcher::EVENT_STATUS_OK); |
87
|
|
|
$this->assertFileExists($this->logPath . EventDispatcherTest::EVENT_LOG_NAME); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* actions launched before test starts |
92
|
|
|
*/ |
93
|
|
|
protected function setUp(): void |
94
|
|
|
{ |
95
|
|
|
$this->logPath = __DIR__ . '/log'; |
96
|
|
|
|
97
|
|
|
$this->clearLog(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
protected function clearLog() |
101
|
|
|
{ |
102
|
|
|
$logFile = $this->logPath . EventDispatcherTest::EVENT_LOG_NAME; |
103
|
|
|
|
104
|
|
|
if (file_exists($logFile)) { |
105
|
|
|
unlink($logFile); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* actions launched after test was finished |
111
|
|
|
*/ |
112
|
|
|
protected function tearDown(): void |
113
|
|
|
{ |
114
|
|
|
$this->clearLog(); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|