1 | <?php |
||
11 | class LoggerTest extends TestCase |
||
12 | { |
||
13 | /** |
||
14 | * @noinspection PhpUsageOfSilenceOperatorInspection |
||
15 | */ |
||
16 | public function testLogging() |
||
17 | { |
||
18 | $logfile = sys_get_temp_dir() . '/LoggerTest'; |
||
19 | @unlink($logfile); |
||
20 | |||
21 | $test = new TestPlugin(); |
||
22 | $auth = new Auth(); |
||
23 | $auth->addPlugin($test); |
||
24 | |||
25 | $globalLogger = new Logger('GlobalLogger'); |
||
26 | $globalLogger->pushHandler(new StreamHandler($logfile, Logger::WARNING)); |
||
27 | |||
28 | $internalLogger = new Logger('InternalLogger'); |
||
29 | $internalLogger->pushHandler(new StreamHandler($logfile, Logger::WARNING)); |
||
30 | |||
31 | $auth->setLogger($globalLogger); |
||
32 | $this->assertEquals($globalLogger, $auth->getLogger()); |
||
33 | |||
34 | /* It can use the global logger... */ |
||
35 | $this->assertFalse(@file_get_contents($logfile)); |
||
36 | $test->testWarning("Logger Test!"); |
||
37 | $this->assertStringContainsString("Logger Test!", @file_get_contents($logfile)); |
||
38 | $this->assertStringContainsString("GlobalLogger", @file_get_contents($logfile)); |
||
39 | @unlink($logfile); |
||
40 | |||
41 | /* ... Or its own logger! */ |
||
42 | $this->assertFalse(@file_get_contents($logfile)); |
||
43 | $test->setLogger($internalLogger); |
||
44 | $test->testWarning("Logger Test!"); |
||
45 | $this->assertStringContainsString("Logger Test!", @file_get_contents($logfile)); |
||
46 | $this->assertStringContainsString("InternalLogger", @file_get_contents($logfile)); |
||
47 | @unlink($logfile); |
||
48 | } |
||
49 | } |
||
50 |