1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SumoCoders\FrameworkCoreBundle\Tests\Composer; |
4
|
|
|
|
5
|
|
|
use SumoCoders\FrameworkCoreBundle\Installer\Installer; |
6
|
|
|
|
7
|
|
|
class InstallerTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var Installer |
11
|
|
|
*/ |
12
|
|
|
protected $installer; |
13
|
|
|
|
14
|
|
|
public function setUp() |
15
|
|
|
{ |
16
|
|
|
$this->installer = new Installer(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testDecoratedMessage() |
20
|
|
|
{ |
21
|
|
|
$this->assertEquals( |
22
|
|
|
'<error>I will be wrapped in an errortag.</error>', |
23
|
|
|
$this->installer->getDecoratedMessage( |
24
|
|
|
'I will be wrapped in an errortag.', |
25
|
|
|
'error', |
26
|
|
|
true |
27
|
|
|
) |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testNotDecoratedMessage() |
32
|
|
|
{ |
33
|
|
|
$this->assertEquals( |
34
|
|
|
'I wont be wrapped in an errortag.', |
35
|
|
|
$this->installer->getDecoratedMessage( |
36
|
|
|
'I wont be wrapped in an errortag.', |
37
|
|
|
'error', |
38
|
|
|
false |
39
|
|
|
) |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testLocalProjectInformation() |
44
|
|
|
{ |
45
|
|
|
$information = $this->installer->extractInformationFromPath( |
46
|
|
|
'/Users/tijs/Sites/foo/bar' |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
$this->assertTrue($information['is_local']); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testNotLocalProjectInformation() |
53
|
|
|
{ |
54
|
|
|
$information = $this->installer->extractInformationFromPath( |
55
|
|
|
'/home/sumocoders/apps/foo/bar/releases/20150415160001' |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$this->assertFalse($information['is_local']); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
public function testCorrectProjectInformation() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$information = $this->installer->extractInformationFromPath( |
64
|
|
|
'/Users/tijs/Sites/foo/bar' |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$this->assertEquals('foo', $information['client']); |
68
|
|
|
$this->assertEquals('bar', $information['project']); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
View Code Duplication |
public function testNotCorrectProjectInformation() |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$information = $this->installer->extractInformationFromPath( |
74
|
|
|
'/home/sumocoders/apps/foo/bar/releases/20150415160001' |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$this->assertNull($information['client']); |
78
|
|
|
$this->assertNull($information['project']); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
View Code Duplication |
public function testValidUpdateCapfile() |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$originalContent = <<<ORIGINAL |
84
|
|
|
set :first_name, 'foo' |
85
|
|
|
set :last_name, 'bar' |
86
|
|
|
ORIGINAL; |
87
|
|
|
|
88
|
|
|
$expectedContent = <<<EXPECTED |
89
|
|
|
set :first_name, 'John' |
90
|
|
|
set :last_name, 'Doe' |
91
|
|
|
EXPECTED; |
92
|
|
|
|
93
|
|
|
$tempFile = tempnam(sys_get_temp_dir(), 'test'); |
94
|
|
|
file_put_contents($tempFile, $originalContent); |
95
|
|
|
|
96
|
|
|
$this->installer->updateCapfile( |
97
|
|
|
$tempFile, |
98
|
|
|
array( |
99
|
|
|
'first_name' => 'John', |
100
|
|
|
'last_name' => 'Doe', |
101
|
|
|
) |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
$this->assertEquals( |
105
|
|
|
$expectedContent, |
106
|
|
|
file_get_contents($tempFile) |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
unlink($tempFile); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
View Code Duplication |
public function testValidUpdateYmlFile() |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
$originalContent = <<<ORIGINAL |
115
|
|
|
parameters: |
116
|
|
|
first_name: foo |
117
|
|
|
last_name: bar |
118
|
|
|
ORIGINAL; |
119
|
|
|
|
120
|
|
|
$expectedContent = <<<EXPECTED |
121
|
|
|
parameters: |
122
|
|
|
first_name: John |
123
|
|
|
last_name: Doe |
124
|
|
|
|
125
|
|
|
EXPECTED; |
126
|
|
|
|
127
|
|
|
$tempFile = tempnam(sys_get_temp_dir(), 'test'); |
128
|
|
|
file_put_contents($tempFile, $originalContent); |
129
|
|
|
|
130
|
|
|
$this->installer->updateYmlFile( |
131
|
|
|
$tempFile, |
132
|
|
|
array( |
133
|
|
|
'first_name' => 'John', |
134
|
|
|
'last_name' => 'Doe', |
135
|
|
|
) |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
$this->assertEquals( |
139
|
|
|
ltrim($expectedContent), |
140
|
|
|
file_get_contents($tempFile) |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
unlink($tempFile); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
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.