Completed
Pull Request — master (#181)
by
unknown
17:45
created

RequestListenerTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace ONGR\SettingsBundle\Tests\Functional;
4
5
use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
8
use Symfony\Component\HttpKernel\HttpKernelInterface;
9
10
class RequestListenerTest extends AbstractElasticsearchTestCase
11
{
12
    protected function getDataArray()
13
    {
14
        return [
15
            'settings' => [
16
                'setting' => [
17
                    [
18
                        '_id' => '1',
19
                        'name' => 'foo',
20
                        'profile' => ['not-profile'],
21
                        'value' => true,
22
                        'type' => 'bool',
23
                    ],
24
                    [
25
                        '_id' => '2',
26
                        'name' => 'bar',
27
                        'profile' => ['profile'],
28
                        'value' => true,
29
                        'type' => 'bool',
30
                    ],
31
                ]
32
            ]
33
        ];
34
    }
35
36
    public function testOnKernelRequest()
37
    {
38
        $cookie = $this->getContainer()->get('ongr_settings.cookie.active_experiments');
39
        $cookie->load(null);
40
        $cookie = $this->getContainer()->get('ongr_settings.cookie.active_profiles');
41
        $cookie->load(json_encode(['profile']));
42
        $listener = $this->getContainer()->get('ongr_settings.request_listener');
43
        $request = new Request();
44
        $request->cookies->set(
45
            $this->getContainer()->getParameter('ongr_settings.cookie.active_profiles.name'),
46
            serialize(['profile'])
47
        );
48
        $event = new GetResponseEvent(static::$kernel, $request, HttpKernelInterface::MASTER_REQUEST);
49
        $listener->onKernelRequest($event);
50
        $extension = $this->getContainer()->get('ongr_settings.setting_extension');
51
52
        $this->assertTrue($extension->getSettingValue('bar'));
53
        $this->assertFalse($extension->getSettingValue('foo'));
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    protected function tearDown()
60
    {
61
        parent::tearDown();
62
63
        $this->getContainer()->get('ongr_settings.settings_manager')->getCache()->deleteAll();
64
    }
65
}
66