Completed
Branch master (a0e1ef)
by Sergei
03:53 queued 01:35
created

ConfigMergersProviderTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 73
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testGetItems() 0 70 1
1
<?php
2
3
namespace Modera\BackendGoogleAnalyticsBundle\Tests\Unit\Contributions;
4
5
use Modera\BackendGoogleAnalyticsBundle\Contributions\ConfigMergersProvider;
6
use Modera\BackendGoogleAnalyticsBundle\ModeraBackendGoogleAnalyticsBundle;
7
use Modera\MjrIntegrationBundle\Config\ConfigMergerInterface;
8
use Modera\SecurityBundle\Entity\User;
9
10
/**
11
 * @author    Sergei Lissovski <[email protected]>
12
 * @copyright 2016 Modera Foundation
13
 */
14
class ConfigMergersProviderTest extends \PHPUnit_Framework_TestCase
15
{
16
    public function testGetItems()
17
    {
18
        $user = \Phake::mock(User::clazz());
19
        \Phake::when($user)
20
            ->getId()
21
            ->thenReturn('foo-id')
22
        ;
23
24
        $token = \Phake::mock('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken');
25
        \Phake::when($token)
26
            ->getUser()
27
            ->thenReturn($user)
28
        ;
29
30
        $tokenStorage = \Phake::mock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
31
        \Phake::when($tokenStorage)
32
            ->getToken()
33
            ->thenReturn($token)
34
        ;
35
36
        $configEntry = \Phake::mock('Modera\ConfigBundle\Config\ConfigurationEntryInterface');
37
        \Phake::when($configEntry)
38
            ->getValue()
39
            ->thenReturn('foo-value')
40
        ;
41
42
        $configEntriesManager = \Phake::mock('Modera\ConfigBundle\Config\ConfigurationEntriesManagerInterface');
43
        \Phake::when($configEntriesManager)
44
            ->findOneByNameOrDie(ModeraBackendGoogleAnalyticsBundle::TRACKING_CODE_CONFIG_KEY)
45
            ->thenReturn($configEntry)
46
        ;
47
48
        $provider = new ConfigMergersProvider($tokenStorage, $configEntriesManager, 'prod');
0 ignored issues
show
Documentation introduced by
$tokenStorage is of type object<Phake_IMock>, but the function expects a object<Symfony\Component...\TokenStorageInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$configEntriesManager is of type object<Phake_IMock>, but the function expects a object<Modera\ConfigBund...ntriesManagerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
50
        $items = $provider->getItems();
51
52
        $this->assertTrue(is_array($items));
53
        $this->assertEquals(1, count($items));
54
55
        /* @var ConfigMergerInterface $merger */
56
        $merger = $items[0];
57
58
        $this->assertInstanceOf('Modera\MjrIntegrationBundle\Config\ConfigMergerInterface', $merger);
59
60
        $config = $merger->merge(array());
61
62
        $this->assertArrayHasKey('modera_backend_google_analytics', $config);
63
        $config = $config['modera_backend_google_analytics'];
64
        $this->assertArrayHasKey('tracking_code', $config);
65
        $this->assertEquals('foo-value', $config['tracking_code']);
66
        $this->assertEquals('foo-id', $config['user_id']);
67
        $this->assertArrayHasKey('user_id', $config);
68
        $this->assertArrayHasKey('is_debug', $config);
69
        $this->assertFalse($config['is_debug']); // because it's "prod" env now
70
        $this->assertArrayHasKey('prefix', $config);
71
        $this->assertEquals('/backend', $config['prefix']);
72
73
        // --- env = dev
74
75
        $provider = new ConfigMergersProvider($tokenStorage, $configEntriesManager, 'dev');
0 ignored issues
show
Documentation introduced by
$tokenStorage is of type object<Phake_IMock>, but the function expects a object<Symfony\Component...\TokenStorageInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$configEntriesManager is of type object<Phake_IMock>, but the function expects a object<Modera\ConfigBund...ntriesManagerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
76
77
        $items = $provider->getItems();
78
79
        $this->assertTrue(is_array($items));
80
        $this->assertEquals(1, count($items));
81
82
        $config = $items[0]->merge(array());
83
84
        $this->assertTrue($config['modera_backend_google_analytics']['is_debug']);
85
    }
86
}
87