Passed
Pull Request — master (#4)
by Francis
01:43
created

LoggerTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 5
dl 0
loc 38
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Vectorface\Tests\Auth;
4
5
use Vectorface\Auth\Auth;
6
use Monolog\Logger;
7
use Monolog\Handler\StreamHandler;
8
use PHPUnit\Framework\TestCase;
9
use Vectorface\Tests\Auth\Helpers\TestPlugin;
10
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