FROM wordpress:6.7.2-php8.1-fpm

# Install dependencies
RUN apt-get update && apt-get install -y \
    vim \
    libzip-dev \
    procps \
    net-tools \
    unzip \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install mysqli pdo pdo_mysql zip

# Composer is managed on the host and mounted via volume

# Install WP-CLI (download to /tmp first)
RUN curl -o /tmp/wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
    && echo "DEBUG: WP-CLI Downloaded to /tmp" \
    && ls -l /tmp/wp-cli.phar
RUN chmod +x /tmp/wp-cli.phar \
    && echo "DEBUG: WP-CLI chmod done" \
    && ls -l /tmp/wp-cli.phar
RUN mv /tmp/wp-cli.phar /usr/local/bin/wp \
    && echo "DEBUG: WP-CLI Moved to /usr/local/bin/wp" \
    && ls -l /usr/local/bin/wp

# Set working directory
WORKDIR /var/www/html

# Copy composer files
COPY composer.* ./

# Dependencies are installed on the host and mounted via volume

# Verify installations
RUN php -r "if (!extension_loaded('pdo_mysql')) { exit(1); }"
# RUN composer --version # Removed as composer is not installed in image

# WordPress test framework is installed via Composer (wp-phpunit/wp-phpunit)
# Remove conflicting manual installation:
# RUN curl -o /tmp/wordpress-tests.tar.gz https://wordpress.org/wordpress-tests-latest.tar.gz
# RUN mkdir -p /tmp/wordpress-tests-lib && tar -xzf /tmp/wordpress-tests.tar.gz -C /tmp/wordpress-tests-lib --strip-components=1
# RUN rm /tmp/wordpress-tests.tar.gz