1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\AdminListBundle\Tests\Helper; |
4
|
|
|
|
5
|
|
|
use Kunstmaan\AdminBundle\Helper\DomainConfiguration; |
6
|
|
|
use PHPUnit_Framework_TestCase; |
7
|
|
|
use Symfony\Component\DependencyInjection\Container; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2015-03-19 at 09:56:53. |
12
|
|
|
*/ |
13
|
|
|
class DomainConfigurationTest extends PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var DomainConfiguration |
17
|
|
|
*/ |
18
|
|
|
protected $object; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Sets up the fixture, for example, opens a network connection. |
22
|
|
|
* This method is called before a test is executed. |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
public function setUp() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$map = array( |
27
|
|
|
array('multilanguage', true), |
28
|
|
|
array('defaultlocale', 'nl'), |
29
|
|
|
array('requiredlocales', 'nl|fr|en'), |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
$this->object = new DomainConfiguration($this->getContainer($map)); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetSet() |
36
|
|
|
{ |
37
|
|
|
$data = $this->object->getLocalesExtraData(); |
38
|
|
|
$this->assertCount(0, $data); |
39
|
|
|
$data = $this->object->getFullHostConfig(); |
40
|
|
|
$this->assertCount(0, $data); |
41
|
|
|
$this->assertNull($this->object->getFullHost()); |
42
|
|
|
$this->assertNull($this->object->getFullHostById(123)); |
43
|
|
|
$this->assertNull($this->object->getHostSwitched()); |
44
|
|
|
$this->assertNull($this->object->getHostBaseUrl()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
private function getContainer($map) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$this->container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$this->container |
52
|
|
|
->method('getParameter') |
53
|
|
|
->will($this->returnValueMap($map)); |
54
|
|
|
$this->container |
55
|
|
|
->expects($this->any()) |
56
|
|
|
->method('get') |
57
|
|
|
->with($this->equalTo('request_stack')) |
58
|
|
|
->willReturn($this->getRequestStack()); |
59
|
|
|
|
60
|
|
|
return $this->container; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
private function getRequestStack() |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$requestStack = $this->createMock('Symfony\Component\HttpFoundation\RequestStack'); |
66
|
|
|
$requestStack->expects($this->any())->method('getMasterRequest')->willReturn($this->getRequest()); |
67
|
|
|
|
68
|
|
|
return $requestStack; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function getRequest() |
72
|
|
|
{ |
73
|
|
|
$request = Request::create('http://domain.tld/'); |
74
|
|
|
|
75
|
|
|
return $request; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.