3 DATABASENAME=${MYSQL_DATABASE:-test}
4 DATABASEUSER=${MYSQL_USERNAME:-friendica}
5 DATABASEHOST=${MYSQL_HOST:-localhost}
8 export MYSQL_DATABASE="$DATABASENAME"
9 export MYSQL_USERNAME="$DATABASEUSER"
10 export MYSQL_PASSWORD="friendica"
12 if [ -z "$PHP_EXE" ]; then
15 PHP=$(which "$PHP_EXE")
16 # Use the Friendica internal composer
17 COMPOSER="$BASEDIR/bin/composer.phar"
21 _XDEBUG_CONFIG=$XDEBUG_CONFIG
24 if [ -x "$PHP" ]; then
25 echo "Using PHP executable $PHP"
27 echo "Could not find PHP executable $PHP_EXE" >&2
31 echo "Installing depdendencies"
32 $PHP "$COMPOSER" install
34 PHPUNIT="$BASEDIR/vendor/bin/phpunit"
36 if [ -x "$PHPUNIT" ]; then
37 echo "Using PHPUnit executable $PHPUNIT"
39 echo "Could not find PHPUnit executable after composer $PHPUNIT" >&2
43 if ! [ \( -w config -a ! -f config/local.config.php \) -o \( -f config/local.config.php -a -w config/local.config.php \) ]; then
44 echo "Please enable write permissions on config and config/config.php" >&2
48 # Back up existing (dev) config if one exists and backup not already there
49 if [ -f config/local.config.php ] && [ ! -f config/local.config-autotest-backup.php ]; then
50 mv config/local.config.php config/local.config-autotest-backup.php
53 function cleanup_config {
55 if [ -n "$DOCKER_CONTAINER_ID" ]; then
56 echo "Kill the docker $DOCKER_CONTAINER_ID"
57 docker stop "$DOCKER_CONTAINER_ID"
58 docker rm -f "$DOCKER_CONTAINER_ID"
63 # Restore existing config
64 if [ -f config/local.config-autotest-backup.php ]; then
65 mv config/local.config-autotest-backup.php config/local.config.php
69 # restore config on exit
70 trap cleanup_config EXIT
72 function execute_tests {
73 echo "Setup environment for MariaDB testing ..."
77 # backup current config
78 if [ -f config/local.config.php ]; then
79 mv config/local.config.php config/local.config-autotest-backup.php
82 if [ -n "$USEDOCKER" ]; then
83 echo "Fire up the mysql docker"
84 DOCKER_CONTAINER_ID=$(docker run \
85 -e MYSQL_ROOT_PASSWORD=friendica \
86 -e MYSQL_USER="$DATABASEUSER" \
87 -e MYSQL_PASSWORD=friendica \
88 -e MYSQL_DATABASE="$DATABASENAME" \
90 DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID")
92 if [ -z "$DRONE" ]; then # no need to drop the DB when we are on CI
93 if [ "mysql" != "$(mysql --version | grep -o mysql)" ]; then
94 echo "Your mysql binary is not provided by mysql"
95 echo "To use the docker container set the USEDOCKER environment variable"
98 mysql -u "$DATABASEUSER" -pfriendica -e "DROP DATABASE IF EXISTS $DATABASENAME"
99 mysql -u "$DATABASEUSER" -pfriendica -e "CREATE DATABASE $DATABASENAME DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"
105 echo "Waiting for MySQL $DATABASEHOST initialization..."
106 if ! bin/wait-for-connection $DATABASEHOST 3306 300; then
107 echo "[ERROR] Waited 300 seconds, no response" >&2
111 if [ -n "$USEDOCKER" ]; then
112 echo "Initialize database..."
113 docker exec $DOCKER_CONTAINER_ID mysql -u root -pfriendica -e 'CREATE DATABASE IF NOT EXISTS $DATABASENAME;'
116 export MYSQL_HOST="$DATABASEHOST"
119 echo "Installing Friendica..."
120 "$PHP" ./bin/console.php autoinstall --dbuser="$DATABASEUSER" --dbpass=friendica --dbdata="$DATABASENAME" --dbhost="$DATABASEHOST" --url=https://friendica.local --admin=admin@friendica.local
124 rm -fr "coverage-html"
125 mkdir "coverage-html"
126 if [[ "$_XDEBUG_CONFIG" ]]; then
127 export XDEBUG_CONFIG=$_XDEBUG_CONFIG
131 if [ -z "$NOCOVERAGE" ]; then
132 COVER="--coverage-clover autotest-clover.xml --coverage-html coverage-html"
137 INPUT="$BASEDIR/tests"
142 echo "${PHPUNIT[@]}" --configuration tests/phpunit.xml $COVER --log-junit "autotest-results.xml" "$INPUT" "$2"
143 "${PHPUNIT[@]}" --configuration tests/phpunit.xml $COVER --log-junit "autotest-results.xml" "$INPUT" "$2"
146 if [ -n "$DOCKER_CONTAINER_ID" ]; then
147 echo "Kill the docker $DOCKER_CONTAINER_ID"
148 docker stop $DOCKER_CONTAINER_ID
149 docker rm -f $DOCKER_CONTAINER_ID
150 unset $DOCKER_CONTAINER_ID
155 # Start the test execution
157 if [ -n "$1" ] && [ ! -f "tests/$FILENAME" ] && [ "${FILENAME:0:2}" != "--" ]; then
158 execute_tests "$FILENAME" "$2"