# Inspec test for recipe irrigate-php::php82

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

control 'php82' do
  # For using node attributes in tests
  nodes_dir = '/tmp/kitchen/nodes'
  output = command("ls #{nodes_dir}").stdout.strip
  node_json = "#{nodes_dir}/#{output}"

  if file(node_json).exist?
    node = json(node_json).params
    case node['automatic']['platform_family']
    when 'debian'
      prerequisite_packages = %w(
        apt-transport-https
        bzip2
        ca-certificates
        curl
        gpg
        libbz2-dev
        libcurl4-openssl-dev
        libdb-dev
        libevent-dev
        libfreetype6-dev
        libgmp-dev
        libjpeg-dev
        libjpeg62-turbo-dev
        libmcrypt-dev
        libmemcached-dev
        libmhash-dev
        libmhash2
        libpng-dev
        libssl-dev
        libtiff-dev
        libxml2-dev
        libzip-dev
        lsb-release
        memcached
        software-properties-common
        unzip
        wget
      )

      prerequisite_packages.each do |package|
        describe package(package) do
          it { should be_installed }
        end
      end

      describe apt('https://packages.sury.org/php') do
        it { should exist }
        it { should be_enabled }
      end

      packages = %w(
        php8.2
        php8.2-apcu
        php8.2-bcmath
        php8.2-cli
        php8.2-common
        php8.2-curl
        php8.2-dev
        php8.2-gd
        php8.2-gmp
        php8.2-imagick
        php8.2-ldap
        php8.2-mbstring
        php8.2-mcrypt
        php8.2-memcache
        php8.2-memcached
        php8.2-mysql
        php8.2-opcache
        php8.2-pgsql
        php8.2-redis
        php8.2-redis
        php8.2-soap
        php8.2-ssh2
        php8.2-uploadprogress
        php8.2-xml
        php8.2-yaml
        php8.2-zip
        php-pear
      )

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

      describe file '/etc/php/8.2/cli/php.ini' do
        it { should exist }
        its('owner') { should eq 'root' }
        its('group') { should eq 'root' }
        its('mode') { should cmp '0644' }
      end
    end
  end
end
