1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Dziki\MonologSentryBundle\Tests\Functional; |
6
|
|
|
|
7
|
|
|
use Dziki\MonologSentryBundle\MonologSentryBundle; |
8
|
|
|
use Dziki\MonologSentryBundle\Processor\TagAppending; |
9
|
|
|
use Dziki\MonologSentryBundle\SubscribedProcessor\UserDataAppending; |
10
|
|
|
use Dziki\MonologSentryBundle\UserAgent\CachedParser; |
11
|
|
|
use Dziki\MonologSentryBundle\UserAgent\PhpUserAgentParser; |
12
|
|
|
use Nyholm\BundleTest\BaseBundleTestCase; |
13
|
|
|
use Nyholm\BundleTest\CompilerPass\PublicServicePass; |
14
|
|
|
use Psr\Log\LoggerInterface; |
15
|
|
|
use Symfony\Bundle\MonologBundle\MonologBundle; |
16
|
|
|
use Symfony\Bundle\SecurityBundle\SecurityBundle; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
19
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
20
|
|
|
|
21
|
|
|
class BundleInitializationTest extends BaseBundleTestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @test |
25
|
|
|
*/ |
26
|
|
|
public function checkDefaultServicesLoaded(): void |
27
|
|
|
{ |
28
|
|
|
// Create a new Kernel |
29
|
|
|
$kernel = $this->createKernel(); |
30
|
|
|
|
31
|
|
|
$kernel->addBundle(SecurityBundle::class); |
32
|
|
|
$kernel->addBundle(MonologBundle::class); |
33
|
|
|
|
34
|
|
|
$kernel->addConfigFile(__DIR__ . '/config.yaml'); |
35
|
|
|
|
36
|
|
|
// Make all services public |
37
|
|
|
$kernel->addCompilerPasses([new PublicServicePass()]); |
38
|
|
|
|
39
|
|
|
// Boot the kernel. |
40
|
|
|
$kernel->boot(); |
41
|
|
|
|
42
|
|
|
// Get the container |
43
|
|
|
$container = $this->getContainer(); |
44
|
|
|
|
45
|
|
|
$this->logIn($container); |
46
|
|
|
|
47
|
|
|
$userDataAppending = $container->get('dziki.monolog_sentry_bundle.user_data_appending_subscribed_processor'); |
48
|
|
|
$this->assertInstanceOf(UserDataAppending::class, $userDataAppending); |
49
|
|
|
|
50
|
|
|
$cachedParser = $container->get(CachedParser::class); |
51
|
|
|
$this->assertInstanceOf(CachedParser::class, $cachedParser); |
52
|
|
|
|
53
|
|
|
$phpUserAgentParser = $container->get(PhpUserAgentParser::class); |
54
|
|
|
$this->assertInstanceOf(PhpUserAgentParser::class, $phpUserAgentParser); |
55
|
|
|
|
56
|
|
|
foreach (['symfony_version', 'commit', 'environment'] as $tagName) { |
57
|
|
|
$tagService = $container->get("dziki.monolog_sentry_bundle.{$tagName}_appending_processor"); |
58
|
|
|
$this->assertInstanceOf(TagAppending::class, $tagService); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** @var LoggerInterface $logger */ |
62
|
|
|
$logger = $container->get('logger'); |
63
|
|
|
|
64
|
|
|
$logger->info('some log'); |
65
|
|
|
|
66
|
|
|
$kernel->handle(new Request()); |
67
|
|
|
|
68
|
|
|
$logger->error('and now everything should be covered :)'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function logIn(ContainerInterface $container): void |
72
|
|
|
{ |
73
|
|
|
$session = $container->get('session'); |
74
|
|
|
|
75
|
|
|
$firewallName = 'main'; |
76
|
|
|
// if you don't define multiple connected firewalls, the context defaults to the firewall name |
77
|
|
|
// See https://symfony.com/doc/current/reference/configuration/security.html#firewall-context |
78
|
|
|
$firewallContext = $firewallName; |
79
|
|
|
|
80
|
|
|
// you may need to use a different token class depending on your application. |
81
|
|
|
// for example, when using Guard authentication you must instantiate PostAuthenticationGuardToken |
82
|
|
|
$token = new UsernamePasswordToken('test', 'test', $firewallName, ['ROLE_ADMIN']); |
83
|
|
|
$session->set('_security_' . $firewallContext, serialize($token)); |
84
|
|
|
$session->save(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
protected function getBundleClass(): string |
88
|
|
|
{ |
89
|
|
|
return MonologSentryBundle::class; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|