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 [ -z "$NOINSTALL" ]; then
83 if [ -n "$USEDOCKER" ]; then
84 echo "Fire up the mysql docker"
85 DOCKER_CONTAINER_ID=$(docker run \
86 -e MYSQL_ROOT_PASSWORD=friendica \
87 -e MYSQL_USER="$DATABASEUSER" \
88 -e MYSQL_PASSWORD=friendica \
89 -e MYSQL_DATABASE="$DATABASENAME" \
91 DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID")
93 if [ -z "$DRONE" ]; then # no need to drop the DB when we are on CI
94 if [ "mysql" != "$(mysql --version | grep -o mysql)" ]; then
95 echo "Your mysql binary is not provided by mysql"
96 echo "To use the docker container set the USEDOCKER environment variable"
99 mysql -u "$DATABASEUSER" -pfriendica -e "DROP DATABASE IF EXISTS $DATABASENAME"
100 mysql -u "$DATABASEUSER" -pfriendica -e "CREATE DATABASE $DATABASENAME DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"
106 echo "Waiting for MySQL $DATABASEHOST initialization..."
107 if ! bin/wait-for-connection $DATABASEHOST 3306 300; then
108 echo "[ERROR] Waited 300 seconds, no response" >&2
112 if [ -n "$USEDOCKER" ]; then
113 echo "Initialize database..."
114 docker exec $DOCKER_CONTAINER_ID mysql -u root -pfriendica -e 'CREATE DATABASE IF NOT EXISTS $DATABASENAME;'
117 export MYSQL_HOST="$DATABASEHOST"
120 echo "Installing Friendica..."
121 "$PHP" ./bin/console.php autoinstall --dbuser="$DATABASEUSER" --dbpass=friendica --dbdata="$DATABASENAME" --dbhost="$DATABASEHOST" --url=https://friendica.local --admin=admin@friendica.local
126 rm -fr "coverage-html"
127 mkdir "coverage-html"
128 if [[ "$_XDEBUG_CONFIG" ]]; then
129 export XDEBUG_CONFIG=$_XDEBUG_CONFIG
133 if [ -z "$NOCOVERAGE" ]; then
134 COVER="--coverage-clover=tests/autotest-clover.xml --coverage-html=tests/coverage-html"
139 # per default, there is no cache installed
140 GROUP='--exclude-group=REDIS,MEMCACHE,MEMCACHED,APCU'
141 if [ "$TEST_SELECTION" == "REDIS" ]; then
142 GROUP="--group=REDIS"
144 if [ "$TEST_SELECTION" == "MEMCACHE" ]; then
145 GROUP="--group=MEMCACHE"
147 if [ "$TEST_SELECTION" == "MEMCACHED" ]; then
148 GROUP="--group=MEMCACHED"
150 if [ "$TEST_SELECTION" == "APCU" ]; then
153 if [ "$TEST_SELECTION" == "NODB" ]; then
154 GROUP="--exclude-group=DB,SLOWDB"
157 INPUT="$BASEDIR/tests"
162 echo "${PHPUNIT[@]}" --configuration tests/phpunit.xml "$GROUP" "$COVER" --log-junit "autotest-results.xml" "$INPUT" "$2"
163 "${PHPUNIT[@]}" --configuration tests/phpunit.xml "$GROUP" "$COVER" --log-junit "autotest-results.xml" "$INPUT" "$2"
166 if [ -n "$DOCKER_CONTAINER_ID" ]; then
167 echo "Kill the docker $DOCKER_CONTAINER_ID"
168 docker stop $DOCKER_CONTAINER_ID
169 docker rm -f $DOCKER_CONTAINER_ID
170 unset $DOCKER_CONTAINER_ID
175 # Start the test execution
177 if [ -n "$1" ] && [ ! -f "tests/$FILENAME" ] && [ "${FILENAME:0:2}" != "--" ]; then
178 execute_tests "$FILENAME" "$2"