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