Skip to content

Commit 2bed296

Browse files
authored
Upgraded travis dist to repair broken php8 tests + refactored some tests (#809)
* Upgraded travis dist to repair broken php8 tests * Trying to repair broken build * Trying to repair broken build * Trying to repair broken build * Fixed Couchdb tests & driver * Removed dump... * Fixed tests for php 7.x ... * Fixed tests & dropped support of Riak which is became unmaintenable and is globally unused * Refactored some tests and isolated TestHelper out of core code
1 parent 170400c commit 2bed296

File tree

58 files changed

+601
-553
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+601
-553
lines changed

bin/ci/run_tests.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
$dir = __DIR__;
1717
$driver = $argv[ 1 ] ?? 'Files';
1818
$phpBinPath = $_SERVER['PHP_BIN_PATH'] ?? 'php';
19+
$failedTests = [];
1920

2021
/**
2122
* @param string $pattern
@@ -37,7 +38,7 @@
3738
foreach ($globCallback(PFC_TEST_DIR . DIRECTORY_SEPARATOR . '*.test.php') as $filename) {
3839
$climate->backgroundLightYellow()->blue()->out('---');
3940
$command = "{$phpBinPath} -f {$filename} {$driver}";
40-
$climate->out("<yellow>phpfastcache@unit-test</yellow> <blue>{$dir}</blue> <green>#</green> <red>$command</red>");
41+
$climate->out("<yellow>phpfastcache@unit-tests</yellow> <blue>{$dir}</blue> <green>#</green> <red>$command</red>");
4142

4243
\exec($command, $output, $return_var);
4344
$climate->out('=====================================');
@@ -48,6 +49,7 @@
4849
} else {
4950
$climate->red("Process finished with exit code $return_var");
5051
$status = 255;
52+
$failedTests[] = basename($filename);
5153
}
5254

5355
$climate->out('');
@@ -64,6 +66,7 @@
6466
$climate->backgroundGreen()->white()->flank('[OK] The build has passed successfully', '#')->out('');
6567
} else {
6668
$climate->backgroundRed()->white()->flank('[KO] The build has failed miserably', '~')->out('');
69+
$climate->red()->out('Tests failed: ' . implode(', ', $failedTests))->out('');
6770
}
6871

6972
exit($status);

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
"psr/cache": "~1.0.0",
2626
"psr/simple-cache": "~1.0.0",
2727
"ext-mbstring": "*",
28-
"ext-json": "*"
28+
"ext-json": "*",
29+
"phpfastcache/couchdb": "^1.0"
2930
},
3031
"require-dev": {
31-
"league/climate": "^3.5"
32+
"league/climate": "^3.5",
33+
"ext-gettext": "*"
3234
},
3335
"suggest": {
3436
"ext-apc": "*",
@@ -51,7 +53,8 @@
5153
},
5254
"autoload": {
5355
"psr-4": {
54-
"Phpfastcache\\": "lib/Phpfastcache/"
56+
"Phpfastcache\\": "lib/Phpfastcache/",
57+
"Phpfastcache\\Tests\\": "tests/lib/"
5558
}
5659
}
5760
}

composer.lock

Lines changed: 61 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Phpfastcache/Autoload/Autoload.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
const PFC_PHP_EXT = 'php';
2222
const PFC_BIN_DIR = __DIR__ . '/../../../bin/';
2323
const PFC_LIB_DIR = __DIR__ . '/../../../lib/';
24+
const PFC_TESTS_DIR = __DIR__ . '/../../../tests/lib/';
25+
const PFC_TESTS_NS = 'Phpfastcache\\Tests\\';
26+
2427

2528
\trigger_error('The legacy autoload will be removed in the next major release. Please include Phpfastcache through composer by running `composer require phpfastcache/phpfastcache`.', \E_USER_DEPRECATED);
2629
/**
@@ -59,9 +62,15 @@ static function ($entity): void {
5962
return;
6063
}
6164

62-
$entity = str_replace('\\', '/', $entity);
63-
$path = PFC_LIB_DIR . $entity . '.' . PFC_PHP_EXT;
65+
$entityPath = str_replace('\\', '/', $entity);
66+
67+
if(\strpos($entity, PFC_TESTS_NS) === 0){
68+
$path = PFC_TESTS_DIR . \str_replace(str_replace('\\', '/', PFC_TESTS_NS), '', $entityPath) . '.' . PFC_PHP_EXT;
69+
}else{
70+
$path = PFC_LIB_DIR . $entityPath . '.' . PFC_PHP_EXT;
71+
}
6472

73+
$path = \realpath($path);
6574
if (\is_readable($path)) {
6675
require_once $path;
6776
}
@@ -73,4 +82,4 @@ static function ($entity): void {
7382
'Your project already makes use of Composer. You SHOULD use the composer dependency "phpfastcache/phpfastcache" instead of hard-autoloading.',
7483
E_USER_WARNING
7584
);
76-
}
85+
}

tests/AbstractProxy.test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
9-
use Phpfastcache\Helper\TestHelper;
9+
use Phpfastcache\Tests\Helper\TestHelper;
1010
use Phpfastcache\Proxy\PhpfastcacheAbstractProxy;
1111

1212

@@ -41,11 +41,11 @@ public function __construct($driver = '', $config = null)
4141
$driverInstance = new CustomMemcachedCacheClass();
4242

4343
if (!is_object($driverInstance->getItem('test'))) {
44-
$testHelper->printFailText('$driverInstance->getItem() returned an invalid var type:' . gettype($driverInstance));
44+
$testHelper->assertFail('$driverInstance->getItem() returned an invalid var type:' . gettype($driverInstance));
4545
}else if(!($driverInstance->getItem('test') instanceof ExtendedCacheItemInterface)){
46-
$testHelper->printFailText('$driverInstance->getItem() returned an invalid class that does not implements ExtendedCacheItemInterface: ' . get_class($driverInstance));
46+
$testHelper->assertFail('$driverInstance->getItem() returned an invalid class that does not implements ExtendedCacheItemInterface: ' . get_class($driverInstance));
4747
}else{
48-
$testHelper->printPassText('$driverInstance->getItem() returned a valid class that implements ExtendedCacheItemInterface: ' . get_class($driverInstance));
48+
$testHelper->assertPass('$driverInstance->getItem() returned a valid class that implements ExtendedCacheItemInterface: ' . get_class($driverInstance));
4949
}
5050

5151
$testHelper->terminateTest();

tests/Apcu.test.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,8 @@
55
* @author Georges.L (Geolim4) <contact@geolim4.com>
66
*/
77

8-
use Phpfastcache\Api;
98
use Phpfastcache\CacheManager;
10-
use Phpfastcache\Cluster\AggregatorInterface;
11-
use Phpfastcache\Cluster\ClusterAggregator;
12-
use Phpfastcache\Cluster\ItemAbstract;
13-
use Phpfastcache\Core\Pool\AggregablePoolInterface;
14-
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
15-
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
16-
use Phpfastcache\Exceptions\PhpfastcacheRootException;
17-
use Phpfastcache\Helper\TestHelper;
18-
use Phpfastcache\Drivers\Fakefiles\Config;
9+
use Phpfastcache\Tests\Helper\TestHelper;
1910

2011

2112
chdir(__DIR__);

tests/Api.test.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Phpfastcache\Api;
99
use Phpfastcache\Exceptions\PhpfastcacheRootException;
10-
use Phpfastcache\Helper\TestHelper;
10+
use Phpfastcache\Tests\Helper\TestHelper;
1111

1212
chdir(__DIR__);
1313
require_once __DIR__ . '/../vendor/autoload.php';
@@ -18,39 +18,39 @@
1818
*/
1919
try {
2020
$version = Api::getVersion();
21-
$testHelper->printPassText(sprintf('Successfully retrieved the API version: %s', $version));
21+
$testHelper->assertPass(sprintf('Successfully retrieved the API version: %s', $version));
2222
} catch (PhpfastcacheRootException $e) {
23-
$testHelper->printFailText(sprintf('Failed to retrieve the API version with the following error error: %s', $e->getMessage()));
23+
$testHelper->assertFail(sprintf('Failed to retrieve the API version with the following error error: %s', $e->getMessage()));
2424
}
2525

2626
/**
2727
* Testing PhpFastCache version
2828
*/
2929
try {
3030
$version = Api::getPhpFastCacheVersion();
31-
$testHelper->printPassText(sprintf('Successfully retrieved PhpFastCache version: %s', $version));
31+
$testHelper->assertPass(sprintf('Successfully retrieved PhpFastCache version: %s', $version));
3232
} catch (PhpfastcacheRootException $e) {
33-
$testHelper->printFailText(sprintf('Failed to retrieve the PhpFastCache version with the following error error: %s', $e->getMessage()));
33+
$testHelper->assertFail(sprintf('Failed to retrieve the PhpFastCache version with the following error error: %s', $e->getMessage()));
3434
}
3535

3636
/**
3737
* Testing API changelog
3838
*/
3939
try {
4040
$changelog = Api::getChangelog();
41-
$testHelper->printPassText(sprintf("Successfully retrieved API changelog:\n%s", $changelog));
41+
$testHelper->assertPass(sprintf("Successfully retrieved API changelog:\n%s", $changelog));
4242
} catch (PhpfastcacheRootException $e) {
43-
$testHelper->printFailText(sprintf('Failed to retrieve the API changelog with the following error error: %s', $e->getMessage()));
43+
$testHelper->assertFail(sprintf('Failed to retrieve the API changelog with the following error error: %s', $e->getMessage()));
4444
}
4545

4646
/**
4747
* Testing PhpFastCache changelog
4848
*/
4949
try {
5050
$changelog = Api::getPhpFastCacheChangelog();
51-
$testHelper->printPassText(sprintf("Successfully retrieved PhpFastCache changelog:\n%s", $changelog));
51+
$testHelper->assertPass(sprintf("Successfully retrieved PhpFastCache changelog:\n%s", $changelog));
5252
} catch (PhpfastcacheRootException $e) {
53-
$testHelper->printFailText(sprintf('Failed to retrieve the PhpFastCache changelog with the following error error: %s', $e->getMessage()));
53+
$testHelper->assertFail(sprintf('Failed to retrieve the PhpFastCache changelog with the following error error: %s', $e->getMessage()));
5454
}
5555

5656
$testHelper->terminateTest();

tests/AttachingDetachingMethods.test.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Phpfastcache\CacheManager;
99
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
10-
use Phpfastcache\Helper\TestHelper;
10+
use Phpfastcache\Tests\Helper\TestHelper;
1111
use Psr\Cache\CacheItemPoolInterface;
1212

1313

@@ -22,9 +22,9 @@
2222
$driverInstance = CacheManager::getInstance($defaultDriver);
2323

2424
if (!is_object($driverInstance)) {
25-
$testHelper->printFailText('CacheManager::getInstance() returned an invalid variable type:' . gettype($driverInstance));
25+
$testHelper->assertFail('CacheManager::getInstance() returned an invalid variable type:' . gettype($driverInstance));
2626
}else if(!($driverInstance instanceof CacheItemPoolInterface)){
27-
$testHelper->printFailText('CacheManager::getInstance() returned an invalid class:' . get_class($driverInstance));
27+
$testHelper->assertFail('CacheManager::getInstance() returned an invalid class:' . get_class($driverInstance));
2828
}else{
2929
$key = 'test_attaching_detaching';
3030

@@ -34,19 +34,19 @@
3434

3535
if($driverInstance->isAttached($itemDetached) !== true)
3636
{
37-
$testHelper->printPassText('ExtendedCacheItemPoolInterface::isAttached() identified $itemDetached as being detached.');
37+
$testHelper->assertPass('ExtendedCacheItemPoolInterface::isAttached() identified $itemDetached as being detached.');
3838
}
3939
else
4040
{
41-
$testHelper->printFailText('ExtendedCacheItemPoolInterface::isAttached() failed to identify $itemDetached as to be detached.');
41+
$testHelper->assertFail('ExtendedCacheItemPoolInterface::isAttached() failed to identify $itemDetached as to be detached.');
4242
}
4343

4444
try{
4545
$driverInstance->attachItem($itemDetached);
46-
$testHelper->printFailText('ExtendedCacheItemPoolInterface::attachItem() attached $itemDetached without trowing an error.');
46+
$testHelper->assertFail('ExtendedCacheItemPoolInterface::attachItem() attached $itemDetached without trowing an error.');
4747
}catch(PhpfastcacheLogicException $e){
48-
$testHelper->printPassText('ExtendedCacheItemPoolInterface::attachItem() failed to attach $itemDetached by trowing a phpfastcacheLogicException exception.');
48+
$testHelper->assertPass('ExtendedCacheItemPoolInterface::attachItem() failed to attach $itemDetached by trowing a phpfastcacheLogicException exception.');
4949
}
5050
}
5151

52-
$testHelper->terminateTest();
52+
$testHelper->terminateTest();

tests/AutoDriver.test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
use Phpfastcache\CacheManager;
99
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
1010
use Phpfastcache\Exceptions\PhpfastcacheRootException;
11-
use Phpfastcache\Helper\TestHelper;
11+
use Phpfastcache\Tests\Helper\TestHelper;
1212

1313
chdir(__DIR__);
1414
require_once __DIR__ . '/../vendor/autoload.php';
1515
$testHelper = new TestHelper('"Auto" driver');
1616

17-
$testHelper->printSkipText('This feature has been removed as of phpfastcache V8');
17+
$testHelper->assertSkip('This feature has been removed as of phpfastcache V8');
1818
/*try{
1919
$driverInstance = CacheManager::getInstance('Auto');
2020
if($driverInstance instanceof ExtendedCacheItemPoolInterface){

tests/Autoload.test.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
use Phpfastcache\CacheManager;
9+
use Phpfastcache\Tests\Helper\TestHelper;
910
use Psr\Cache\CacheItemInterface;
1011

1112
chdir(__DIR__);
@@ -32,4 +33,14 @@
3233
print '[PASS] Autoload successfully found the Psr CacheItemInterface' . PHP_EOL;
3334
}
3435

35-
exit($exitCode);
36+
/**
37+
* Testing Psr autoload
38+
*/
39+
if (!class_exists(TestHelper::class)) {
40+
print '[FAIL] Autoload failed to find the TestHelper' . PHP_EOL;
41+
$exitCode = 255;
42+
} else {
43+
print '[PASS] Autoload successfully found the TestHelper' . PHP_EOL;
44+
}
45+
46+
exit($exitCode);

tests/CacheClearSingleInstance.test.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
99
use Phpfastcache\CacheManager;
1010
use Phpfastcache\Exceptions\PhpfastcacheInstanceNotFoundException;
11-
use Phpfastcache\Helper\TestHelper;
11+
use Phpfastcache\Tests\Helper\TestHelper;
1212

1313
chdir(__DIR__);
1414
require_once __DIR__ . '/../vendor/autoload.php';
@@ -28,17 +28,17 @@
2828

2929
$cacheInstances = CacheManager::getInstances();
3030
if(\count($cacheInstances) === 3){
31-
$testHelper->printPassText('A single cache instance have been cleared');
31+
$testHelper->assertPass('A single cache instance have been cleared');
3232
}else{
33-
$testHelper->printFailText('A single cache instance have NOT been cleared');
33+
$testHelper->assertFail('A single cache instance have NOT been cleared');
3434
}
3535

3636
$driverInstance2Hash = spl_object_hash($driverInstance2);
3737
foreach ($cacheInstances as $cacheInstance) {
3838
$driverInstanceHash = spl_object_hash($cacheInstance);
3939
if($driverInstanceHash !== $driverInstance2Hash){
40-
$testHelper->printPassText("Compared cache instance #{$driverInstanceHash} does not match with previously cleared cache instance #" . $driverInstance2Hash);
40+
$testHelper->assertPass("Compared cache instance #{$driverInstanceHash} does not match with previously cleared cache instance #" . $driverInstance2Hash);
4141
}else{
42-
$testHelper->printFailText("Compared cache instance #{$driverInstanceHash} unfortunately match with previously cleared cache instance #" . $driverInstance2Hash);
42+
$testHelper->assertFail("Compared cache instance #{$driverInstanceHash} unfortunately match with previously cleared cache instance #" . $driverInstance2Hash);
4343
}
44-
}
44+
}

0 commit comments

Comments
 (0)