# Inspec test for recipe irrigate-php::php73

# The Inspec reference, with examples and extensive documentation, can be
# found at http://inspec.io/docs/reference/resources/

control 'php73' do
  attribute_file = '/tmp/kitchen/nodes/default-centos-76.json'
  if file(attribute_file).exist?
    node = json(attribute_file).params
    case node['automatic']['platform_family']
    when 'rhel'
      if node['automatic']['platform_version'].to_s.start_with?('7')
        describe command('yum repolist') do
          its('stdout') { should include 'remi-php73' }
          its('stdout') { should include 'remi-php73-debuginfo' }
          its('stdout') { should include 'remi73-safe' }
        end

        packages = %w(
          autoconf
          bzip2-devel
          epel-release
          freetype-devel
          gcc-c++
          glibc
          gmp-devel
          httpd-devel
          ImageMagick
          ImageMagick-devel
          libcurl-devel
          libdb4-devel
          libevent
          libjpeg-turbo
          libjpeg-turbo-devel
          libmcrypt
          libmcrypt-devel
          libmemcached
          libpng-devel
          libtiff
          libtiff-devel
          libxml2-devel
          make
          memcached
          mhash
          mhash-devel
          mod_ssl
          openssl-devel
          php73
          php73-php
          php73-php-bcmath
          php73-php-cli
          php73-php-common
          php73-php-devel
          php73-php-gd
          php73-php-gmp
          php73-php-ldap
          php73-php-mbstring
          php73-php-mysqlnd
          php73-php-opcache
          php73-php-pear
          php73-php-pecl-imagick
          php73-php-pecl-imagick-devel
          php73-php-pecl-mcrypt
          php73-php-pecl-memcache
          php73-php-pecl-memcached
          php73-php-pecl-redis4
          php73-php-pecl-ssh2
          php73-php-pecl-uploadprogress
          php73-php-pecl-zip
          php73-php-pgsql
          php73-php-phpiredis
          php73-php-soap
          php73-php-xml
          unixODBC
          unixODBC-devel
        )

        packages.each do |name|
          describe package name do
            it { should be_installed }
          end
        end

        require 'erb'
        node['php'] = node['default']['php']
        template_sh = File.read('templates/default/remi-php73.sh.erb')
        rendered_content_sh = ERB.new(template_sh).result(binding)
        describe file '/etc/profile.d/remi-php73.sh' do
          it { should exist }
          its('owner') { should eq 'root' }
          its('group') { should eq 'root' }
          its('mode') { should cmp '0644' }
          its('content') { should eq rendered_content_sh }
        end

        template_ini = File.read('templates/default/php.ini.erb')
        rendered_content_ini = ERB.new(template_ini).result(binding)
        describe file '/etc/opt/remi/php73/php.ini' do
          it { should exist }
          its('owner') { should eq 'root' }
          its('group') { should eq 'root' }
          its('mode') { should cmp '0644' }
          its('content') { should eq rendered_content_ini }
        end

        describe file '/usr/local/bin/php73' do
          it { should be_symlink }
          its('link_path') { should eq '/opt/remi/php73/root/usr/bin/php' }
        end

      end
    end
  else
    puts "File #{attribute_file} does not exist, skiping attribute-depending checks"
  end
end
