Skip to content

Commit d620eaa

Browse files
authored
Merge pull request #826 from Geolim4/master
Migrate all tests on bionic
2 parents c413ffd + 15982a8 commit d620eaa

File tree

11 files changed

+107
-55
lines changed

11 files changed

+107
-55
lines changed

.travis.yml

Lines changed: 7 additions & 16 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
@@ -26,38 +27,28 @@ jobs:
2627
fast_finish: true
2728
allow_failures:
2829
- php: nightly
29-
include:
30-
- dist: trusty
31-
php: 7.3
32-
- dist: trusty
33-
php: 7.4
34-
exclude:
35-
- dist: bionic
36-
php: 7.3
37-
- dist: bionic
38-
php: 7.4
3930

4031
before_install:
4132
# Memcached is not yet available for PHP8 (hasn't been updated since 2019): https://pecl.php.net/package/memcached
4233
# Memcache however seems to be compatible with PHP 7 and 8: https://pecl.php.net/package/memcache
4334
#
4435
- |
45-
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;
4639
pecl channel-update pecl.php.net;
4740
yes | pecl install -f mongodb-stable;
4841
yes | pecl install -f apcu-stable || true;
42+
yes | pecl install -f memcache;
43+
yes | pecl install -f couchbase-stable;
4944
- |
5045
if [[ $TRAVIS_PHP_VERSION == "8."* || $TRAVIS_PHP_VERSION == "nightly" ]]; then
51-
./bin/ci/scripts/setup_couchbase.sh;
52-
yes | pecl install -f couchbase-stable;
53-
yes | pecl install -f memcache;
5446
phpenv config-add bin/ci/php8_phpfastcache.ini;
5547
else
5648
phpenv config-add bin/ci/php7_phpfastcache.ini;
5749
fi
5850
- phpenv config-add bin/ci/php_common.ini;
5951
- phpenv config-rm xdebug.ini
60-
- ./bin/ci/scripts/setup_mongodb.sh
6152

6253
install:
6354
- ./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: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
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
74

85
export CB_VERSION=7.0.0
@@ -30,8 +27,8 @@ check_db() {
3027
i=1
3128
# Echo with
3229
numbered_echo() {
33-
echo "[$i] $@"
34-
i=`expr $i + 1`
30+
echo "[$i] $*"
31+
i=$(($i+1))
3532
}
3633

3734
echo "# Prepare Couchbase dependencies"
@@ -54,24 +51,23 @@ done
5451

5552
echo "# Couchbase Server Online"
5653
echo "# Starting setup process"
57-
58-
echo "# Setting up memory"
54+
echo "# 1) Setting up memory"
5955
curl -i "http://127.0.0.1:8091/pools/default" \
6056
-d memoryQuota=${MEMORY_QUOTA} \
6157
-d indexMemoryQuota=${INDEX_MEMORY_QUOTA} \
6258
-d ftsMemoryQuota=${FTS_MEMORY_QUOTA}
6359

64-
echo "# Setting up services"
60+
echo "# 2) Setting up services"
6561
curl -i "http://127.0.0.1:8091/node/controller/setupServices" \
6662
-d services="${SERVICES}"
6763

68-
echo "# Setting up user credentials"
64+
echo "# 3) Setting up user credentials"
6965
curl -i "http://127.0.0.1:8091/settings/web" \
7066
-d port=8091 \
7167
-d username=${USERNAME} \
7268
-d password=${PASSWORD}
7369

74-
echo "# Setting up the bucket"
70+
echo "# 4) Setting up the bucket"
7571
curl -i "http://127.0.0.1:8091/pools/default/buckets" \
7672
-d name=phpfastcache \
7773
-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)