--- /dev/null
+kind: pipeline
+name: mysql-php7.1
+
+steps:
+- name: mysql-php7.1
+ image: friendicaci/php7.1:php7.1
+ commands:
+ - NOCOVERAGE=true ./autotest.sh
+ environment:
+ MYSQL_USERNAME: friendica
+ MYSQL_PASSWORD: friendica
+ MYSQL_DATABASE: friendica
+ MYSQL_HOST: mysql
+
+services:
+- name: mysql
+ image: mysql:8.0
+ command: [ "--default-authentication-plugin=mysql_native_password" ]
+ environment:
+ MYSQL_ROOT_PASSWORD: friendica
+ MYSQL_USER: friendica
+ MYSQL_PASSWORD: friendica
+ MYSQL_DATABASE: friendica
+ tmpfs:
+ - /var/lib/mysql
+
+#trigger:
+# branch:
+# - master
+# - develop
+# - "*-rc"
+# event:
+# - pull_request
+# - push
- phpenv config-add .travis/redis.ini
- phpenv config-add .travis/memcached.ini
+script: vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover clover.xml
+
after_success: bash <(curl -s https://codecov.io/bash)
--- /dev/null
+#!/usr/bin/env bash
+
+DATABASENAME=${MYSQL_DATABASE:-test}
+DATABASEUSER=${MYSQL_USERNAME:-friendica}
+DATABASEHOST=${MYSQL_HOST:-localhost}
+BASEDIR=$PWD
+
+export MYSQL_DATABASE="$DATABASENAME"
+export MYSQL_USERNAME="$DATABASEUSER"
+export MYSQL_PASSWORD="friendica"
+
+if [ -z "$PHP_EXE" ]; then
+ PHP_EXE=php
+fi
+PHP=$(which "$PHP_EXE")
+# Use the Friendica internal composer
+COMPOSER="$BASEDIR/bin/composer.phar"
+
+set -e
+
+_XDEBUG_CONFIG=$XDEBUG_CONFIG
+unset XDEBUG_CONFIG
+
+if [ -x "$PHP" ]; then
+ echo "Using PHP executable $PHP"
+else
+ echo "Could not find PHP executable $PHP_EXE" >&2
+ exit 3
+fi
+
+echo "Installing depdendencies"
+$PHP "$COMPOSER" install
+
+PHPUNIT="$BASEDIR/vendor/bin/phpunit"
+
+if [ -x "$PHPUNIT" ]; then
+ echo "Using PHPUnit executable $PHPUNIT"
+else
+ echo "Could not find PHPUnit executable after composer $PHPUNIT" >&2
+ exit 3
+fi
+
+if ! [ \( -w config -a ! -f config/local.config.php \) -o \( -f config/local.config.php -a -w config/local.config.php \) ]; then
+ echo "Please enable write permissions on config and config/config.php" >&2
+ exit 1
+fi
+
+# Back up existing (dev) config if one exists and backup not already there
+if [ -f config/local.config.php ] && [ ! -f config/local.config-autotest-backup.php ]; then
+ mv config/local.config.php config/local.config-autotest-backup.php
+fi
+
+function cleanup_config {
+
+ if [ -n "$DOCKER_CONTAINER_ID" ]; then
+ echo "Kill the docker $DOCKER_CONTAINER_ID"
+ docker stop "$DOCKER_CONTAINER_ID"
+ docker rm -f "$DOCKER_CONTAINER_ID"
+ fi
+
+ cd "$BASEDIR"
+
+ # Restore existing config
+ if [ -f config/local.config-autotest-backup.php ]; then
+ mv config/local.config-autotest-backup.php config/local.config.php
+ fi
+}
+
+# restore config on exit
+trap cleanup_config EXIT
+
+function execute_tests {
+ echo "Setup environment for MariaDB testing ..."
+ # back to root folder
+ cd "$BASEDIR"
+
+ # backup current config
+ if [ -f config/local.config.php ]; then
+ mv config/local.config.php config/local.config-autotest-backup.php
+ fi
+
+ if [ -n "$USEDOCKER" ]; then
+ echo "Fire up the mysql docker"
+ DOCKER_CONTAINER_ID=$(docker run \
+ -e MYSQL_ROOT_PASSWORD=friendica \
+ -e MYSQL_USER="$DATABASEUSER" \
+ -e MYSQL_PASSWORD=friendica \
+ -e MYSQL_DATABASE="$DATABASENAME" \
+ -d mysql)
+ DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID")
+ else
+ if [ -z "$DRONE" ]; then # no need to drop the DB when we are on CI
+ if [ "mysql" != "$(mysql --version | grep -o mysql)" ]; then
+ echo "Your mysql binary is not provided by mysql"
+ echo "To use the docker container set the USEDOCKER environment variable"
+ exit 3
+ fi
+ mysql -u "$DATABASEUSER" -pfriendica -e "DROP DATABASE IF EXISTS $DATABASENAME"
+ mysql -u "$DATABASEUSER" -pfriendica -e "CREATE DATABASE $DATABASENAME DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"
+ else
+ DATABASEHOST=mysql
+ fi
+ fi
+
+ echo "Waiting for MySQL $DATABASEHOST initialization..."
+ if ! bin/wait-for-connection $DATABASEHOST 3306 300; then
+ echo "[ERROR] Waited 300 seconds, no response" >&2
+ exit 1
+ fi
+
+ if [ -n "$USEDOCKER" ]; then
+ echo "Initialize database..."
+ docker exec $DOCKER_CONTAINER_ID mysql -u root -pfriendica -e 'CREATE DATABASE IF NOT EXISTS $DATABASENAME;'
+ fi
+
+ export MYSQL_HOST="$DATABASEHOST"
+
+ #call installer
+ echo "Installing Friendica..."
+ "$PHP" ./bin/console.php autoinstall --dbuser="$DATABASEUSER" --dbpass=friendica --dbdata="$DATABASENAME" --dbhost="$DATABASEHOST" --url=https://friendica.local --admin=admin@friendica.local
+
+ #test execution
+ echo "Testing..."
+ rm -fr "coverage-html"
+ mkdir "coverage-html"
+ if [[ "$_XDEBUG_CONFIG" ]]; then
+ export XDEBUG_CONFIG=$_XDEBUG_CONFIG
+ fi
+
+ COVER=''
+ if [ -z "$NOCOVERAGE" ]; then
+ COVER="--coverage-clover autotest-clover.xml --coverage-html coverage-html"
+ else
+ echo "No coverage"
+ fi
+
+ INPUT="$BASEDIR/tests"
+ if [ -n "$1" ]; then
+ INPUT="$INPUT/$1"
+ fi
+
+ echo "${PHPUNIT[@]}" --configuration tests/phpunit.xml $COVER --log-junit "autotest-results.xml" "$INPUT" "$2"
+ "${PHPUNIT[@]}" --configuration tests/phpunit.xml $COVER --log-junit "autotest-results.xml" "$INPUT" "$2"
+ RESULT=$?
+
+ if [ -n "$DOCKER_CONTAINER_ID" ]; then
+ echo "Kill the docker $DOCKER_CONTAINER_ID"
+ docker stop $DOCKER_CONTAINER_ID
+ docker rm -f $DOCKER_CONTAINER_ID
+ unset $DOCKER_CONTAINER_ID
+ fi
+}
+
+#
+# Start the test execution
+#
+if [ -n "$1" ] && [ ! -f "tests/$FILENAME" ] && [ "${FILENAME:0:2}" != "--" ]; then
+ execute_tests "$FILENAME" "$2"
+else
+ execute_tests
+fi
--- /dev/null
+#!/usr/bin/php
+
+<?php
+$timeout = 60;
+switch ($argc) {
+ case 4:
+ $timeout = (float)$argv[3];
+ case 3:
+ $host = $argv[1];
+ $port = (int)$argv[2];
+ break;
+ default:
+ fwrite(STDERR, 'Usage: '.$argv[0].' host port [timeout]'."\n");
+ exit(2);
+}
+if ($timeout < 0) {
+ fwrite(STDERR, 'Timeout must be greater than zero'."\n");
+ exit(2);
+}
+if ($port < 1) {
+ fwrite(STDERR, 'Port must be an integer greater than zero'."\n");
+ exit(2);
+}
+$socketTimeout = (float)ini_get('default_socket_timeout');
+if ($socketTimeout > $timeout) {
+ $socketTimeout = $timeout;
+}
+$stopTime = time() + $timeout;
+do {
+ $sock = @fsockopen($host, $port, $errno, $errstr, $socketTimeout);
+ if ($sock !== false) {
+ fclose($sock);
+ fwrite(STDOUT, "\n");
+ exit(0);
+ }
+ sleep(1);
+ fwrite(STDOUT, '.');
+} while (time() < $stopTime);
+fwrite(STDOUT, "\n");
+exit(1);
\ No newline at end of file
use Friendica\Util\Strings;
use Friendica\Util\XML;
-require_once 'mod/share.php';
-require_once 'mod/item.php';
-require_once 'mod/wall_upload.php';
+require_once __DIR__ . '/../mod/share.php';
+require_once __DIR__ . '/../mod/item.php';
+require_once __DIR__ . '/../mod/wall_upload.php';
define('API_METHOD_ANY', '*');
define('API_METHOD_GET', 'GET');
/**
* @file mod/api.php
*/
+
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Database\DBA;
use Friendica\Module\Login;
-require_once 'include/api.php';
+require_once __DIR__ . '/../include/api.php';
function oauth_get_client(OAuthRequest $request)
{
use Friendica\Util\Strings;
use Friendica\Worker\Delivery;
-require_once 'include/items.php';
+require_once __DIR__ . '/../include/items.php';
function item_post(App $a) {
if (!local_user() && !remote_user()) {
+++ /dev/null
-<?xml version="1.0"?>
-<phpunit
- bootstrap="tests/bootstrap.php"
- verbose="true">
- <testsuites>
- <testsuite>
- <directory>tests/</directory>
- </testsuite>
- </testsuites>
- <!-- Filters for Code Coverage -->
- <filter>
- <whitelist>
- <directory suffix=".php">.</directory>
- <exclude>
- <directory suffix=".php">config/</directory>
- <directory suffix=".php">doc/</directory>
- <directory suffix=".php">images/</directory>
- <directory suffix=".php">library/</directory>
- <directory suffix=".php">spec/</directory>
- <directory suffix=".php">tests/</directory>
- <directory suffix=".php">view/</directory>
- </exclude>
- </whitelist>
- </filter>
- <logging>
- <log type="coverage-clover" target="clover.xml" />
- </logging>
- <listeners>
- <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
- </listeners>
-</phpunit>
$memcache_host = $config->get('system', 'memcache_host');
$memcache_port = $config->get('system', 'memcache_port');
- if (!$this->memcache->connect($memcache_host, $memcache_port)) {
+ if (!@$this->memcache->connect($memcache_host, $memcache_port)) {
throw new Exception('Expected Memcache server at ' . $memcache_host . ':' . $memcache_port . ' isn\'t available');
}
}
$redis_pw = $config->get('system', 'redis_password');
$redis_db = $config->get('system', 'redis_db', 0);
- if (isset($redis_port) && !$this->redis->connect($redis_host, $redis_port)) {
+ if (isset($redis_port) && !@$this->redis->connect($redis_host, $redis_port)) {
throw new Exception('Expected Redis server at ' . $redis_host . ':' . $redis_port . ' isn\'t available');
- } elseif (!$this->redis->connect($redis_host)) {
+ } elseif (!@$this->redis->connect($redis_host)) {
throw new Exception('Expected Redis server at ' . $redis_host . ' isn\'t available');
}
use Friendica\Core\Logger;
use Friendica\Util\DateTimeFormat;
-require_once 'include/dba.php';
+require_once __DIR__ . '/../../include/dba.php';
/**
* @brief This class contain functions for the database management
{
// Use environment variables for mysql if they are set beforehand
if (!empty($server['MYSQL_HOST'])
- && !empty($server['MYSQL_USERNAME'] || !empty($server['MYSQL_USER']))
+ && (!empty($server['MYSQL_USERNAME'] || !empty($server['MYSQL_USER'])))
&& $server['MYSQL_PASSWORD'] !== false
&& !empty($server['MYSQL_DATABASE']))
{
{
// Use environment variables for mysql if they are set beforehand
if (!empty($server['MYSQL_HOST'])
- && !empty($server['MYSQL_USERNAME'] || !empty($server['MYSQL_USER']))
+ && (!empty($server['MYSQL_USERNAME'] || !empty($server['MYSQL_USER'])))
&& $server['MYSQL_PASSWORD'] !== false
&& !empty($server['MYSQL_DATABASE']))
{
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<phpunit
+ bootstrap="bootstrap.php"
+ verbose="true">
+ <testsuite name='friendica'>
+ <directory suffix='.php'>functional/</directory>
+ <directory suffix='.php'>include/</directory>
+ <directory suffix='.php'>src/</directory>
+ <directory suffix='.php'>./</directory>
+ </testsuite>
+ <!-- Filters for Code Coverage -->
+ <filter>
+ <whitelist>
+ <directory suffix=".php">..</directory>
+ <exclude>
+ <directory suffix=".php">config/</directory>
+ <directory suffix=".php">doc/</directory>
+ <directory suffix=".php">images/</directory>
+ <directory suffix=".php">library/</directory>
+ <directory suffix=".php">spec/</directory>
+ <directory suffix=".php">tests/</directory>
+ <directory suffix=".php">view/</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+ <listeners>
+ <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
+ </listeners>
+</phpunit>
{
$configMock = \Mockery::mock(Configuration::class);
+ $host = $_SERVER['MEMCACHE_HOST'] ?? 'localhost';
+
$configMock
->shouldReceive('get')
->with('system', 'memcache_host')
- ->andReturn('localhost');
+ ->andReturn($host);
$configMock
->shouldReceive('get')
->with('system', 'memcache_port')
->andReturn(11211);
- $this->cache = new MemcacheCache('localhost', $configMock);
+ try {
+ $this->cache = new MemcacheCache($host, $configMock);
+ } catch (\Exception $e) {
+ $this->markTestSkipped('Memcache is not available');
+ }
return $this->cache;
}
{
$configMock = \Mockery::mock(Configuration::class);
+ $host = $_SERVER['MEMCACHED_HOST'] ?? 'localhost';
+
$configMock
->shouldReceive('get')
->with('system', 'memcached_hosts')
- ->andReturn([0 => 'localhost, 11211']);
+ ->andReturn([0 => $host . ', 11211']);
$logger = new NullLogger();
- $this->cache = new MemcachedCache('localhost', $configMock, $logger);
+ try {
+ $this->cache = new MemcachedCache($host, $configMock, $logger);
+ } catch (\Exception $exception) {
+ $this->markTestSkipped('Memcached is not available');
+ }
return $this->cache;
}
{
$configMock = \Mockery::mock(Configuration::class);
+ $host = $_SERVER['REDIS_HOST'] ?? 'localhost';
+
$configMock
->shouldReceive('get')
->with('system', 'redis_host')
- ->andReturn('localhost');
+ ->andReturn($host);
$configMock
->shouldReceive('get')
->with('system', 'redis_port')
->with('system', 'redis_password')
->andReturn(null);
- $this->cache = new RedisCache('localhost', $configMock);
+ try {
+ $this->cache = new RedisCache($host, $configMock);
+ } catch (\Exception $e) {
+ $this->markTestSkipped('Redis is not available.');
+ }
return $this->cache;
}
{
$configMock = \Mockery::mock(Configuration::class);
+ $host = $_SERVER['MEMCACHE_HOST'] ?? 'localhost';
+
$configMock
->shouldReceive('get')
->with('system', 'memcache_host')
- ->andReturn('localhost');
+ ->andReturn($host);
$configMock
->shouldReceive('get')
->with('system', 'memcache_port')
->andReturn(11211);
- return new CacheLock(new MemcacheCache('localhost', $configMock));
+ $lock = null;
+
+ try {
+ $cache = new MemcacheCache($host, $configMock);
+ $lock = new CacheLock($cache);
+ } catch (\Exception $e) {
+ $this->markTestSkipped('Memcache is not available');
+ }
+
+ return $lock;
}
}
{
$configMock = \Mockery::mock(Configuration::class);
+ $host = $_SERVER['MEMCACHED_HOST'] ?? 'localhost';
+
$configMock
->shouldReceive('get')
->with('system', 'memcached_hosts')
- ->andReturn([0 => 'localhost, 11211']);
+ ->andReturn([0 => $host . ', 11211']);
$logger = new NullLogger();
- return new CacheLock(new MemcachedCache('localhost', $configMock, $logger));
+ $lock = null;
+
+ try {
+ $cache = new MemcachedCache($host, $configMock, $logger);
+ $lock = new CacheLock($cache);
+ } catch (\Exception $e) {
+ $this->markTestSkipped('Memcached is not available');
+ }
+
+ return $lock;
}
}
{
$configMock = \Mockery::mock(Configuration::class);
+ $host = $_SERVER['REDIS_HOST'] ?? 'localhost';
+
$configMock
->shouldReceive('get')
->with('system', 'redis_host')
- ->andReturn('localhost');
+ ->andReturn($host);
$configMock
->shouldReceive('get')
->with('system', 'redis_port')
->with('system', 'redis_password')
->andReturn(null);
- return new CacheLock(new RedisCache('localhost', $configMock));
+ $lock = null;
+
+ try {
+ $cache = new RedisCache($host, $configMock);
+ $lock = new CacheLock($cache);
+ } catch (\Exception $e) {
+ $this->markTestSkipped('Redis is not available');
+ }
+
+ return $lock;
}
}