1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Spiral Framework. |
5
|
|
|
* |
6
|
|
|
* @license MIT |
7
|
|
|
* @author Anton Titov (Wolfy-J) |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Spiral\Tests\Monolog; |
13
|
|
|
|
14
|
|
|
use Monolog\Logger; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
use Psr\Log\NullLogger; |
17
|
|
|
use Spiral\Boot\BootloadManager; |
18
|
|
|
use Spiral\Config\ConfigManager; |
19
|
|
|
use Spiral\Config\ConfiguratorInterface; |
20
|
|
|
use Spiral\Config\LoaderInterface; |
21
|
|
|
use Spiral\Core\Container; |
22
|
|
|
use Spiral\Core\ContainerScope; |
23
|
|
|
use Spiral\Logger\ListenerRegistry; |
24
|
|
|
use Spiral\Logger\ListenerRegistryInterface; |
25
|
|
|
use Spiral\Logger\Traits\LoggerTrait; |
26
|
|
|
use Spiral\Monolog\Bootloader\MonologBootloader; |
27
|
|
|
use Spiral\Monolog\Config\MonologConfig; |
28
|
|
|
|
29
|
|
|
class TraitTest extends TestCase |
30
|
|
|
{ |
31
|
|
|
use LoggerTrait; |
32
|
|
|
|
33
|
|
|
public function setUp(): void |
34
|
|
|
{ |
35
|
|
|
$this->logger = null; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testNoScope(): void |
39
|
|
|
{ |
40
|
|
|
$logger = $this->getLogger(); |
41
|
|
|
$this->assertInstanceOf(NullLogger::class, $this->getLogger()); |
42
|
|
|
$this->assertSame($logger, $this->getLogger()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testSetLogger(): void |
46
|
|
|
{ |
47
|
|
|
$logger = new NullLogger(); |
48
|
|
|
$this->setLogger($logger); |
49
|
|
|
$this->assertSame($logger, $this->getLogger()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testScope(): void |
53
|
|
|
{ |
54
|
|
|
$container = new Container(); |
55
|
|
|
$container->bind(ConfiguratorInterface::class, new ConfigManager( |
|
|
|
|
56
|
|
|
new class() implements LoaderInterface { |
57
|
|
|
public function has(string $section): bool |
58
|
|
|
{ |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function load(string $section): array |
63
|
|
|
{ |
64
|
|
|
return []; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
)); |
68
|
|
|
$container->get(BootloadManager::class)->bootload([MonologBootloader::class]); |
69
|
|
|
$container->bind(MonologConfig::class, new MonologConfig()); |
|
|
|
|
70
|
|
|
$container->bind(ListenerRegistryInterface::class, new ListenerRegistry()); |
|
|
|
|
71
|
|
|
|
72
|
|
|
ContainerScope::runScope($container, function (): void { |
73
|
|
|
$this->assertInstanceOf(Logger::class, $this->getLogger()); |
74
|
|
|
$this->assertSame(self::class, $this->getLogger()->getName()); |
|
|
|
|
75
|
|
|
}); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|