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'); |
|
|
|
|
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'); |
|
|
|
|
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
|
|
|
|
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: