<commit_before>require 'spec_helper'

describe 'composer' do
  context 'on RedHat operating system family' do
    let(:facts) { {
        :osfamily => 'RedHat',
    } }

    it { should include_class('composer::params') }

    it {
      should contain_exec('download_composer').with({
        :command     => 'curl -s http://getcomposer.org/installer | php',
        :cwd         => '/tmp',
        :creates     => '/tmp/composer.phar',
        :logoutput   => false,
      })
    }

    it {
      should contain_augeas('whitelist_phar').with({
        :context     => '/files/etc/suhosin.ini/suhosin',
        :changes     => 'set suhosin.executor.include.whitelist phar',
      })
    }

    it {
      should contain_augeas('allow_url_fopen').with({
        :context    => '/files/etc/php.ini/PHP',
        :changes    => 'set allow_url_fopen On',
      })
    }

    context 'with default parameters' do
      it 'should compile' do
        catalogue
      end

      it { should contain_package('php-cli').with_ensure('present') }
      it { should contain_package('curl').with_ensure('present') }
      it { should contain_file('/usr/local/bin').with_ensure('directory') }

      it {
        should contain_file('/usr/local/bin/composer').with({
          :source => 'present',
          :source => '/tmp/composer.phar',
          :mode   => '0755',
        })
      }
    end

    context 'with custom parameters' do
      let(:params) { {
        :target_dir    => '/you_sir/lowcal/been',
        :php_package   => 'php8-cli',
        :composer_file => 'compozah',
        :curl_package  => 'kerl',
      } }

      it 'should compile' do
        catalogue
      end

      it { should contain_package('php8-cli').with_ensure('present') }
      it { should contain_package('kerl').with_ensure('present') }
      it { should contain_file('/you_sir/lowcal/been').with_ensure('directory') }

      it {
        should contain_file('/you_sir/lowcal/been/compozah').with({
          :source => 'present',
          :source => '/tmp/composer.phar',
          :mode   => '0755',
        })
      }
    end
  end
end<commit_msg>adding tests for new suhosin_enable param and Debian family<commit_after>require 'spec_helper'

describe 'composer' do
  ['RedHat', 'Debian'].each do |osfamily|
    case osfamily
    when 'RedHat'
      php_package = 'php-cli'
      php_context = '/files/etc/php.ini/PHP'
      suhosin_context = '/files/etc/suhosin.ini/suhosin'
    when 'Debian'
      php_package = 'php5-cli'
      php_context = '/files/etc/php5/cli/php.ini/PHP'
      suhosin_context = '/files/etc/php5/conf.d/suhosin.ini/suhosin'
    else
      php_package = 'php-cli'
      php_context = '/files/etc/php.ini/PHP'
      suhosin_context = '/files/etc/suhosin.ini/suhosin'
    end

    context "on #{osfamily} operating system family" do
      let(:facts) { {
          :osfamily => osfamily,
      } }

      it { should include_class('composer::params') }

      it {
        should contain_exec('download_composer').with({
          :command     => 'curl -s http://getcomposer.org/installer | php',
          :cwd         => '/tmp',
          :creates     => '/tmp/composer.phar',
          :logoutput   => false,
        })
      }

      it {
        should contain_augeas('whitelist_phar').with({
          :context     => suhosin_context,
          :changes     => 'set suhosin.executor.include.whitelist phar',
        })
      }

      it {
        should contain_augeas('allow_url_fopen').with({
          :context    => php_context,
          :changes    => 'set allow_url_fopen On',
        })
      }

      context 'with default parameters' do
        it 'should compile' do
          catalogue
        end

        it { should contain_package(php_package).with_ensure('present') }
        it { should contain_package('curl').with_ensure('present') }
        it { should contain_file('/usr/local/bin').with_ensure('directory') }

        it {
          should contain_file('/usr/local/bin/composer').with({
            :source => 'present',
            :source => '/tmp/composer.phar',
            :mode   => '0755',
          })
        }
      end

      context 'with custom parameters' do
        let(:params) { {
          :target_dir      => '/you_sir/lowcal/been',
          :php_package     => 'php8-cli',
          :composer_file   => 'compozah',
          :curl_package    => 'kerl',
          :suhosin_enabled => false,
        } }

        it 'should compile' do
          catalogue
        end

        it { should contain_package('php8-cli').with_ensure('present') }
        it { should contain_package('kerl').with_ensure('present') }
        it { should contain_file('/you_sir/lowcal/been').with_ensure('directory') }

        it {
          should contain_file('/you_sir/lowcal/been/compozah').with({
            :source => 'present',
            :source => '/tmp/composer.phar',
            :mode   => '0755',
          })
        }

        it { should_not contain_augeas('whitelist_phar') }
        it { should_not contain_augeas('allow_url_fopen') }

      end
    end
  end
end
{'fraction_non_alphanumeric': 0.14140426364169764, 'fraction_numerical': 0.004498337570897712, 'mean_word_length': 1.992393212404915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1337028', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1593, 'n_words': 288}