diff --git a/.sync.yml b/.sync.yml index 85de9bb..cb3729c 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,24 +1,27 @@ --- .travis.yml: docker_sets: - set: ubuntu1604-64 options: script: 'bundle exec rspec spec/acceptance/php56_spec.rb' - set: centos7-64 options: script: 'bundle exec rspec spec/acceptance/php56_spec.rb' + - set: ubuntu2004-64 + options: + script: 'bundle exec rspec spec/acceptance/php_spec.rb' - set: ubuntu1804-64 options: script: 'bundle exec rspec spec/acceptance/php_spec.rb' - set: ubuntu1604-64 options: script: 'bundle exec rspec spec/acceptance/php_spec.rb' - set: centos7-64 options: script: 'bundle exec rspec spec/acceptance/php_spec.rb' - set: debian9-64 options: script: 'bundle exec rspec spec/acceptance/php_spec.rb' secure: "GOhttACuJt+3s38m4WnW5RuTgwqaAoeEQnNT+X1Ukn7KdcIk4KV8NzYU/CC0VIm8lUOnBWYJKEC4ixX/J/4Wbxox2RAoKMQrO++L0DB1zTCJnq9SfoUBMaQhXvLu+PbxAR0p3P47ozra0C+pOWDpOaxT9ecufrPQt9W9Z4aY/bs=" spec/spec_helper_acceptance.rb: unmanaged: false diff --git a/.travis.yml b/.travis.yml index 017ebab..2f26976 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,109 +1,114 @@ --- # yamllint disable rule:line-length rule:truthy os: linux dist: focal language: ruby cache: bundler before_install: - yes | gem update --system - bundle --version script: - 'bundle exec rake $CHECK' jobs: fast_finish: true include: - rvm: 2.4.4 bundler_args: --without system_tests development release env: PUPPET_VERSION="~> 5.0" CHECK=test - rvm: 2.5.3 bundler_args: --without system_tests development release env: PUPPET_VERSION="~> 6.0" CHECK=test_with_coveralls - rvm: 2.5.3 bundler_args: --without system_tests development release env: PUPPET_VERSION="~> 6.0" CHECK=rubocop - rvm: 2.4.4 bundler_args: --without system_tests development release env: PUPPET_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=yes - rvm: 2.5.3 bundler_args: --without development release env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=ubuntu1604-64 CHECK=beaker script: bundle exec rspec spec/acceptance/php56_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=ubuntu1604-64 CHECK=beaker script: bundle exec rspec spec/acceptance/php56_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=centos7-64 CHECK=beaker script: bundle exec rspec spec/acceptance/php56_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=centos7-64 CHECK=beaker script: bundle exec rspec spec/acceptance/php56_spec.rb services: docker + - rvm: 2.5.3 + bundler_args: --without development release + env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=ubuntu2004-64 CHECK=beaker + script: bundle exec rspec spec/acceptance/php_spec.rb + services: docker - rvm: 2.5.3 bundler_args: --without development release env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=ubuntu1804-64 CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=ubuntu1804-64 CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=ubuntu1604-64 CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=ubuntu1604-64 CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=centos7-64 CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=centos7-64 CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=debian9-64 CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=debian9-64 CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker branches: only: - master - /^v\d/ notifications: email: false webhooks: https://voxpupu.li/incoming/travis irc: on_success: always on_failure: always channels: - "chat.freenode.org#voxpupuli-notifications" deploy: provider: puppetforge username: puppet password: secure: "GOhttACuJt+3s38m4WnW5RuTgwqaAoeEQnNT+X1Ukn7KdcIk4KV8NzYU/CC0VIm8lUOnBWYJKEC4ixX/J/4Wbxox2RAoKMQrO++L0DB1zTCJnq9SfoUBMaQhXvLu+PbxAR0p3P47ozra0C+pOWDpOaxT9ecufrPQt9W9Z4aY/bs=" on: tags: true # all_branches is required to use tags all_branches: true # Only publish the build marked with "DEPLOY_TO_FORGE" condition: "$DEPLOY_TO_FORGE = yes" diff --git a/manifests/globals.pp b/manifests/globals.pp index f3b4670..351b204 100644 --- a/manifests/globals.pp +++ b/manifests/globals.pp @@ -1,158 +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. # # 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', default => '7.3', }, 'Ubuntu' => $facts['os']['release']['major'] ? { + '20.04' => '7.4', '16.04' => '7.0', 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 { /^[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/metadata.json b/metadata.json index ac49eac..4ee2c02 100644 --- a/metadata.json +++ b/metadata.json @@ -1,87 +1,88 @@ { "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" + "18.04", + "20.04" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ "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/acceptance/php_spec.rb b/spec/acceptance/php_spec.rb index 95427df..888af45 100644 --- a/spec/acceptance/php_spec.rb +++ b/spec/acceptance/php_spec.rb @@ -1,105 +1,111 @@ 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-8} packagename = 'php5-fpm' when %r{debian-9} packagename = 'php7.0-fpm' when %r{debian-10} packagename = 'php7.3-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-18.04}, %r{ubuntu-16.04} + when %r{ubuntu-20.04}, %r{ubuntu-18.04}, %r{ubuntu-16.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-', settings => { extension => undef }, }, '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-8} packagename = 'php5-fpm' when %r{debian-9} packagename = 'php7.0-fpm' when %r{debian-10} packagename = 'php7.3-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_spec.rb b/spec/classes/php_spec.rb index 4d0f065..135626a 100644 --- a/spec/classes/php_spec.rb +++ b/spec/classes/php_spec.rb @@ -1,363 +1,375 @@ 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 '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 '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 '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 '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 '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 '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 66c2e85..2278c6f 100644 --- a/spec/defines/extension_spec.rb +++ b/spec/defines/extension_spec.rb @@ -1,262 +1,264 @@ 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 '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 7816c4a..1deca1a 100644 --- a/spec/defines/fpm_pool_spec.rb +++ b/spec/defines/fpm_pool_spec.rb @@ -1,43 +1,45 @@ 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 '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