diff --git a/.fixtures.yml b/.fixtures.yml index 9c310df..3c6280a 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,10 +1,11 @@ fixtures: repositories: stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" apt: "https://github.com/puppetlabs/puppetlabs-apt.git" + translate: "https://github.com/puppetlabs/puppetlabs-translate.git" zypprepo: "https://github.com/deadpoint/puppet-zypprepo.git" inifile: "https://github.com/puppetlabs/puppetlabs-inifile.git" archive: "https://github.com/voxpupuli/puppet-archive.git" yumrepo_core: repo: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git puppet_version: ">= 6.0.0" diff --git a/manifests/dev.pp b/manifests/dev.pp index c5cca3d..3beb3f8 100644 --- a/manifests/dev.pp +++ b/manifests/dev.pp @@ -1,42 +1,42 @@ # Install the development package with headers for PHP # # === Parameters # # [*ensure*] # The PHP ensure of PHP dev to install # # [*package*] # The package name for the PHP development files # class php::dev ( String $ensure = $php::ensure, String $package = "${php::package_prefix}${php::params::dev_package_suffix}", Boolean $manage_repos = $php::manage_repos, ) inherits php::params { assert_private() # On FreeBSD there is no 'devel' package. $real_package = $facts['os']['family'] ? { 'FreeBSD' => [], default => $package, } if $facts['os']['family'] == 'Debian' { # we can set the dependency only if we manage repos $require = $manage_repos ? { true => Class['::apt::update'], false => undef, } } else { $require = undef } # Default PHP come with xml module and no seperate package for it - if $facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['full'], '16.04') >= 0 { + if $facts['os']['name'] == 'Ubuntu' { ensure_packages(["${php::package_prefix}xml"], { ensure => present, require => $require, }) } package { $real_package: ensure => $ensure, require => Class['php::packages'], } } diff --git a/manifests/fpm.pp b/manifests/fpm.pp index a042b8a..4b2790a 100644 --- a/manifests/fpm.pp +++ b/manifests/fpm.pp @@ -1,125 +1,110 @@ # Install and configure mod_php for fpm # # === Parameters # # [*user*] # The user that php-fpm should run as # # [*group*] # The group that php-fpm should run as # # [*service_enable*] # Enable/disable FPM service # # [*service_ensure*] # Ensure FPM service is either 'running' or 'stopped' # # [*service_name*] # This is the name of the php-fpm service. It defaults to reasonable OS # defaults but can be different in case of using php7.0/other OS/custom fpm service # # [*service_provider*] # This is the name of the service provider, in case there is a non # OS default service provider used to start FPM. # Defaults to 'undef', pick system defaults. # # [*pools*] # Hash of php::fpm::pool resources that will be created. Defaults # to a single php::fpm::pool named www with default parameters. # # [*log_owner*] # The php-fpm log owner # # [*log_group*] # The group owning php-fpm logs # # [*package*] # Specify which package to install # # [*ensure*] # Specify which version of the package to install # # [*inifile*] # Path to php.ini for fpm # # [*settings*] # fpm settings hash # # [*global_pool_settings*] # Hash of defaults params php::fpm::pool resources that will be created. # Defaults is empty hash. # # [*pool_purge*] # Whether to purge pool config files not created # by this module # class php::fpm ( String $ensure = $php::ensure, $user = $php::fpm_user, $group = $php::fpm_group, $service_ensure = $php::fpm_service_ensure, $service_enable = $php::fpm_service_enable, $service_name = $php::fpm_service_name, $service_provider = $php::fpm_service_provider, String $package = $php::real_fpm_package, Stdlib::Absolutepath $inifile = $php::fpm_inifile, Hash $settings = $php::real_settings, $global_pool_settings = $php::real_fpm_global_pool_settings, Hash $pools = $php::real_fpm_pools, $log_owner = $php::log_owner, $log_group = $php::log_group, Boolean $pool_purge = $php::pool_purge, ) { if ! defined(Class['php']) { warning('php::fpm is private') } $real_settings = $settings # On FreeBSD fpm is not a separate package, but included in the 'php' package. # Implies that the option SET+=FPM was set when building the port. $real_package = $facts['os']['family'] ? { 'FreeBSD' => [], default => $package, } package { $real_package: ensure => $ensure, require => Class['php::packages'], } class { 'php::fpm::config': user => $user, group => $group, inifile => $inifile, settings => $real_settings, log_owner => $log_owner, log_group => $log_group, pool_purge => $pool_purge, require => Package[$real_package], } contain 'php::fpm::config' contain 'php::fpm::service' Class['php::fpm::config'] ~> Class['php::fpm::service'] $real_global_pool_settings = $global_pool_settings $real_pools = $pools create_resources(::php::fpm::pool, $real_pools, $real_global_pool_settings) - - # Create an override to use a reload signal as trusty and utopic's - # upstart version supports this - if ($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['full'], '14') >= 0 and versioncmp($facts['os']['release']['full'], '16') < 0) { - if ($service_enable) { - $fpm_override = 'reload signal USR2' - } - else { - $fpm_override = "reload signal USR2\nmanual" - } - file { "/etc/init/${php::fpm::service::service_name}.override": - content => $fpm_override, - before => Package[$real_package], - } - } } diff --git a/manifests/fpm/service.pp b/manifests/fpm/service.pp index 5aa7a0f..fe87c87 100644 --- a/manifests/fpm/service.pp +++ b/manifests/fpm/service.pp @@ -1,49 +1,39 @@ # Manage fpm service # # === Parameters # # [*service_name*] # name of the php-fpm service # # [*ensure*] # 'ensure' value for the service # # [*enable*] # Defines if the service is enabled # # [*provider*] # Defines if the service provider to use # class php::fpm::service ( $service_name = $php::fpm::service_name, $ensure = $php::fpm::service_ensure, $enable = $php::fpm::service_enable, $provider = $php::fpm::service_provider, ) { if ! defined(Class['php::fpm']) { warning('php::fpm::service is private') } - $reload = "service ${service_name} reload" - - if ($facts['os']['name'] == 'Ubuntu' - and versioncmp($facts['os']['release']['full'], '12') >= 0 - and versioncmp($facts['os']['release']['full'], '14') < 0) { - # Precise upstart doesn't support reload signals, so use - # regular service restart instead - $restart = undef - } else { - $restart = $reload - } + $restart = "service ${service_name} reload" service { $service_name: ensure => $ensure, enable => $enable, provider => $provider, hasrestart => true, restart => $restart, hasstatus => true, } ::Php::Extension <| |> ~> Service[$service_name] } diff --git a/manifests/globals.pp b/manifests/globals.pp index 17b9457..f3b4670 100644 --- a/manifests/globals.pp +++ b/manifests/globals.pp @@ -1,169 +1,158 @@ # PHP globals class # # === Parameters # # [*php_version*] # The version of php. # # [*config_root*] # The configuration root directory. # # [*fpm_pid_file*] # Path to pid file for fpm # # [*rhscl_mode*] # The mode specifies the specifics in paths for the various RedHat SCL environments so that the module is configured # correctly on their pathnames. # # Valid modes are: 'rhscl', 'remi' # class php::globals ( Optional[Pattern[/^(rh-)?(php)?[57](\.)?[0-9]/]] $php_version = undef, Optional[Stdlib::Absolutepath] $config_root = undef, Optional[Stdlib::Absolutepath] $fpm_pid_file = undef, $rhscl_mode = undef, ) { $default_php_version = $facts['os']['name'] ? { 'Debian' => $facts['os']['release']['major'] ? { '9' => '7.0', - '10' => '7.3', - default => '5.x', + default => '7.3', }, 'Ubuntu' => $facts['os']['release']['major'] ? { - '18.04' => '7.2', '16.04' => '7.0', - default => '5.x', + default => '7.2', }, default => '5.x', } $globals_php_version = pick($php_version, $default_php_version) case $facts['os']['family'] { 'Debian': { if $facts['os']['name'] == 'Ubuntu' { case $globals_php_version { - /^5\.4/: { - $default_config_root = '/etc/php5' - $default_fpm_pid_file = "/var/run/php/php${globals_php_version}-fpm.pid" - $fpm_error_log = '/var/log/php5-fpm.log' - $fpm_service_name = 'php5-fpm' - $ext_tool_enable = '/usr/sbin/php5enmod' - $ext_tool_query = '/usr/sbin/php5query' - $package_prefix = 'php5-' - } /^[57].[0-9]/: { $default_config_root = "/etc/php/${globals_php_version}" $default_fpm_pid_file = "/var/run/php/php${globals_php_version}-fpm.pid" $fpm_error_log = "/var/log/php${globals_php_version}-fpm.log" $fpm_service_name = "php${globals_php_version}-fpm" $ext_tool_enable = "/usr/sbin/phpenmod -v ${globals_php_version}" $ext_tool_query = "/usr/sbin/phpquery -v ${globals_php_version}" $package_prefix = "php${globals_php_version}-" } default: { # Default php installation from Ubuntu official repository use the following paths until 16.04 # For PPA please use the $php_version to override it. $default_config_root = '/etc/php5' $default_fpm_pid_file = '/var/run/php5-fpm.pid' $fpm_error_log = '/var/log/php5-fpm.log' $fpm_service_name = 'php5-fpm' $ext_tool_enable = '/usr/sbin/php5enmod' $ext_tool_query = '/usr/sbin/php5query' $package_prefix = 'php5-' } } } else { case $globals_php_version { /^5\.6/, /^7\.[0-9]/: { $default_config_root = "/etc/php/${globals_php_version}" $default_fpm_pid_file = "/var/run/php/php${globals_php_version}-fpm.pid" $fpm_error_log = "/var/log/php${globals_php_version}-fpm.log" $fpm_service_name = "php${globals_php_version}-fpm" $ext_tool_enable = "/usr/sbin/phpenmod -v ${globals_php_version}" $ext_tool_query = "/usr/sbin/phpquery -v ${globals_php_version}" $package_prefix = "php${globals_php_version}-" } default: { $default_config_root = '/etc/php5' $default_fpm_pid_file = '/var/run/php5-fpm.pid' $fpm_error_log = '/var/log/php5-fpm.log' $fpm_service_name = 'php5-fpm' $ext_tool_enable = '/usr/sbin/php5enmod' $ext_tool_query = '/usr/sbin/php5query' $package_prefix = 'php5-' } } } } 'Suse': { case $globals_php_version { /^7/: { $default_config_root = '/etc/php7' $package_prefix = 'php7-' $default_fpm_pid_file = '/var/run/php7-fpm.pid' $fpm_error_log = '/var/log/php7-fpm.log' } default: { $default_config_root = '/etc/php5' $package_prefix = 'php5-' $default_fpm_pid_file = '/var/run/php5-fpm.pid' $fpm_error_log = '/var/log/php5-fpm.log' } } } 'RedHat': { case $rhscl_mode { 'remi': { $rhscl_root = "/opt/remi/${php_version}/root" $default_config_root = "/etc/opt/remi/${php_version}" $default_fpm_pid_file = '/var/run/php-fpm/php-fpm.pid' $package_prefix = "${php_version}-php-" $fpm_service_name = "${php_version}-php-fpm" } 'rhscl': { $rhscl_root = "/opt/rh/${php_version}/root" $default_config_root = "/etc/opt/rh/${php_version}" # rhscl registers contents by copy in /etc/opt/rh $default_fpm_pid_file = "/var/opt/rh/${php_version}/run/php-fpm/php-fpm.pid" $package_prefix = "${php_version}-php-" $fpm_service_name = "${php_version}-php-fpm" } undef: { $default_config_root = '/etc/php.d' $default_fpm_pid_file = '/var/run/php-fpm/php-fpm.pid' $fpm_service_name = undef $package_prefix = undef } default: { fail("Unsupported rhscl_mode '${rhscl_mode}'") } } } 'FreeBSD': { case $globals_php_version { /^(\d)\.(\d)$/: { $package_prefix = "php${1}${2}-" } default: { $package_prefix = 'php56-' } } $default_config_root = '/usr/local/etc' $default_fpm_pid_file = '/var/run/php-fpm.pid' $fpm_service_name = undef } 'Archlinux': { $default_config_root = '/etc/php' $default_fpm_pid_file = '/run/php-fpm/php-fpm.pid' } default: { fail("Unsupported osfamily: ${facts['os']['family']}") } } $globals_config_root = pick($config_root, $default_config_root) $globals_fpm_pid_file = pick($fpm_pid_file, $default_fpm_pid_file) } diff --git a/manifests/repo/debian.pp b/manifests/repo/debian.pp index 1bf4aeb..5dd4d50 100644 --- a/manifests/repo/debian.pp +++ b/manifests/repo/debian.pp @@ -1,83 +1,67 @@ # Configure debian apt repo # # === Parameters # # [*location*] # Location of the apt repository # # [*release*] # Release of the apt repository # # [*repos*] # Apt repository names # # [*include_src*] # Add source source repository # # [*key*] # Public key in apt::key format # # [*dotdeb*] # Enable special dotdeb handling # # [*sury*] # Enable special sury handling # class php::repo::debian ( $location = 'https://packages.dotdeb.org', $release = 'wheezy-php56', $repos = 'all', $include_src = false, $key = { 'id' => '6572BBEF1B5FF28B28B706837E3F070089DF5277', 'source' => 'http://www.dotdeb.org/dotdeb.gpg', }, $dotdeb = true, $sury = true, ) { assert_private() include 'apt' apt::source { "source_php_${release}": location => $location, release => $release, repos => $repos, include => { 'src' => $include_src, 'deb' => true, }, key => $key, } - if ($dotdeb) { - # both repositories are required to work correctly - # See: http://www.dotdeb.org/instructions/ - if $release == 'wheezy-php56' { - apt::source { 'dotdeb-wheezy': - location => $location, - release => 'wheezy', - repos => $repos, - include => { - 'src' => $include_src, - 'deb' => true, - }, - } - } - } - - if ($sury and $php::globals::php_version in ['5.6','7.1','7.2']) { + if ($sury and $php::globals::php_version in ['7.1','7.2']) { apt::source { 'source_php_sury': location => 'https://packages.sury.org/php/', repos => 'main', include => { 'src' => $include_src, 'deb' => true, }, key => { id => '15058500A0235D97F5D10063B188E2B695BD4743', source => 'https://packages.sury.org/php/apt.gpg', }, } } } diff --git a/manifests/repo/ubuntu.pp b/manifests/repo/ubuntu.pp index c375b25..a8546f7 100644 --- a/manifests/repo/ubuntu.pp +++ b/manifests/repo/ubuntu.pp @@ -1,32 +1,35 @@ # Configure ubuntu ppa # # === Parameters # # [*version*] # PHP version to manage (e.g. 5.6) # class php::repo::ubuntu ( $version = undef, ) { + if $facts['os']['name'] != 'Ubuntu' { + fail("class php::repo::ubuntu does not work on OS ${facts['os']['name']}") + } include 'apt' if($version == undef) { $version_real = '5.6' } else { $version_real = $version } if ($version_real == '5.5') { fail('PHP 5.5 is no longer available for download') } assert_type(Pattern[/^\d\.\d/], $version_real) $version_repo = $version_real ? { '5.4' => 'ondrej/php5-oldstable', default => 'ondrej/php' } ::apt::ppa { "ppa:${version_repo}": package_manage => true, } } diff --git a/metadata.json b/metadata.json index 22f409c..ac49eac 100644 --- a/metadata.json +++ b/metadata.json @@ -1,88 +1,87 @@ { "name": "puppet-php", "version": "7.1.1-rc0", "author": "Vox Pupuli", "summary": "Generic PHP module that supports many platforms", "license": "MIT", "source": "https://github.com/voxpupuli/puppet-php", "project_page": "https://github.com/voxpupuli/puppet-php", "issues_url": "https://github.com/voxpupuli/puppet-php/issues", "description": "Puppet module that aims to manage PHP and extensions in a generic way on many platforms with sane defaults and easy configuration", "dependencies": [ { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.16.0 < 7.0.0" }, { "name": "puppetlabs/apt", "version_requirement": ">= 4.4.0 < 8.0.0" }, { "name": "puppetlabs/inifile", "version_requirement": ">= 1.4.1 < 5.0.0" }, { "name": "puppet/zypprepo", "version_requirement": ">= 2.0.0 < 3.0.0" }, { "name": "puppet/archive", "version_requirement": ">= 1.0.0 < 5.0.0" } ], "requirements": [ { "name": "puppet", "version_requirement": ">= 5.5.8 < 7.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "16.04", "18.04" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ - "8", "9", "10" ] }, { "operatingsystem": "RedHat", "operatingsystemrelease": [ "6", "7" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "6", "7" ] }, { "operatingsystem": "FreeBSD", "operatingsystemrelease": [ "11" ] }, { "operatingsystem": "SLES", "operatingsystemrelease": [ "11" ] }, { "operatingsystem": "OpenSUSE" }, { "operatingsystem": "Archlinux" } ] } diff --git a/spec/classes/php_fpm_config_spec.rb b/spec/classes/php_fpm_config_spec.rb index 3e6d4c9..18f6c36 100644 --- a/spec/classes/php_fpm_config_spec.rb +++ b/spec/classes/php_fpm_config_spec.rb @@ -1,41 +1,46 @@ require 'rspec' require 'spec_helper' describe 'php::fpm::config' do on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end + describe 'works without params' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('php::globals') } + it { is_expected.to contain_class('php::params') } + end describe 'creates config file' do let(:params) do { inifile: '/etc/php5/conf.d/unique-name.ini', settings: { 'apc.enabled' => 1 } } end it do is_expected.to contain_class('php::fpm::config').with( inifile: '/etc/php5/conf.d/unique-name.ini', settings: { 'apc.enabled' => 1 } ) end it do is_expected.to contain_php__config('fpm').with( file: '/etc/php5/conf.d/unique-name.ini', config: { 'apc.enabled' => 1 } ) end end end end end diff --git a/spec/classes/php_fpm_service_spec.rb b/spec/classes/php_fpm_service_spec.rb index 5e15a83..96855c7 100644 --- a/spec/classes/php_fpm_service_spec.rb +++ b/spec/classes/php_fpm_service_spec.rb @@ -1,30 +1,44 @@ require 'spec_helper' describe 'php::fpm::service', type: :class do on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end let(:pre_condition) { 'class {"php": fpm => true}' } + describe 'works without default' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('php::cli') } + it { is_expected.to contain_class('php::composer::auto_update') } + it { is_expected.to contain_class('php::composer') } + it { is_expected.to contain_class('php::dev') } + it { is_expected.to contain_class('php::fpm::config') } + it { is_expected.to contain_class('php::fpm') } + it { is_expected.to contain_class('php::packages') } + it { is_expected.to contain_class('php::globals') } + it { is_expected.to contain_class('php::params') } + it { is_expected.to contain_class('php::pear') } + end + describe 'when called with no parameters' do # rubocop:disable RSpec/RepeatedExample case facts[:osfamily] when 'Debian' case facts[:operatingsystemrelease] when '16.04' it { is_expected.to contain_service('php7.0-fpm').with_ensure('running') } end when 'Suse' it { is_expected.to contain_service('php-fpm').with_ensure('running') } when 'FreeBSD' it { is_expected.to contain_service('php-fpm').with_ensure('running') } else it { is_expected.to contain_service('php-fpm').with_ensure('running') } end end end end end diff --git a/spec/classes/php_fpm_spec.rb b/spec/classes/php_fpm_spec.rb index afe1c59..45f29d9 100644 --- a/spec/classes/php_fpm_spec.rb +++ b/spec/classes/php_fpm_spec.rb @@ -1,38 +1,42 @@ require 'spec_helper' describe 'php::fpm', type: :class do on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end let(:pre_condition) { 'class {"php": fpm => false}' } + describe 'works without params' do + it { is_expected.to compile.with_all_deps } + end + describe 'when called with no parameters' do # rubocop:disable RSpec/RepeatedExample case facts[:osfamily] when 'Debian' case facts[:operatingsystemrelease] when '16.04' it { is_expected.to contain_package('php7.0-fpm').with_ensure('present') } it { is_expected.to contain_service('php7.0-fpm').with_ensure('running') } end when 'Suse' it { is_expected.to contain_package('php5-fpm').with_ensure('present') } it { is_expected.to contain_service('php-fpm').with_ensure('running') } when 'FreeBSD' it { is_expected.not_to contain_package('php56-') } it { is_expected.not_to contain_package('php5-fpm') } it { is_expected.not_to contain_package('php-fpm') } it { is_expected.to contain_service('php-fpm').with_ensure('running') } else it { is_expected.to contain_package('php-fpm').with_ensure('present') } it { is_expected.to contain_service('php-fpm').with_ensure('running') } end # rubocop:enable RSpec/RepeatedExample it { is_expected.to contain_class('php::fpm::config').that_notifies('Class[php::fpm::service]') } it { is_expected.to contain_class('php::fpm::service') } end end end end diff --git a/spec/classes/php_repo_spec.rb b/spec/classes/php_repo_spec.rb index c7be774..dc1e542 100644 --- a/spec/classes/php_repo_spec.rb +++ b/spec/classes/php_repo_spec.rb @@ -1,31 +1,38 @@ require 'spec_helper' describe 'php::repo', type: :class do on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end let :pre_condition do 'include php' end + describe 'works without params' do + if facts[:os]['name'] == 'Archlinux' + it { is_expected.to compile.and_raise_error(%r{No repo available for}) } + else + it { is_expected.to compile.with_all_deps } + end + end describe 'when configuring a package repo' do case facts[:osfamily] when 'Debian' case facts[:operatingsystem] when 'Debian' it { is_expected.to contain_class('php::repo::debian') } when 'Ubuntu' it { is_expected.to contain_class('php::repo::ubuntu') } end when 'Suse' it { is_expected.to contain_class('php::repo::suse') } when 'RedHat' it { is_expected.to contain_class('php::repo::redhat') } end end end end end diff --git a/spec/classes/php_repo_ubuntu_spec.rb b/spec/classes/php_repo_ubuntu_spec.rb index 56b68a3..e283c6b 100644 --- a/spec/classes/php_repo_ubuntu_spec.rb +++ b/spec/classes/php_repo_ubuntu_spec.rb @@ -1,49 +1,20 @@ require 'spec_helper' describe 'php::repo::ubuntu', type: :class do on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end - case facts[:lsbdistcodename] - when 'trusty' - describe 'when called with no parameters on Ubuntu trusty' do - it { is_expected.to contain_exec('add-apt-repository-ppa:ondrej/php') } + describe 'works without params' do + if facts[:os]['name'] == 'Ubuntu' + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_apt__ppa('ppa:ondrej/php') } + else + it { is_expected.to compile.and_raise_error(%r{class php::repo::ubuntu does not work on OS}) } end - - describe 'when called with version 7.0 on Ubuntu trusty' do - let(:params) do - { - version: '7.0' - } - end - - it { is_expected.to contain_exec('add-apt-repository-ppa:ondrej/php') } - end - - describe 'when call with version 5.6 on Ubuntu trusty' do - let(:params) do - { - version: '5.6' - } - end - - it { is_expected.to contain_exec('add-apt-repository-ppa:ondrej/php') } - end - - describe 'when call with version 5.4 on Ubuntu trusty' do - let(:params) do - { - version: '5.4' - } - end - - it { is_expected.to raise_error(Puppet::Error) } - end - end end end end diff --git a/spec/classes/php_spec.rb b/spec/classes/php_spec.rb index ebb765d..7be513d 100644 --- a/spec/classes/php_spec.rb +++ b/spec/classes/php_spec.rb @@ -1,321 +1,323 @@ 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 '10' 'php7.3-cli' 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_package = case facts[:os]['name'] when 'Debian' case facts[:os]['release']['major'] when '10' 'php7.3-fpm' 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_package = case facts[:os]['name'] when 'Debian' case facts[:os]['release']['major'] when '10' 'php7.3-dev' 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 'works without params' do + it { is_expected.to compile.with_all_deps } + 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_package).with_ensure('present') } it { is_expected.to contain_package(php_dev_package).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 extensions' do let(:params) { { extensions: { xml: {} } } } it { is_expected.to contain_php__extension('xml').with_ensure('present') } end describe 'when called with ensure absent and extensions' do extensions = { xml: {} } let(:params) { { ensure: 'absent', extensions: extensions } } it { is_expected.to contain_php__extension('xml').with_ensure('absent') } case facts[:osfamily] when 'Debian' it { is_expected.to contain_package(php_cli_package).with_ensure('absent') } it { is_expected.to contain_package(php_fpm_package).with_ensure('absent') } it { is_expected.to contain_package(php_dev_package).with_ensure('absent') } when 'Suse' it { is_expected.to contain_package('php5').with_ensure('absent') } it { is_expected.to contain_package('php5-devel').with_ensure('absent') } when 'RedHat', 'CentOS' it { is_expected.to contain_package('php-cli').with_ensure('absent') } it { is_expected.to contain_package('php-common').with_ensure('absent') } 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 '10' '/etc/php/7.3/fpm/pool.d/www.conf' 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 '10' '/etc/php/7.3/fpm/pool.d/www.conf' 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 describe 'when called with pool_purge => true and fpm_pools => {}' do let(:params) { { pool_purge: true, fpm_pools: {} } } it { is_expected.to contain_class('php::fpm').with(pool_purge: true) } it { is_expected.not_to contain_php__fpm__pool('www') } end end end end