Completed
Pull Request — master (#176)
by
unknown
02:01
created

RequestListenerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 68
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataArray() 0 15 1
A getSetProfilesData() 0 12 1
A testSetProfiles() 0 19 1
1
<?php
2
3
namespace ONGR\SettingsBundle\Tests\Functional\EventListener;
4
5
use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase;
6
use ONGR\SettingsBundle\Service\SettingsManager;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
9
10
class RequestListenerTest extends AbstractElasticsearchTestCase
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected function getDataArray()
16
    {
17
        return [
18
            'settings' => [
19
                'setting' => [
20
                    [
21
                        'name' => 'foo',
22
                        'profile' => ['default'],
23
                        'type' => 'bool',
24
                        'value' => true,
25
                    ],
26
                ],
27
            ],
28
        ];
29
    }
30
31
32
    /**
33
     * Data provider for testSetProfiles()
34
     *
35
     * @return array
36
     */
37
    public function getSetProfilesData()
38
    {
39
        $out = [];
40
41
        // Case #0 - set profiles to manager on master request
42
        $out[] = ['requestType' => 1, 'expected' => ['foo', 'bar']];
43
44
        // Case #1 - dont set profiles to manager on non master request
45
        $out[] = ['requestType' => 2, 'expected' => []];
46
47
        return $out;
48
    }
49
50
    /**
51
     * Check if find by works as expected.
52
     *
53
     * @param int   $requestType
54
     * @param array $expected
55
     *
56
     * @dataProvider getSetProfilesData()
57
     */
58
    public function testSetProfiles($requestType, $expected)
59
    {
60
        /** @var SettingsManager $manager */
61
        $manager  = $this->getContainer()->get('ongr_settings.settings_manager');
62
        $profileCookie   = $this->getContainer()->get('ongr_settings.cookie.active_profiles');
63
        $experimentCookie   = $this->getContainer()->get('ongr_settings.cookie.active_experiments');
64
        $listener = $this->getContainer()->get('ongr_settings.request_listener');
65
        $activeProfiles = ['foo', 'bar'];
66
67
        $this->assertEmpty($manager->getActiveProfiles());
68
69
        $profileCookie->load(json_encode($activeProfiles));
70
        $experimentCookie->load('');
71
        $listener->onKernelRequest(
72
            new GetResponseEvent(static::$kernel, new Request(), $requestType)
73
        );
74
75
        $this->assertEquals($expected, $manager->getActiveProfiles());
76
    }
77
}
78