Skip to content

Commit

Permalink
Merge pull request #119 from 2pisoftware/feat/phpunit-10
Browse files Browse the repository at this point in the history
Phpunit 10 and dev tools script
  • Loading branch information
mattbell87 authored Mar 14, 2024
2 parents 4f0244d + 7feb2c0 commit f1863f5
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 953 deletions.
11 changes: 11 additions & 0 deletions .codepipeline/docker/cmfive_dev_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# To be run on the container, see install_dev_tools.sh
set -e

echo "🏗️ Installing required system packages"
apk add --no-cache php$PHPVERSION-dom php$PHPVERSION-xmlwriter php$PHPVERSION-tokenizer php$PHPVERSION-ctype mysql-client mariadb-connector-c-dev bash

echo "🔨 Installing phpunit v${PHPUNIT}"
cd /usr/local/bin && curl -L https://phar.phpunit.de/phpunit-${PHPUNIT}.phar -o phpunit && chmod +x phpunit && chmod 777 .

# NOTE: Playwright is not recommended to be installed here
44 changes: 0 additions & 44 deletions .codepipeline/docker/config.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,50 +59,6 @@
Config::set("system.environment", "development");
Config::set("core_template.foundation.reveal.animation", "none");
Config::set("core_template.foundation.reveal.animation_speed", 0);
//========== must be "ENABLED" to run ==========================
//========== "config" will pass through to CmfiveSite helper ===
Config::set('system.environment', "development");
Config::set(
"tests",
[
"testrunner" => "ENABLED",
"config" => '',
"yaml" =>
[
"- WebDriver:" =>
[
"url" => "http://webapp:3000",
"browser" => "chrome",
"wait" => "8",
"host" => "seleniumDrv",
"port" => "4444",
"capabilities" =>
[
"acceptInsecureCerts" => true,
"goog:chromeOptions" => [
"w3c" => "false",
"args" => '['
.'"--headless=new","--disable-gpu",'
.'"-proxy-bypass-list=*","--proxy-server=direct://","--dns-prefetch-disable",'
.'"--disk-cache-size=0","–-media-cache-size=0",'
.'"--window-size=1920,1200","--disable-remote-fonts",'
.'"--ignore-certificate-errors","--disable-extensions","--no-sandbox",'
// .'"--enable-logging=/var/customlog/ch.log","--v=1'
.'"--disable-dev-shm-usage"'
.']'
]
]
],
"- Db:" =>
[
"dsn" => "mysql:host=mysqldb:3306;dbname=cmfive",
"user" => "cmfive",
"password" => "cmfive",
],
"- Asserts:" => "",
]
]
);

//========= Anonymous Access ================================
// bypass authentication if sent from the following IP addresses
Expand Down
113 changes: 113 additions & 0 deletions .codepipeline/docker/install_dev_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/sh
# Installs the dev tools to the desired cmfive container

## USAGE:
# If you have docker compose running:
# ./install_dev_tools.sh
# Or specify container name:
# CONTAINER=cmfive_webapp_1 ./install_dev_tools.sh
# To skip playwright dependencies:
# SKIP_PLAYWRIGHT=true ./install_dev_tools.sh

#Settings
PHPVERSION=81
PHPUNIT=10

# If CONTAINER is not defined, default to the container name of the webapp service in docker compose
if [ -z "$CONTAINER" ]; then
CONTAINER=$(docker compose ps -q webapp)
if [ -z "$CONTAINER" ]; then
echo "❌ Error: Could not find container name. Please specify the container name with CONTAINER=container_name"
exit 1
fi
echo "💭 Using container from docker compose"
fi

# Check if $CONTAINER is a valid container name or id
if ! docker inspect --type=container "$CONTAINER" >/dev/null 2>&1; then
echo "❌ Error: Invalid container name or id: $CONTAINER"
exit 1
fi

# Tell user if test dir already exists in container (and has greater than 0 files)
if docker exec $CONTAINER sh -c 'test -d "/var/www/html/test" && test "$(ls -A /var/www/html/test | wc -l)" -gt 0'; then
echo "💭 Test directory exists in the container"
else
# Find test dir
TEST_DIR=""
if test -d "./test"; then
TEST_DIR="./test"
elif test -d "../test"; then
TEST_DIR="../test"
elif test -d "../../test"; then
TEST_DIR="../../test"
fi
# If test dir is found and the container doesnt have an existing test dir, copy it
if [ -n "$TEST_DIR" ] ; then
echo "💭 Using test directory: $TEST_DIR"
echo "📦 Copying test directory to container"
docker cp "$TEST_DIR" "$CONTAINER:/var/www/html"
if [ $? -ne 0 ]; then
echo "❌ Error: Could not copy test directory to container"
exit 1
fi
else
# If test dir is not found, exit the script
echo "❌ Error: Could not find test directory"
exit 1
fi
fi

echo ""
echo "👷 -- Installing dev tools to container: $CONTAINER --"
echo ""

# Copy cmfive_dev_tools
SCRIPT_DIR=$(dirname "$0")
docker cp "$SCRIPT_DIR/cmfive_dev_tools.sh" "$CONTAINER:/home/cmfive"
if [ $? -ne 0 ]; then
echo "❌ Error: Could not copy cmfive_dev_tools.sh to container"
exit 1
fi

# Run cmfive_dev_tools
docker exec $CONTAINER sh -c "PHPUNIT=${PHPUNIT} PHPVERSION=${PHPVERSION} /home/cmfive/cmfive_dev_tools.sh"
if [ $? -ne 0 ]; then
echo "❌ Error: cmfive_dev_tools.sh failed"
exit 1
fi

echo ""
echo "👷 -- Installing host machine dev tools --"
echo ""

# If SKIP_PLAYWRIGHT is true skip the rest of the script
if [ "$SKIP_PLAYWRIGHT" = true ]; then
echo "✔️ Dev tools installed successfully"
exit 0
fi

# --- Install Playwright dependencies ---
echo "🔨 Installing Playwright dependencies"

# If not Debian or Ubuntu exit the script
if ! command -v apt-get &> /dev/null; then
echo "⚠️ WARNING: Playwright dependencies are only supported on Debian and Ubuntu"
echo "✔️ Dev tools installed successfully"
exit 0
fi

# Check if npm is installed on host machine
if ! command -v npm &> /dev/null; then
echo "⚠️ WARNING: npm is not installed on this machine. Please install npm and run 'npm install' in the test directory"
echo "✔️ Dev tools installed successfully"
exit 0
fi

yes | npx playwright install --with-deps
if [ $? -ne 0 ]; then
echo "❌ Error: Failed to install Playwright dependencies"
exit 1
fi

echo "✔️ Dev tools installed successfully"
37 changes: 0 additions & 37 deletions .codepipeline/test_agent/configs/test_agent-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,43 +60,6 @@
Config::set("system.environment", "development");
Config::set("core_template.foundation.reveal.animation", "none");
Config::set("core_template.foundation.reveal.animation_speed", 0);
//========== must be "ENABLED" to run ==========================
Config::set(
"tests",
[
"testrunner" => "",
"config" => '',
"yaml" =>
[
"- WebDriver:" =>
[
"url" => "http://webapp:3000",
"browser" => "chrome",
"wait" => "60",
"host" => "seleniumDrv",
"port" => "4444",
"capabilities" =>
[
"acceptInsecureCerts" => true,
"goog:chromeOptions" => [
"w3c" => "false",
"args" => '["--headless","--disable-gpu","--window-size=1920,1200","--ignore-certificate-errors","--disable-extensions","--no-sandbox","--disable-dev-shm-usage"]'
]
]
],
"- Db:" =>
[
"dsn" => (getenv('DB') ?: 'mysql')
. ":host=" . (getenv('DB_HOST') ?: 'localhost')
. ":" . (getenv('DB_PORT') ?: '')
. ";dbname=" . (getenv('DB_DATABASE') ?: '<database>'),
"user" => (getenv('DB_USERNAME') ?: '<username>'),
"password" => (getenv('DB_PASSWORD') ?: '<password>'),
],
"- Asserts:" => "",
]
]
);

//========= Anonymous Access ================================
// bypass authentication if sent from the following IP addresses
Expand Down
Loading

0 comments on commit f1863f5

Please sign in to comment.