<commit_before>#!/bin/bash

set -x

set -o errexit
set -o pipefail
set -o nounset

HOST_PORT="1081"
CONTAINER_PORT="80"
CONTAINER_NAME=web-local-test
DOCKER_IMAGE=$(awk '{print $1}' .docker_image)

# Wait for container to be ready.
function containercheck {
    set +x
	for i in {10..0};
	do
		# status contains uptime and health in parenthesis, sed to return health
		status="$(docker ps --format "{{.Status}}" --filter "name=$CONTAINER_NAME" | sed  's/.*(\(.*\)).*/\1/')"
		if [[ "$status" == "healthy" ]]
		then
			set -x
			return 0
		fi
		sleep 1
	done
	echo "nginx container did not become ready"
	echo "--- FAIL: ddev-webserver container failure info"
    docker ps -a
    docker logs $CONTAINER_NAME
    docker inspect $CONTAINER_NAME
	return 1
}

function cleanup {
	echo "Removing $CONTAINER_NAME"
	docker rm -f $CONTAINER_NAME 2>/dev/null || true
}
trap cleanup EXIT

cleanup

UNAME=$(uname)

# Using a static composer dir saves the composer downloads for each php version.
composercache=${HOME}/tmp/composercache_${RANDOM}_$$
mkdir -p $composercache && chmod 777 $composercache

export MOUNTUID=$UID
export MOUNTGID=$(id -g)
if [ "$UNAME" = "MINGW64_NT-10.0" ] ; then
	MOUNTUID=1000
	MOUNTGID=1000
fi

for v in 5.6 7.0 7.1 7.2; do
	echo "starting container for tests on php$v"

	docker run -u "$MOUNTUID:$MOUNTGID" -p $HOST_PORT:$CONTAINER_PORT -e "DOCROOT=docroot" -e "DDEV_PHP_VERSION=$v" -d --name $CONTAINER_NAME -v "/$composercache:/home/.composer/cache:rw" -d $DOCKER_IMAGE
	if ! containercheck; then
        exit 101
    fi

	curl --fail localhost:$HOST_PORT/test/phptest.php
	curl -s localhost:$HOST_PORT/test/test-email.php | grep "Test email sent"
	docker exec -t $CONTAINER_NAME php --version | grep "PHP $v"
	docker exec -t $CONTAINER_NAME drush --version
	docker exec -t $CONTAINER_NAME wp --version

	# Make sure composer create-project is working.
	docker exec -t $CONTAINER_NAME composer create-project -d //tmp drupal-composer/drupal-project:8.x-dev my-drupal8-site --stability dev --no-interaction

    # Default settings for assert.active should be 1
    docker exec -t $CONTAINER_NAME php -i | grep "assert.active.*=> 1 => 1"

	echo "testing error states for php$v"
	# These are just the standard nginx 403 and 404 pages
	curl localhost:$HOST_PORT/ | grep "403 Forbidden"<commit_msg>Change to use the a usable user and group in container test (#1289)<commit_after>#!/bin/bash

set -x

set -o errexit
set -o pipefail
set -o nounset

HOST_PORT="1081"
CONTAINER_PORT="80"
CONTAINER_NAME=web-local-test
DOCKER_IMAGE=$(awk '{print $1}' .docker_image)

# Wait for container to be ready.
function containercheck {
    set +x
	for i in {10..0};
	do
		# status contains uptime and health in parenthesis, sed to return health
		status="$(docker ps --format "{{.Status}}" --filter "name=$CONTAINER_NAME" | sed  's/.*(\(.*\)).*/\1/')"
		if [[ "$status" == "healthy" ]]
		then
			set -x
			return 0
		fi
		sleep 1
	done
	echo "nginx container did not become ready"
	echo "--- FAIL: ddev-webserver container failure info"
    docker ps -a
    docker logs $CONTAINER_NAME
    docker inspect $CONTAINER_NAME
	return 1
}

function cleanup {
	echo "Removing $CONTAINER_NAME"
	docker rm -f $CONTAINER_NAME 2>/dev/null || true
}
trap cleanup EXIT

cleanup

UNAME=$(uname)

# Using a static composer dir saves the composer downloads for each php version.
composercache=${HOME}/tmp/composercache_${RANDOM}_$$
mkdir -p $composercache && chmod 777 $composercache

export MOUNTUID=$UID
export MOUNTGID=$(id -g)
if [ "$UNAME" = "MINGW64_NT-10.0" -o "$MOUNTUID" -ge 60000 ] ; then
	MOUNTUID=1000
	MOUNTGID=1000
fi

for v in 5.6 7.0 7.1 7.2; do
	echo "starting container for tests on php$v"

	docker run -u "$MOUNTUID:$MOUNTGID" -p $HOST_PORT:$CONTAINER_PORT -e "DOCROOT=docroot" -e "DDEV_PHP_VERSION=$v" -d --name $CONTAINER_NAME -v "/$composercache:/home/.composer/cache:rw" -d $DOCKER_IMAGE
	if ! containercheck; then
        exit 101
    fi

	curl --fail localhost:$HOST_PORT/test/phptest.php
	curl -s localhost:$HOST_PORT/test/test-email.php | grep "Test email sent"
	docker exec -t $CONTAINER_NAME php --version | grep "PHP $v"
	docker exec -t $CONTAINER_NAME drush --version
	docker exec -t $CONTAINER_NAME wp --version

	# Make sure composer create-project is working.
	docker exec -t $CONTAINER_NAME composer create-project -d //tmp drupal-composer/drupal-project:8.x-dev my-drupal8-site --stability dev --no-interaction

    # Default settings for assert.active should be 1
    docker exec -t $CONTAINER_NAME php -i | grep "assert.active.*=> 1 => 1"

	echo "testing error states for php$v"
	# These are just the standard nginx 403 and 404 pages
	curl localhost:$HOST_PORT/ | grep "403 Forbidden"
{'fraction_non_alphanumeric': 0.12316840093438097, 'fraction_numerical': 0.02569547674665534, 'mean_word_length': 3.7527749747729566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3305974', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1663, 'n_words': 541}