-
Notifications
You must be signed in to change notification settings - Fork 0
/
TraitTest.php
73 lines (61 loc) · 2.21 KB
/
TraitTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
namespace Spiral\Tests\Monolog;
use Monolog\Logger;
use Psr\Log\NullLogger;
use Spiral\Boot\BootloadManager\StrategyBasedBootloadManager;
use Spiral\Boot\FinalizerInterface;
use Spiral\Config\ConfigManager;
use Spiral\Config\ConfiguratorInterface;
use Spiral\Config\LoaderInterface;
use Spiral\Core\ContainerScope;
use Spiral\Logger\ListenerRegistry;
use Spiral\Logger\ListenerRegistryInterface;
use Spiral\Logger\Traits\LoggerTrait;
use Spiral\Monolog\Bootloader\MonologBootloader;
use Spiral\Monolog\Config\MonologConfig;
class TraitTest extends BaseTest
{
use LoggerTrait;
public function setUp(): void
{
parent::setUp();
$this->logger = null;
}
public function testNoScope(): void
{
$logger = $this->getLogger();
$this->assertInstanceOf(NullLogger::class, $this->getLogger());
$this->assertSame($logger, $this->getLogger());
}
public function testSetLogger(): void
{
$logger = new NullLogger();
$this->setLogger($logger);
$this->assertSame($logger, $this->getLogger());
}
public function testScope(): void
{
$this->container->bind(FinalizerInterface::class, $finalizer = \Mockery::mock(FinalizerInterface::class));
$finalizer->shouldReceive('addFinalizer')->once();
$this->container->bind(ConfiguratorInterface::class, new ConfigManager(
new class() implements LoaderInterface {
public function has(string $section): bool
{
return false;
}
public function load(string $section): array
{
return [];
}
}
));
$this->container->get(StrategyBasedBootloadManager::class)->bootload([MonologBootloader::class]);
$this->container->bind(MonologConfig::class, new MonologConfig());
$this->container->bind(ListenerRegistryInterface::class, new ListenerRegistry());
ContainerScope::runScope($this->container, function (): void {
$this->assertInstanceOf(Logger::class, $this->getLogger());
$this->assertSame(self::class, $this->getLogger()->getName());
});
}
}