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/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