Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phpunit 10 and dev tools script #119

Merged
merged 11 commits into from
Mar 14, 2024
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
if docker exec $CONTAINER test -d /var/www/html/test/.install; 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
6 changes: 5 additions & 1 deletion cmfiveTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,12 @@ function getTestsForModule($module)
$details['actor'] = rtrim($file, ".php");
}
if ($ext == UNIT_DIRECTORY) {
$modFile = $module . "_" . $file;
$modFile = $module . "/" . $file;
$details['unit'] = $modFile;
//Create $module directory if it doesn't exist
if (!is_dir(ROOT_PATH . DS . $dest_paths[$ext] . DS . $module)) {
mkdir(ROOT_PATH . DS . $dest_paths[$ext] . DS . $module);
}
}
if ($ext == $findActor) {
$details['actor'] = rtrim($file, ".php");
Expand Down
15 changes: 0 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ services:
- ENVIRONMENT=development
volumes:
- ./:/var/www/html:rw
- ./test/Codeception/tests/boilerplate:/var/www/html/test/Codeception/tests/boilerplate
- ./test/Codeception/tests/_output:/var/www/html/test/Codeception/tests/_output
ports:
- "3000:80"
- "3443:443"
Expand Down Expand Up @@ -74,19 +72,6 @@ services:
webapp:
condition: service_healthy

seleniumsrv:
image: selenium/standalone-chrome:111.0
container_name: seleniumDrv
hostname: seleniumDrv
ports:
- "4444:4444"
environment:
- TZ=Australia/Sydney
- START_XVFB=false
shm_size: '4gb'
networks:
- default

volumes:
dbdata:
driver: local
Expand Down
26 changes: 0 additions & 26 deletions test/.install/install.sh

This file was deleted.

19 changes: 0 additions & 19 deletions test/Codeception/.gitignore

This file was deleted.

48 changes: 0 additions & 48 deletions test/Codeception/readme.txt

This file was deleted.

Empty file.
Loading
Loading