Skip to content

Commit 6b59f32

Browse files
committed
Improved travis tests efficiency
1 parent e64925f commit 6b59f32

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
language: php
1313
services:
1414
- memcached
15+
# - redis-server
1516
before_script: phpenv config-add var/php/conf/phpfastcache.ini
1617
php:
1718
# - 5.3
@@ -27,3 +28,4 @@ script:
2728
- php -f tests/SyntaxChecker.test.php
2829
- php -f tests/Autoload.test.php
2930
- php -f tests/NewCacheInstance.test.php
31+
- php -f tests/Psr6InterfaceImplements.test.php

src/phpFastCache/CacheManager.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,21 @@ class CacheManager
7878
*/
7979
public static function getInstance($driver = 'auto', $config = [])
8080
{
81+
static $badPracticeOmeter = [];
82+
8183
$driver = ucfirst(strtolower($driver));
8284
$config = array_merge(self::$config, $config);
83-
if ($driver === 'Auto') {
85+
if (!$driver || $driver === 'Auto') {
8486
$driver = self::getAutoClass($config);
8587
}
8688

8789
$instance = crc32($driver . serialize($config));
8890
if (!isset(self::$instances[ $instance ])) {
91+
$badPracticeOmeter[$driver] = 1;
8992
$class = self::getNamespacePath() . $driver . '\Driver';
9093
self::$instances[ $instance ] = new $class($config);
91-
} else {
92-
trigger_error('[' . $driver . '] Calling CacheManager::getInstance for already instanced drivers is a bad practice and have a significant impact on performances.
94+
} else if(++$badPracticeOmeter[$driver] >= 5){
95+
trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances.
9396
See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F');
9497
}
9598

@@ -99,9 +102,9 @@ public static function getInstance($driver = 'auto', $config = [])
99102
/**
100103
* @param $config
101104
* @return string
102-
* @throws \Exception
105+
* @throws phpFastCacheDriverCheckException
103106
*/
104-
public static function getAutoClass($config)
107+
public static function getAutoClass($config = [])
105108
{
106109
static $autoDriver;
107110

src/phpFastCache/Drivers/Sqlite/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function getSqliteDir()
9797
*/
9898
public function driverCheck()
9999
{
100-
return extension_loaded('pdo_sqlite') || @mkdir($this->getFilesDir(), $this->setChmodAuto(), true);
100+
return extension_loaded('pdo_sqlite') && @mkdir($this->getSqliteDir(), $this->setChmodAuto(), true);
101101
}
102102

103103
/**

src/phpFastCache/Drivers/Ssdb/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected function driverConnect()
160160
return true;
161161
}
162162
}catch(SSDBException $e){
163-
throw new phpFastCacheDriverException('Ssdb failed to connect with error: '. $e->getMessage(), 0 , $e);
163+
throw new phpFastCacheDriverCheckException('Ssdb failed to connect with error: '. $e->getMessage(), 0 , $e);
164164
}
165165
}
166166

tests/Autoload.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
if (!class_exists('phpFastCache\CacheManager')) {
1616
echo "[FAIL] Autoload failed to find the CacheManager\n";
17-
$status = 1;
17+
$status = 255;
1818
}
1919
echo "[PASS] Autoload successfully found the CacheManager\n";
2020

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* @author Khoa Bui (khoaofgod) <[email protected]> http://www.phpfastcache.com
5+
* @author Georges.L (Geolim4) <[email protected]>
6+
*/
7+
8+
use phpFastCache\CacheManager;
9+
use Psr\Cache\CacheItemPoolInterface;
10+
11+
12+
chdir(__DIR__);
13+
require_once __DIR__ . '/../vendor/autoload.php';
14+
15+
$status = 0;
16+
echo "Testing new cache instance\n";
17+
18+
/**
19+
* Testing memcached as it is declared in .travis.yml
20+
*/
21+
$driverInstance = CacheManager::getInstance();
22+
23+
if (!is_object($driverInstance)) {
24+
echo '[FAIL] CacheManager::getInstance() returned an invalid variable type:' . gettype($driverInstance) . "\n";
25+
$status = 1;
26+
}else if(!($driverInstance instanceof CacheItemPoolInterface)){
27+
echo '[FAIL] CacheManager::getInstance() returned an invalid class:' . get_class($driverInstance) . "\n";
28+
$status = 1;
29+
}else{
30+
echo '[PASS] CacheManager::getInstance() returned a valid CacheItemPoolInterface object: ' . get_class($driverInstance) . "\n";
31+
}
32+
33+
exit($status);

tests/SyntaxChecker.test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function read_dir($dir, $ext = null)
2929
return $list;
3030
}
3131

32-
$list = read_dir('.', 'php');
33-
$list += read_dir('.', 'tpl');
32+
$list = read_dir(__DIR__ . '/../', 'php');
33+
$list += read_dir(__DIR__ . '/../', 'tpl');
3434

3535
$exit = 0;
3636
foreach ($list as $file) {

0 commit comments

Comments
 (0)