forked from voxpupuli/puppet-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp_spec.rb
More file actions
278 lines (252 loc) · 11.7 KB
/
php_spec.rb
File metadata and controls
278 lines (252 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
require 'spec_helper'
describe 'php', type: :class do
on_supported_os.each do |os, facts|
context "on #{os}" do
let :facts do
facts
end
php_cli_package = case facts[:os]['name']
when 'Debian'
case facts[:os]['release']['major']
when '9'
'php7.0-cli'
else
'php5-cli'
end
when 'Ubuntu'
case facts[:os]['release']['major']
when '18.04'
'php7.2-cli'
when '16.04'
'php7.0-cli'
else
'php5-cli'
end
end
php_fpm_ackage = case facts[:os]['name']
when 'Debian'
case facts[:os]['release']['major']
when '9'
'php7.0-fpm'
else
'php5-fpm'
end
when 'Ubuntu'
case facts[:os]['release']['major']
when '18.04'
'php7.2-fpm'
when '16.04'
'php7.0-fpm'
else
'php5-fpm'
end
end
php_dev_ackage = case facts[:os]['name']
when 'Debian'
case facts[:os]['release']['major']
when '9'
'php7.0-dev'
else
'php5-dev'
end
when 'Ubuntu'
case facts[:os]['release']['major']
when '18.04'
'php7.2-dev'
when '16.04'
'php7.0-dev'
else
'php5-dev'
end
end
describe 'when called with no parameters' do
case facts[:osfamily]
when 'Suse', 'RedHat', 'CentOS'
it { is_expected.to contain_class('php::global') }
end
case facts[:osfamily]
when 'Debian'
it { is_expected.not_to contain_class('php::global') }
it { is_expected.to contain_class('php::fpm') }
it { is_expected.to contain_package('php-pear').with_ensure('present') }
it { is_expected.to contain_class('php::composer') }
it { is_expected.to contain_package(php_cli_package).with_ensure('present') }
it { is_expected.to contain_package(php_fpm_ackage).with_ensure('present') }
it { is_expected.to contain_package(php_dev_ackage).with_ensure('present') }
when 'Suse'
it { is_expected.to contain_package('php5').with_ensure('present') }
it { is_expected.to contain_package('php5-devel').with_ensure('present') }
it { is_expected.to contain_package('php5-pear').with_ensure('present') }
it { is_expected.not_to contain_package('php5-cli') }
it { is_expected.not_to contain_package('php5-dev') }
it { is_expected.not_to contain_package('php-pear') }
when 'RedHat', 'CentOS'
it { is_expected.to contain_package('php-cli').with_ensure('present') }
it { is_expected.to contain_package('php-common').with_ensure('present') }
end
end
describe 'when called with package_prefix parameter' do
package_prefix = 'myphp-'
let(:params) { { package_prefix: package_prefix } }
case facts[:osfamily]
when 'Suse', 'RedHat', 'CentOS'
it { is_expected.to contain_class('php::global') }
end
case facts[:osfamily]
when 'Debian', 'RedHat', 'CentOS'
it { is_expected.to contain_package("#{package_prefix}cli").with_ensure('present') }
end
case facts[:osfamily]
when 'Debian'
it { is_expected.not_to contain_class('php::global') }
it { is_expected.to contain_class('php::fpm') }
it { is_expected.to contain_class('php::composer') }
it { is_expected.to contain_package('php-pear').with_ensure('present') }
it { is_expected.to contain_package("#{package_prefix}dev").with_ensure('present') }
it { is_expected.to contain_package("#{package_prefix}fpm").with_ensure('present') }
when 'Suse'
it { is_expected.to contain_package('php5').with_ensure('present') }
it { is_expected.to contain_package("#{package_prefix}devel").with_ensure('present') }
it { is_expected.to contain_package("#{package_prefix}pear").with_ensure('present') }
it { is_expected.not_to contain_package("#{package_prefix}cli").with_ensure('present') }
it { is_expected.not_to contain_package("#{package_prefix}dev") }
it { is_expected.not_to contain_package('php-pear') }
when 'RedHat', 'CentOS'
it { is_expected.to contain_package("#{package_prefix}common").with_ensure('present') }
end
end
describe 'when called with fpm_user parameter' do
let(:params) { { fpm_user: 'nginx' } }
it { is_expected.to contain_class('php::fpm').with(user: 'nginx') }
it { is_expected.to contain_php__fpm__pool('www').with(user: 'nginx') }
dstfile = case facts[:osfamily]
when 'Debian'
case facts[:os]['name']
when 'Debian'
case facts[:os]['release']['major']
when '9'
'/etc/php/7.0/fpm/pool.d/www.conf'
else
'/etc/php5/fpm/pool.d/www.conf'
end
when 'Ubuntu'
case facts[:os]['release']['major']
when '18.04'
'/etc/php/7.2/fpm/pool.d/www.conf'
when '16.04'
'/etc/php/7.0/fpm/pool.d/www.conf'
else
'/etc/php5/fpm/pool.d/www.conf'
end
end
when 'Archlinux'
'/etc/php/php-fpm.d/www.conf'
when 'Suse'
'/etc/php5/fpm/pool.d/www.conf'
when 'RedHat'
'/etc/php-fpm.d/www.conf'
when 'FreeBSD'
'/usr/local/etc/php-fpm.d/www.conf'
end
it { is_expected.to contain_file(dstfile).with_content(%r{user = nginx}) }
end
describe 'when called with fpm_group parameter' do
let(:params) { { fpm_group: 'nginx' } }
it { is_expected.to contain_class('php::fpm').with(group: 'nginx') }
it { is_expected.to contain_php__fpm__pool('www').with(group: 'nginx') }
dstfile = case facts[:osfamily]
when 'Debian'
case facts[:os]['name']
when 'Debian'
case facts[:os]['release']['major']
when '9'
'/etc/php/7.0/fpm/pool.d/www.conf'
else
'/etc/php5/fpm/pool.d/www.conf'
end
when 'Ubuntu'
case facts[:os]['release']['major']
when '18.04'
'/etc/php/7.2/fpm/pool.d/www.conf'
when '16.04'
'/etc/php/7.0/fpm/pool.d/www.conf'
else
'/etc/php5/fpm/pool.d/www.conf'
end
end
when 'Archlinux'
'/etc/php/php-fpm.d/www.conf'
when 'Suse'
'/etc/php5/fpm/pool.d/www.conf'
when 'RedHat'
'/etc/php-fpm.d/www.conf'
when 'FreeBSD'
'/usr/local/etc/php-fpm.d/www.conf'
end
it { is_expected.to contain_file(dstfile).with_content(%r{group = nginx}) }
end
describe 'when fpm is disabled' do
let(:params) { { fpm: false } }
it { is_expected.not_to contain_class('php::fpm') }
end
describe 'when composer is disabled' do
let(:params) { { composer: false } }
it { is_expected.not_to contain_class('php::composer') }
end
if facts[:osfamily] == 'RedHat' || facts[:osfamily] == 'CentOS'
describe 'when called with cli_settings parameter' do
let(:params) do
{
'settings' => { 'PHP/memory_limit' => '300M' },
'cli_settings' => { 'PHP/memory_limit' => '1000M' }
}
end
it { is_expected.to contain_php__config__setting('/etc/php.ini: PHP/memory_limit').with_value('300M') }
it { is_expected.to contain_php__config__setting('/etc/php-fpm.ini: PHP/memory_limit').with_value('300M') }
it { is_expected.to contain_php__config__setting('/etc/php-cli.ini: PHP/memory_limit').with_value('1000M') }
end
describe 'when called with global option for rhscl_mode' do
describe 'when called with mode "remi"' do
scl_php_version = 'php56'
rhscl_mode = 'remi'
let(:pre_condition) do
"class {'::php::globals':
php_version => '#{scl_php_version}',
rhscl_mode => '#{rhscl_mode}'
}"
end
let(:params) do
{ settings: { 'Date/date.timezone' => 'Europe/Berlin' } }
end
it { is_expected.to contain_class('php::global') }
it { is_expected.to contain_package("#{scl_php_version}-php-cli").with_ensure('present') }
it { is_expected.to contain_package("#{scl_php_version}-php-common").with_ensure('present') }
it { is_expected.to contain_php__config('global').with(file: "/etc/opt/#{rhscl_mode}/#{scl_php_version}/php.ini") }
it { is_expected.not_to contain_php__config('cli') }
# see: https://github.com/voxpupuli/puppet-php/blob/master/lib/puppet/parser/functions/to_hash_settings.rb
it { is_expected.to contain_php__config__setting("/etc/opt/#{rhscl_mode}/#{scl_php_version}/php.ini: Date/date.timezone").with_value('Europe/Berlin') }
end
describe 'when called with mode "rhscl"' do
scl_php_version = 'rh-php56'
rhscl_mode = 'rhscl'
let(:pre_condition) do
"class {'::php::globals':
php_version => '#{scl_php_version}',
rhscl_mode => '#{rhscl_mode}'
}"
end
let(:params) do
{ settings: { 'Date/date.timezone' => 'Europe/Berlin' } }
end
it { is_expected.to contain_class('php::global') }
it { is_expected.to contain_package("#{scl_php_version}-php-cli").with_ensure('present') }
it { is_expected.to contain_package("#{scl_php_version}-php-common").with_ensure('present') }
it { is_expected.to contain_php__config('global').with(file: "/etc/opt/rh/#{scl_php_version}/php.ini") }
it { is_expected.to contain_php__config('cli').with(file: "/etc/opt/rh/#{scl_php_version}/php-cli.ini") }
it { is_expected.to contain_php__config__setting("/etc/opt/rh/#{scl_php_version}/php.ini: Date/date.timezone").with_value('Europe/Berlin') }
end
end
end
end
end
end