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

RequestListener::getDataArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace ONGR\SettingsBundle\Tests\Functional;
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 RequestListener 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
        $cookie   = $this->getContainer()->get('ongr_settings.cookie.active_profiles');
63
        $listener = $this->getContainer()->get('ongr_settings.request_listener');
64
        $activeProfiles = ['foo', 'bar'];
65
66
        $this->assertEmpty($manager->getActiveProfiles());
67
68
        $cookie->load(json_encode($activeProfiles));
69
        $listener->onKernelRequest(
70
            new GetResponseEvent(static::$kernel, new Request(), $requestType)
71
        );
72
73
        $this->assertEquals($expected, $manager->getActiveProfiles());
74
    }
75
}
76