These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminBundle\Tests\Helper; |
||
4 | |||
5 | use Kunstmaan\AdminBundle\Helper\DomainConfiguration; |
||
6 | use PHPUnit\Framework\TestCase; |
||
7 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
8 | use Symfony\Component\HttpFoundation\Request; |
||
9 | |||
10 | class DomainConfigurationTest extends TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @var DomainConfiguration |
||
14 | */ |
||
15 | protected $object; |
||
16 | |||
17 | /** |
||
18 | * @var ContainerInterface |
||
19 | */ |
||
20 | protected $container; |
||
21 | |||
22 | public function testGetHost() |
||
23 | { |
||
24 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
25 | $this->assertEquals('domain.tld', $object->getHost()); |
||
26 | } |
||
27 | |||
28 | public function testGetHosts() |
||
29 | { |
||
30 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
31 | $this->assertEquals(array('domain.tld'), $object->getHosts()); |
||
32 | } |
||
33 | |||
34 | public function testGetDefaultLocale() |
||
35 | { |
||
36 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
37 | $this->assertEquals('en', $object->getDefaultLocale()); |
||
38 | } |
||
39 | |||
40 | public function testGetExtraData() |
||
41 | { |
||
42 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
43 | $this->assertEquals(array(), $object->getExtraData()); |
||
44 | } |
||
45 | |||
46 | public function testGetRootNode() |
||
47 | { |
||
48 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
49 | $this->assertNull($object->getRootNode()); |
||
50 | } |
||
51 | |||
52 | public function testIsMultiDomainHost() |
||
53 | { |
||
54 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
55 | $this->assertFalse($object->isMultiDomainHost()); |
||
56 | } |
||
57 | |||
58 | public function testIsMultiLanguageWithSingleLanguage() |
||
59 | { |
||
60 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
61 | $this->assertFalse($object->isMultiLanguage()); |
||
62 | } |
||
63 | |||
64 | public function testIsMultiLanguageWithMultiLanguage() |
||
65 | { |
||
66 | $object = $this->getMultiLanguageDomainConfiguration(); |
||
67 | $this->assertTrue($object->isMultiLanguage()); |
||
68 | } |
||
69 | |||
70 | public function testGetFrontendLocalesWithSingleLanguage() |
||
71 | { |
||
72 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
73 | $this->assertEquals(array('en'), $object->getFrontendLocales()); |
||
74 | } |
||
75 | |||
76 | public function testGetFrontendLocalesWithMultiLanguage() |
||
77 | { |
||
78 | $object = $this->getMultiLanguageDomainConfiguration(); |
||
79 | $this->assertEquals(array('nl', 'fr', 'en'), $object->getFrontendLocales()); |
||
80 | } |
||
81 | |||
82 | public function testGetBackendLocalesWithSingleLanguage() |
||
83 | { |
||
84 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
85 | $this->assertEquals(array('en'), $object->getBackendLocales()); |
||
86 | } |
||
87 | |||
88 | public function testGetBackendLocalesWithMultiLanguage() |
||
89 | { |
||
90 | $object = $this->getMultiLanguageDomainConfiguration(); |
||
91 | $this->assertEquals(array('nl', 'fr', 'en'), $object->getBackendLocales()); |
||
92 | } |
||
93 | |||
94 | View Code Duplication | private function getContainer($map) |
|
95 | { |
||
96 | $this->container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
||
0 ignored issues
–
show
|
|||
97 | |||
98 | $this->container |
||
99 | ->method('getParameter') |
||
100 | ->will($this->returnValueMap($map)); |
||
101 | $this->container |
||
102 | ->expects($this->any()) |
||
103 | ->method('get') |
||
104 | ->with($this->equalTo('request_stack')) |
||
105 | ->willReturn($this->getRequestStack()); |
||
106 | |||
107 | return $this->container; |
||
108 | } |
||
109 | |||
110 | View Code Duplication | private function getRequestStack() |
|
111 | { |
||
112 | $requestStack = $this->createMock('Symfony\Component\HttpFoundation\RequestStack'); |
||
113 | $requestStack->expects($this->any())->method('getMasterRequest')->willReturn($this->getRequest()); |
||
114 | |||
115 | return $requestStack; |
||
116 | } |
||
117 | |||
118 | private function getRequest() |
||
119 | { |
||
120 | $request = Request::create('http://domain.tld/'); |
||
121 | |||
122 | return $request; |
||
123 | } |
||
124 | |||
125 | View Code Duplication | private function getSingleLanguageDomainConfiguration() |
|
126 | { |
||
127 | $map = [ |
||
128 | ['kunstmaan_admin.multi_language', false], |
||
129 | ['kunstmaan_admin.default_locale', 'en'], |
||
130 | ['kunstmaan_admin.required_locales', 'en'], |
||
131 | ]; |
||
132 | |||
133 | $object = new DomainConfiguration($this->getContainer($map)); |
||
134 | |||
135 | return $object; |
||
136 | } |
||
137 | |||
138 | View Code Duplication | private function getMultiLanguageDomainConfiguration() |
|
139 | { |
||
140 | $map = [ |
||
141 | ['kunstmaan_admin.multi_language', true], |
||
142 | ['kunstmaan_admin.default_locale', 'nl'], |
||
143 | ['kunstmaan_admin.required_locales', 'nl|fr|en'], |
||
144 | ]; |
||
145 | |||
146 | $object = new DomainConfiguration($this->getContainer($map)); |
||
147 | |||
148 | return $object; |
||
149 | } |
||
150 | } |
||
151 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..