diff --git a/manifests/globals.pp b/manifests/globals.pp index d466299..a50d304 100644 --- a/manifests/globals.pp +++ b/manifests/globals.pp @@ -1,161 +1,159 @@ # 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. # class php::globals ( Optional[Pattern[/^(rh-)?(php)?[578](\.)?[0-9]/]] $php_version = undef, Optional[Stdlib::Absolutepath] $config_root = undef, Optional[Stdlib::Absolutepath] $fpm_pid_file = undef, Optional[Enum['rhscl', 'remi']] $rhscl_mode = undef, ) { $default_php_version = $facts['os']['name'] ? { 'Debian' => $facts['os']['release']['major'] ? { - '9' => '7.0', '10' => '7.3', '11' => '7.4', default => fail("Unsupported Debian release: ${fact('os.release.major')}"), }, 'Ubuntu' => $facts['os']['release']['major'] ? { - '16.04' => '7.0', '18.04' => '7.2', '20.04' => '7.4', default => fail("Unsupported Ubuntu release: ${fact('os.release.major')}"), }, 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 { /^[578].[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]/, /^8\.[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/pear.pp b/manifests/pear.pp index 45f03d4..6e697d0 100644 --- a/manifests/pear.pp +++ b/manifests/pear.pp @@ -1,62 +1,62 @@ # Install PEAR package manager # # === Parameters # # [*ensure*] # The package ensure of PHP pear to install and run pear auto_discover # # [*package*] # The package name for PHP pear # class php::pear ( String $ensure = $php::pear_ensure, Optional[String] $package = undef, Boolean $manage_repos = $php::manage_repos, ) inherits php::params { assert_private() # Defaults for the pear package name if $package { $package_name = $package } else { if $facts['os']['name'] == 'Amazon' { # On Amazon Linux the package name is also just 'php-pear'. # This would normally not be problematic but if you specify a # package_prefix other than 'php' then it will fail. $package_name = "php-${php::params::pear_package_suffix}" } else { case $facts['os']['family'] { 'Debian': { # Debian is a litte stupid: The pear package is called 'php-pear' # even though others are called 'php5-fpm' or 'php5-dev' $package_name = "php-${php::params::pear_package_suffix}" } default: { # This is the default for all other architectures $package_name = "${php::package_prefix}${php::params::pear_package_suffix}" } } } } # the apt module provides apt::update. apt is only included if we manage any repos $require = $manage_repos ? { true => Class['apt::update'], false => 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' and versioncmp($facts['os']['release']['full'], '18.04') >= 0 { ensure_packages(["${php::package_prefix}xml"], { ensure => present, require => $require, }) package { $package_name: ensure => $ensure, require => [$require,Class['php::cli'],Package["${php::package_prefix}xml"]], } } else { package { $package_name: ensure => $ensure, require => Class['php::cli'], } } } diff --git a/metadata.json b/metadata.json index 253353f..15bac2d 100644 --- a/metadata.json +++ b/metadata.json @@ -1,87 +1,85 @@ { "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 < 9.0.0" }, { "name": "puppetlabs/apt", "version_requirement": ">= 4.4.0 < 9.0.0" }, { "name": "puppetlabs/inifile", "version_requirement": ">= 1.4.1 < 6.0.0" }, { "name": "puppet/zypprepo", "version_requirement": ">= 2.0.0 < 5.0.0" }, { "name": "puppet/archive", "version_requirement": ">= 1.0.0 < 8.0.0" } ], "requirements": [ { "name": "puppet", "version_requirement": ">= 6.1.0 < 8.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ - "16.04", "18.04", "20.04" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ - "9", "10", "11" ] }, { "operatingsystem": "RedHat", "operatingsystemrelease": [ "7" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "7" ] }, { "operatingsystem": "FreeBSD", "operatingsystemrelease": [ "11" ] }, { "operatingsystem": "SLES", "operatingsystemrelease": [ "11" ] }, { "operatingsystem": "OpenSUSE" }, { "operatingsystem": "Archlinux" } ] } diff --git a/spec/acceptance/php_spec.rb b/spec/acceptance/php_spec.rb index 3dd6ba6..f5fc2c3 100644 --- a/spec/acceptance/php_spec.rb +++ b/spec/acceptance/php_spec.rb @@ -1,108 +1,98 @@ require 'spec_helper_acceptance' describe 'php with default settings' do context 'default parameters' do it 'works with defaults' do pp = 'include php' # Run it twice and test for idempotency apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end case default[:platform] when %r{ubuntu-20.04} packagename = 'php7.4-fpm' when %r{ubuntu-18.04} packagename = 'php7.2-fpm' - when %r{ubuntu-16.04} - packagename = 'php7.0-fpm' when %r{el} packagename = 'php-fpm' - when %r{debian-9} - packagename = 'php7.0-fpm' when %r{debian-10} packagename = 'php7.3-fpm' when %r{debian-11} packagename = 'php7.4-fpm' end describe package(packagename) do it { is_expected.to be_installed } end describe service(packagename) do it { is_expected.to be_running } it { is_expected.to be_enabled } end end context 'default parameters with extensions' do case default[:platform] - when %r{ubuntu-20.04}, %r{ubuntu-18.04}, %r{ubuntu-16.04} + when %r{ubuntu-20.04}, %r{ubuntu-18.04} it 'works with defaults' do case default[:platform] when %r{ubuntu-20.04} simplexmlpackagename = 'php7.4-xml' when %r{ubuntu-18.04} simplexmlpackagename = 'php7.2-xml' - when %r{ubuntu-16.04} - simplexmlpackagename = 'php7.0-xml' end pp = <<-EOS class{'php': extensions => { 'mysql' => {}, 'gd' => {}, 'net-url' => { package_prefix => 'php-', }, 'simplexml' => { package_name => '#{simplexmlpackagename}', } } } EOS # Run it twice and test for idempotency apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end else it 'works with defaults' do pp = <<-EOS class{'php': extensions => { 'mysql' => {}, 'gd' => {} } } EOS # Run it twice and test for idempotency apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end end case default[:platform] when %r{ubuntu-20.04} packagename = 'php7.4-fpm' when %r{ubuntu-18.04} packagename = 'php7.2-fpm' - when %r{ubuntu-16.04} - packagename = 'php7.0-fpm' when %r{el} packagename = 'php-fpm' - when %r{debian-9} - packagename = 'php7.0-fpm' when %r{debian-10} packagename = 'php7.3-fpm' when %r{debian-11} packagename = 'php7.4-fpm' end describe package(packagename) do it { is_expected.to be_installed } end describe service(packagename) do it { is_expected.to be_running } it { is_expected.to be_enabled } end end end diff --git a/spec/classes/php_fpm_service_spec.rb b/spec/classes/php_fpm_service_spec.rb index 96855c7..3fb2c8f 100644 --- a/spec/classes/php_fpm_service_spec.rb +++ b/spec/classes/php_fpm_service_spec.rb @@ -1,44 +1,48 @@ 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') } + when '18.04' + it { is_expected.to contain_service('php7.2-fpm').with_ensure('running') } + when '10' + it { is_expected.to contain_service('php7.3-fpm').with_ensure('running') } + when '20.04', '11' + it { is_expected.to contain_service('php7.4-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 45f29d9..1d39fa7 100644 --- a/spec/classes/php_fpm_spec.rb +++ b/spec/classes/php_fpm_spec.rb @@ -1,42 +1,48 @@ 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') } + when '18.04' + it { is_expected.to contain_package('php7.2-fpm').with_ensure('present') } + it { is_expected.to contain_service('php7.2-fpm').with_ensure('running') } + when '20.04', '11' + it { is_expected.to contain_package('php7.4-fpm').with_ensure('present') } + it { is_expected.to contain_service('php7.4-fpm').with_ensure('running') } + when '10' + it { is_expected.to contain_package('php7.3-fpm').with_ensure('present') } + it { is_expected.to contain_service('php7.3-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_spec.rb b/spec/classes/php_spec.rb index 35c8862..778b6d3 100644 --- a/spec/classes/php_spec.rb +++ b/spec/classes/php_spec.rb @@ -1,387 +1,363 @@ 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 '11' 'php7.4-cli' when '10' 'php7.3-cli' - when '9' - 'php7.0-cli' else 'php5-cli' end when 'Ubuntu' case facts[:os]['release']['major'] when '20.04' 'php7.4-cli' 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 '11' 'php7.4-fpm' when '10' 'php7.3-fpm' - when '9' - 'php7.0-fpm' else 'php5-fpm' end when 'Ubuntu' case facts[:os]['release']['major'] when '20.04' 'php7.4-fpm' 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 '11' 'php7.4-dev' when '10' 'php7.3-dev' - when '9' - 'php7.0-dev' else 'php5-dev' end when 'Ubuntu' case facts[:os]['release']['major'] when '20.04' 'php7.4-dev' 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 '11' '/etc/php/7.4/fpm/pool.d/www.conf' 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 '20.04' '/etc/php/7.4/fpm/pool.d/www.conf' 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 '11' '/etc/php/7.4/fpm/pool.d/www.conf' 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 '20.04' '/etc/php/7.4/fpm/pool.d/www.conf' 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 configured with a pool with apparmor_hat parameter' do let(:params) { { fpm_pools: { 'www' => { 'apparmor_hat' => 'www' } } } } it { is_expected.to contain_php__fpm__pool('www').with(apparmor_hat: 'www') } dstfile = case facts[:osfamily] when 'Debian' case facts[:os]['name'] when 'Debian' case facts[:os]['release']['major'] when '11' '/etc/php/7.4/fpm/pool.d/www.conf' 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 '20.04' '/etc/php/7.4/fpm/pool.d/www.conf' 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{apparmor_hat = www}) } 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 diff --git a/spec/defines/extension_spec.rb b/spec/defines/extension_spec.rb index 32e2612..a3d273b 100644 --- a/spec/defines/extension_spec.rb +++ b/spec/defines/extension_spec.rb @@ -1,266 +1,262 @@ require 'spec_helper' describe 'php::extension' do on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end let(:pre_condition) { 'include php' } unless facts[:osfamily] == 'Suse' || facts[:osfamily] == 'FreeBSD' # FIXME: something is wrong on these etcdir = case facts[:os]['name'] when 'Debian' case facts[:os]['release']['major'] when '11' '/etc/php/7.4/mods-available' when '10' '/etc/php/7.3/mods-available' - when '9' - '/etc/php/7.0/mods-available' else '/etc/php5/mods-available' end when 'Ubuntu' case facts[:os]['release']['major'] when '20.04' '/etc/php/7.4/mods-available' when '18.04' '/etc/php/7.2/mods-available' - when '16.04' - '/etc/php/7.0/mods-available' else '/etc/php5/mods-available' end when 'Archlinux' '/etc/php/conf.d' else '/etc/php.d' end context 'installation from repository' do let(:title) { 'json' } let(:params) do { package_prefix: 'php5-', settings: { 'test' => 'foo' } } end it { is_expected.to contain_package('php5-json') } it do is_expected.to contain_php__config('json').with( file: "#{etcdir}/json.ini", config: { 'extension' => 'json.so', 'test' => 'foo' } ) end end context 'configure extension without installing a package' do let(:title) { 'json' } let(:params) do { provider: 'none', settings: { 'test' => 'foo' } } end it do is_expected.to contain_php__config('json').with( file: "#{etcdir}/json.ini", require: nil, config: { 'extension' => 'json.so', 'test' => 'foo' } ) end end context 'add settings prefix if requested' do let(:title) { 'json' } let(:params) do { name: 'json', settings_prefix: true, settings: { 'test' => 'foo' } } end it do is_expected.to contain_php__config('json').with( config: { 'extension' => 'json.so', 'json.test' => 'foo' } ) end end context 'use specific settings prefix if requested' do let(:title) { 'json' } let(:params) do { name: 'json', settings_prefix: 'bar', settings: { 'test' => 'foo' } } end it do is_expected.to contain_php__config('json').with( config: { 'extension' => 'json.so', 'bar.test' => 'foo' } ) end end context 'extensions can be configured as zend' do let(:title) { 'xdebug' } let(:params) do { zend: true } end it { is_expected.to contain_php__config('xdebug').with_config('zend_extension' => 'xdebug.so') } end context 'pecl extensions support so_name' do let(:title) { 'zendopcache' } let(:params) do { provider: 'pecl', zend: true, so_name: 'opcache' } end it do is_expected.to contain_php__config('zendopcache').with( file: "#{etcdir}/opcache.ini", config: { 'zend_extension' => 'opcache.so' } ) end end context 'add ini file prefix if requested' do let(:title) { 'zendopcache' } let(:params) do { provider: 'pecl', zend: true, ini_prefix: '10-', so_name: 'opcache' } end it do is_expected.to contain_php__config('zendopcache').with( file: "#{etcdir}/10-opcache.ini", config: { 'zend_extension' => 'opcache.so' } ) end end context 'pecl extensions support php_api_version' do let(:title) { 'xdebug' } let(:params) do { provider: 'pecl', zend: true, php_api_version: '20100525' } end it { is_expected.to contain_php__config('xdebug').with_config('zend_extension' => '/usr/lib/php5/20100525/xdebug.so') } end if facts[:os]['family'] == 'Debian' context 'on Debian family' do context 'zend extensions call ext_tool_enable' do let(:title) { 'xdebug' } let(:params) do { zend: true } end it { is_expected.to contain_exec('ext_tool_enable_xdebug') } end end end case facts[:os]['name'] when 'Debian' context 'on Debian' do let(:title) { 'xdebug' } it { is_expected.to contain_php__config('xdebug').with_file("#{etcdir}/xdebug.ini") } # note to consider: As of PHP 5.2.0, the JSON extension is bundled and compiled into PHP by default # http://php.net/manual/en/json.installation.php context 'pecl installation' do let(:title) { 'json' } let(:params) do { provider: 'pecl', header_packages: ['libmemcached-dev'], name: 'nice_name', settings: { 'test' => 'foo' } } end it { is_expected.to contain_package('json') } it { is_expected.to contain_package('libmemcached-dev') } it { is_expected.to contain_package('build-essential') } it do is_expected.to contain_php__config('json').with( file: "#{etcdir}/nice_name.ini", config: { 'extension' => 'nice_name.so', 'test' => 'foo' } ) end end end when 'Ubuntu' context 'on Ubuntu' do context 'do not setup mysql.ini' do let(:title) { 'mysql' } let(:params) do { name: 'mysql' } end it do is_expected.to contain_file("#{etcdir}/mysql.ini").with(ensure: 'absent') end end end end end end end end diff --git a/spec/defines/fpm_pool_spec.rb b/spec/defines/fpm_pool_spec.rb index e15d468..d6bdd1f 100644 --- a/spec/defines/fpm_pool_spec.rb +++ b/spec/defines/fpm_pool_spec.rb @@ -1,47 +1,43 @@ require 'spec_helper' describe 'php::fpm::pool' do on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end let(:pre_condition) { 'include php' } case facts[:os]['name'] when 'Debian' context 'plain config' do let(:title) { 'unique-name' } let(:params) { {} } case facts[:os]['release']['major'] when '11' it { is_expected.to contain_file('/etc/php/7.4/fpm/pool.d/unique-name.conf') } when '10' it { is_expected.to contain_file('/etc/php/7.3/fpm/pool.d/unique-name.conf') } - when '9' - it { is_expected.to contain_file('/etc/php/7.0/fpm/pool.d/unique-name.conf') } else it { is_expected.to contain_file('/etc/php5/fpm/pool.d/unique-name.conf') } end end when 'Ubuntu' context 'plain config' do let(:title) { 'unique-name' } let(:params) { {} } case facts[:os]['release']['major'] when '20.04' it { is_expected.to contain_file('/etc/php/7.4/fpm/pool.d/unique-name.conf') } when '18.04' it { is_expected.to contain_file('/etc/php/7.2/fpm/pool.d/unique-name.conf') } - when '16.04' - it { is_expected.to contain_file('/etc/php/7.0/fpm/pool.d/unique-name.conf') } else it { is_expected.to contain_file('/etc/php5/fpm/pool.d/unique-name.conf') } end end end end end end