-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestLoggerForSymfony.php
37 lines (31 loc) · 1.07 KB
/
TestLoggerForSymfony.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
<?php
declare(strict_types=1);
namespace DobroSite\PHPUnit\PSR3\Symfony;
use DobroSite\PHPUnit\PSR3\TestLogger;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
trait TestLoggerForSymfony
{
abstract protected static function getContainer(): ContainerInterface;
/**
* @throws ServiceNotFoundException
* @throws ServiceCircularReferenceException
*/
protected function getLogger(): TestLogger
{
$client = self::getContainer()->get(LoggerInterface::class);
\assert(
$client instanceof TestLogger,
\sprintf(
'Service "%s" should be an instance of %s, but it is %s. '
. 'You should replace it in the test configuration.',
LoggerInterface::class,
TestLogger::class,
$client::class
)
);
return $client;
}
}