1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Dziki\MonologSentryBundle\Tests\Functional; |
6
|
|
|
|
7
|
|
|
use Dziki\MonologSentryBundle\MonologSentryBundle; |
8
|
|
|
use Nyholm\BundleTest\BaseBundleTestCase; |
9
|
|
|
use Nyholm\BundleTest\CompilerPass\PublicServicePass; |
10
|
|
|
use Symfony\Bundle\MonologBundle\MonologBundle; |
11
|
|
|
use Symfony\Bundle\SecurityBundle\SecurityBundle; |
12
|
|
|
use Symfony\Component\DependencyInjection\Container; |
13
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
14
|
|
|
|
15
|
|
|
class BundleInitializationTest extends BaseBundleTestCase |
16
|
|
|
{ |
17
|
|
|
public function testInitBundle() |
18
|
|
|
{ |
19
|
|
|
// Create a new Kernel |
20
|
|
|
$kernel = $this->createKernel(); |
21
|
|
|
|
22
|
|
|
$kernel->addBundle(SecurityBundle::class); |
23
|
|
|
$kernel->addBundle(MonologBundle::class); |
24
|
|
|
|
25
|
|
|
$kernel->addConfigFile(__DIR__ . '/config.yaml'); |
26
|
|
|
|
27
|
|
|
// Make all services public |
28
|
|
|
$kernel->addCompilerPasses([new PublicServicePass()]); |
29
|
|
|
|
30
|
|
|
// Boot the kernel. |
31
|
|
|
$kernel->boot(); |
32
|
|
|
|
33
|
|
|
// Get the container |
34
|
|
|
$container = $this->getContainer(); |
35
|
|
|
|
36
|
|
|
$this->logIn($container); |
37
|
|
|
|
38
|
|
|
$this->assertNotNull($container->get('dziki.monolog_sentry_bundle.user_data_appending_subscribed_processor')); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
private function logIn(Container $container) |
42
|
|
|
{ |
43
|
|
|
$session = $container->get('session'); |
44
|
|
|
|
45
|
|
|
$firewallName = 'main'; |
46
|
|
|
// if you don't define multiple connected firewalls, the context defaults to the firewall name |
47
|
|
|
// See https://symfony.com/doc/current/reference/configuration/security.html#firewall-context |
48
|
|
|
$firewallContext = $firewallName; |
49
|
|
|
|
50
|
|
|
// you may need to use a different token class depending on your application. |
51
|
|
|
// for example, when using Guard authentication you must instantiate PostAuthenticationGuardToken |
52
|
|
|
$token = new UsernamePasswordToken('test', 'test', $firewallName, ['ROLE_ADMIN']); |
53
|
|
|
$session->set('_security_' . $firewallContext, serialize($token)); |
54
|
|
|
$session->save(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function getBundleClass() |
58
|
|
|
{ |
59
|
|
|
return MonologSentryBundle::class; |
60
|
|
|
} |
61
|
|
|
} |