Completed
Pull Request — master (#177)
by
unknown
02:48
created

ExperimentListenerTest::getDataArray()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 29
rs 8.8571
cc 1
eloc 18
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 ExperimentListenerTest extends AbstractElasticsearchTestCase
11
{
12
    protected function getDataArray()
13
    {
14
        return [
15
            'settings' => [
16
                'setting' => [
17
                    [
18
                        '_id' => '5',
19
                        'name' => 'active_experiments',
20
                        'value' => ['bar_experiment'],
21
                        'type' => 'hidden',
22
                    ],
23
                    [
24
                        '_id' => '6',
25
                        'name' => 'foo_experiment',
26
                        'profile' => ['profile1', 'profile2'],
27
                        'value' => ['test_experiment_value'],
28
                        'type' => 'experiment',
29
                    ],
30
                    [
31
                        '_id' => '7',
32
                        'name' => 'bar_experiment',
33
                        'profile' => ['profile1'],
34
                        'value' => '{"Clients":{"types":["Browser"],"clients":["Safari"]}}',
35
                        'type' => 'experiment',
36
                    ],
37
                ]
38
            ]
39
        ];
40
    }
41
42
    public function testOnKernelRequest()
43
    {
44
        $this->getContainer()->get('ongr_settings.settings_manager')
45
            ->setActiveExperimentsSettingName('active_experiments');
46
47
        $cookie = $this->getContainer()->get('ongr_settings.cookie.active_experiments');
48
        $cookie->load(null);
49
        $listener = $this->getContainer()->get('ongr_settings.experiment_listener');
50
        $request = new Request();
51
        $request->headers->set(
52
            'User-Agent',
53
            'AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50'
54
        );
55
        $event = new GetResponseEvent(static::$kernel, $request, HttpKernelInterface::MASTER_REQUEST);
56
        $listener->onKernelRequest($event);
57
        $this->assertEquals(['profile1'], $cookie->getValue());
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    protected function tearDown()
64
    {
65
        parent::tearDown();
66
67
        $this->getContainer()->get('ongr_settings.settings_manager')->getCache()->deleteAll();
68
    }
69
}
70