Skip to content

Commit 15982a8

Browse files
committed
Migrate all tests on bionic
2 parents f92d412 + c413ffd commit 15982a8

File tree

11 files changed

+111
-63
lines changed

11 files changed

+111
-63
lines changed

.travis.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
os: linux
1212
dist: bionic
1313
language: php
14+
1415
services:
1516
- memcached
1617
- redis
17-
- couchdb
1818
- mongodb
19+
- docker
1920

2021
php:
2122
- 7.3
@@ -32,23 +33,22 @@ before_install:
3233
# Memcache however seems to be compatible with PHP 7 and 8: https://pecl.php.net/package/memcache
3334
#
3435
- |
35-
echo "\$TRAVIS_PHP_VERSION set to: $TRAVIS_PHP_VERSION";
36+
./bin/ci/scripts/setup_couchdb.sh;
37+
./bin/ci/scripts/setup_mongodb.sh
38+
./bin/ci/scripts/setup_couchbase.sh;
3639
pecl channel-update pecl.php.net;
3740
yes | pecl install -f mongodb-stable;
3841
yes | pecl install -f apcu-stable || true;
42+
yes | pecl install -f memcache;
43+
yes | pecl install -f couchbase-stable;
3944
- |
4045
if [[ $TRAVIS_PHP_VERSION == "8."* || $TRAVIS_PHP_VERSION == "nightly" ]]; then
41-
./bin/ci/scripts/setup_couchbase.sh;
42-
yes | pecl install -f couchbase-stable;
43-
yes | pecl install -f memcache;
4446
phpenv config-add bin/ci/php8_phpfastcache.ini;
4547
else
46-
yes | pecl install -f memcached;
4748
phpenv config-add bin/ci/php7_phpfastcache.ini;
4849
fi
4950
- phpenv config-add bin/ci/php_common.ini;
5051
- phpenv config-rm xdebug.ini
51-
- ./bin/ci/scripts/setup_mongodb.sh
5252

5353
install:
5454
- ./bin/ci/scripts/install_dependencies.sh

bin/ci/php7_phpfastcache.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
extension="memcached.so"
1+

bin/ci/run_tests.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
$phpBinPath = 'php ';
1515
$status = 0;
1616
$dir = __DIR__;
17+
$projectDir = dirname($dir, 2);
1718
$driver = $argv[ 1 ] ?? 'Files';
1819
$phpBinPath = $_SERVER['PHP_BIN_PATH'] ?? 'php';
1920
$failedTests = [];
21+
$skippedTests = [];
2022

2123
/**
2224
* @param string $pattern
@@ -38,18 +40,23 @@
3840
foreach ($globCallback(PFC_TEST_DIR . DIRECTORY_SEPARATOR . '*.test.php') as $filename) {
3941
$climate->backgroundLightYellow()->blue()->out('---');
4042
$command = "{$phpBinPath} -f {$filename} {$driver}";
41-
$climate->out("<yellow>phpfastcache@unit-tests</yellow> <blue>{$dir}</blue> <green>#</green> <red>$command</red>");
43+
$shortCommand = str_replace(dirname(PFC_TEST_DIR), '~', $command);
44+
45+
$climate->out("<yellow>phpfastcache@unit-tests</yellow> <blue>{$projectDir}</blue> <green>#</green> <red>$shortCommand</red>");
4246

4347
\exec($command, $output, $return_var);
4448
$climate->out('=====================================');
4549
$climate->out(\implode("\n", $output));
4650
$climate->out('=====================================');
4751
if ($return_var === 0) {
48-
$climate->green("Process finished with exit code $return_var");
49-
} else {
50-
$climate->red("Process finished with exit code $return_var");
51-
$status = 255;
52+
$climate->green("Test finished successfully");
53+
} else if($return_var === 1){
54+
$climate->red("Test finished with a least one error");
55+
$status = 1;
5256
$failedTests[] = basename($filename);
57+
}else{
58+
$climate->yellow("Test skipped due to unmeet dependencies");
59+
$skippedTests[] = basename($filename);
5360
}
5461

5562
$climate->out('');
@@ -62,11 +69,15 @@
6269
$execTime = gmdate('i\m s\s', (int) round(microtime(true) - $timestamp, 3));
6370
$climate->out('<yellow>Total tests duration: </yellow><light_green>' . $execTime . '</light_green>');
6471

65-
if ($status === 0) {
72+
if (!$failedTests) {
6673
$climate->backgroundGreen()->white()->flank('[OK] The build has passed successfully', '#')->out('');
6774
} else {
6875
$climate->backgroundRed()->white()->flank('[KO] The build has failed miserably', '~')->out('');
69-
$climate->red()->out('Tests failed: ' . implode(', ', $failedTests))->out('');
76+
$climate->red()->out('[TESTS FAILED] ' . PHP_EOL . '- '. implode(PHP_EOL . '- ', $failedTests))->out('');
77+
}
78+
79+
if($skippedTests){
80+
$climate->yellow()->out('[TESTS SKIPPED] ' . PHP_EOL . '- '. implode(PHP_EOL . '- ', $skippedTests))->out('');
7081
}
7182

7283
exit($status);

bin/ci/scripts/setup_couchbase.sh

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
#!/bin/bash
22

3-
# Not possible to run docker container in travis...
4-
# https://docs.travis-ci.com/user/database-setup/#starting-services => Couchbase not yet available
5-
63
set -e
7-
export COUCHBASE_OS_VERSION=$(lsb_release -sr)
8-
9-
if [[ COUCHBASE_OS_VERSION == "16."* ]]; then
10-
export CB_VERSION=6.6.0
11-
export CB_PACKAGE=couchbase-server-community_6.6.0-ubuntu16.04_amd64.deb
12-
else
13-
export CB_VERSION=7.0.0
14-
export CB_PACKAGE=couchbase-server-community_7.0.0-ubuntu18.04_amd64.deb
15-
fi
164

5+
export CB_VERSION=7.0.0
176
export CB_RELEASE_URL=https://packages.couchbase.com/releases
7+
export CB_PACKAGE=couchbase-server-community_7.0.0-ubuntu18.04_amd64.deb
188

199
# Community Edition requires that all nodes provision all services or data service only
2010
export SERVICES="kv,n1ql,index,fts"
@@ -37,21 +27,15 @@ check_db() {
3727
i=1
3828
# Echo with
3929
numbered_echo() {
40-
echo "[$i] $@"
41-
i=`expr $i + 1`
30+
echo "[$i] $*"
31+
i=$(($i+1))
4232
}
4333

4434
echo "# Prepare Couchbase dependencies"
4535
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A3FAA648D9223EDA
4636
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1616981CC4A088B2
47-
if [[ COUCHBASE_OS_VERSION == "16."* ]]; then
48-
echo "deb https://packages.couchbase.com/ubuntu xenial xenial/main" | sudo tee /etc/apt/sources.list.d/couchbase.list
49-
echo "deb https://packages.couchbase.com/clients/c/repos/deb/ubuntu1604 xenial xenial/main" | sudo tee /etc/apt/sources.list.d/couchbase.list
50-
else
51-
echo "deb https://packages.couchbase.com/ubuntu bionic bionic/main" | sudo tee /etc/apt/sources.list.d/couchbase.list
52-
echo "deb https://packages.couchbase.com/clients/c/repos/deb/ubuntu1804 bionic bionic/main" | sudo tee /etc/apt/sources.list.d/couchbase.list
53-
fi
54-
37+
echo "deb https://packages.couchbase.com/ubuntu bionic bionic/main" | sudo tee /etc/apt/sources.list.d/couchbase.list
38+
echo "deb https://packages.couchbase.com/clients/c/repos/deb/ubuntu1804 bionic bionic/main" | sudo tee /etc/apt/sources.list.d/couchbase.list
5539
sudo apt-get update
5640
sudo apt-get install -yq libcouchbase3 libcouchbase-dev build-essential libssl1.0.0 runit wget python-httplib2 chrpath tzdata lsof lshw sysstat net-tools numactl
5741

@@ -67,24 +51,23 @@ done
6751

6852
echo "# Couchbase Server Online"
6953
echo "# Starting setup process"
70-
71-
echo "# Setting up memory"
54+
echo "# 1) Setting up memory"
7255
curl -i "http://127.0.0.1:8091/pools/default" \
7356
-d memoryQuota=${MEMORY_QUOTA} \
7457
-d indexMemoryQuota=${INDEX_MEMORY_QUOTA} \
7558
-d ftsMemoryQuota=${FTS_MEMORY_QUOTA}
7659

77-
echo "# Setting up services"
60+
echo "# 2) Setting up services"
7861
curl -i "http://127.0.0.1:8091/node/controller/setupServices" \
7962
-d services="${SERVICES}"
8063

81-
echo "# Setting up user credentials"
64+
echo "# 3) Setting up user credentials"
8265
curl -i "http://127.0.0.1:8091/settings/web" \
8366
-d port=8091 \
8467
-d username=${USERNAME} \
8568
-d password=${PASSWORD}
8669

87-
echo "# Setting up the bucket"
70+
echo "# 4) Setting up the bucket"
8871
curl -i "http://127.0.0.1:8091/pools/default/buckets" \
8972
-d name=phpfastcache \
9073
-d ramQuotaMB=256 \

bin/ci/scripts/setup_couchdb.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
export COUCHDB_HOST=localhost
6+
export COUCHDB_PORT=5984
7+
export COUCHDB_VERSION=2.3.1
8+
9+
echo "# Running Docker couchdb image"
10+
docker run -d -p $COUCHDB_PORT:$COUCHDB_PORT couchdb:$COUCHDB_VERSION --with-haproxy --with-admin-party-please -n 1
11+
12+
check_db() {
13+
# Allow 4xx errors not to break the connexion check
14+
curl --silent http://$COUCHDB_HOST:$COUCHDB_PORT > /dev/null
15+
echo $?
16+
}
17+
18+
# Echo with
19+
i=1
20+
numbered_echo() {
21+
echo "[$i] $*"
22+
i=$(($i+1))
23+
}
24+
25+
until [[ $(check_db) = 0 ]]; do
26+
>&2 numbered_echo "Waiting for Couchdb Server to be available"
27+
if [[ i -gt 10 ]]; then
28+
echo "Wait time exceeded, aborting".
29+
break;
30+
fi
31+
sleep 1
32+
done
33+
echo "# Couchbdb Server Online"
34+
35+
echo "# Creating Couchdb admin"
36+
curl -s -X PUT -s -o /dev/null -w "HTTP %{response_code}" $COUCHDB_HOST:${COUCHDB_PORT}/_node/_local/_config/admins/admin -d '"travis"'
37+
# curl -X PUT $COUCHDB_HOST:5984/phpfastcache_test_database
38+
39+
printf "\n\n\n"

bin/ci/scripts/setup_mongodb.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/bin/bash
22

3+
echo "# Setting up Mongodb database and user"
34
mongo pfc_test --eval 'db.createUser({user:"travis",pwd:"test",roles:["readWrite"]});'

tests/Mongodb.test.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
->setUsername('travis')
2121
->setPassword('test');
2222

23-
try{
24-
$cacheInstance = CacheManager::getInstance('Mongodb', $config);
25-
}catch(PhpfastcacheDriverCheckException $exception){
26-
$testHelper->exceptionHandler($exception);
27-
$testHelper->terminateTest();
28-
}
29-
23+
$cacheInstance = CacheManager::getInstance('Mongodb', $config);
3024
$testHelper->runCRUDTests($cacheInstance);
3125
$testHelper->terminateTest();

tests/PredisCustomClient.test.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
throw new PhpfastcacheDriverCheckException('Predis library is not installed');
2121
}
2222

23+
$testHelper->mutePhpNotices();
2324
$predisClient = new PredisClient([
2425
'host' => '127.0.0.1',
2526
'port' => 6379,
@@ -29,17 +30,7 @@
2930
$predisClient->connect();
3031

3132
$cacheInstance = CacheManager::getInstance('Predis', (new PredisConfig())->setPredisClient($predisClient));
32-
$cacheKey = 'predisCustomClient';
33-
$cacheItem = $cacheInstance->getItem($cacheKey);
34-
$cacheItem->set(1337);
35-
$cacheInstance->save($cacheItem);
36-
$cacheInstance->detachAllItems();
37-
unset($cacheItem);
38-
if($cacheInstance->getItem($cacheKey)->get() === 1337){
39-
$testHelper->assertPass('Successfully written and read data from outside Predis client');
40-
}else{
41-
$testHelper->assertFail('Error writing or reading data from outside Predis client');
42-
}
33+
$testHelper->runCRUDTests($cacheInstance);
4334
}catch (\RedisException $e){
4435
$testHelper->assertFail('A Predis exception occurred: ' . $e->getMessage());
4536
}

tests/issues/Github-522.test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
chdir(__DIR__);
1212
require_once __DIR__ . '/../../vendor/autoload.php';
1313
$testHelper = new TestHelper('Github issue #522 - Predis returns wrong type hints');
14+
$testHelper->mutePhpNotices();
1415
// Hide php Redis extension notice by using a little @
15-
$cacheInstance = @CacheManager::getInstance('Predis');
16+
$cacheInstance = CacheManager::getInstance('Predis');
1617
$stringObject = new stdClass;
1718
$stringObject->test = '';
1819

tests/issues/Github-627.test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
chdir(__DIR__);
1515
require_once __DIR__ . '/../../vendor/autoload.php';
1616
$testHelper = new TestHelper('Github issue #627 - Redis/Predis "prefix" option');
17+
$testHelper->mutePhpNotices();
1718
$redisInstance = CacheManager::getInstance('Redis', new RedisConfig(['optPrefix' => uniqid('pfc', true) . '_']));
1819
$predisInstance = CacheManager::getInstance('Predis', new PredisConfig(['optPrefix' => uniqid('pfc', true) . '_']));
1920

0 commit comments

Comments
 (0)