Skip to content

Commit 800ae53

Browse files
authored
Merge pull request #777 from Geolim4/master
Ensured full PHP8 compatibility
2 parents 5b47240 + 6d8cea9 commit 800ae53

File tree

7 files changed

+48
-18
lines changed

7 files changed

+48
-18
lines changed

.github/workflows/tests.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,18 @@ jobs:
3737
extensions: mbstring, intl, pdo_sqlite, json
3838
ini-values: apc.enabled=1, apc.shm_size=32M, apc.ttl=7200, apc.enable_cli=1, apc.serializer=php
3939
- name: Run tests on PHP 7.4
40-
run: php -f ./bin/ci/run_tests.php
40+
run: php -f ./bin/ci/run_tests.php
41+
42+
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
43+
# Docs: https://getcomposer.org/doc/articles/scripts.md
44+
- name: Run tests on PHP 8.0
45+
run: php -f ./bin/ci/run_tests.php
46+
- name: Setup PHP 8.0
47+
uses: shivammathur/setup-php@v2
48+
with:
49+
php-version: '8.0'
50+
coverage: none
51+
extensions: mbstring, intl, pdo_sqlite, json
52+
ini-values: apc.enabled=1, apc.shm_size=32M, apc.ttl=7200, apc.enable_cli=1, apc.serializer=php
53+
- name: Run tests on PHP 8.0
54+
run: php -f ./bin/ci/run_tests.php

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ php:
4141
# - 7.2
4242
- 7.3
4343
- 7.4
44-
- nightly
44+
- 8.0
45+
# - nightly # crashes on almost every builds, very unstable
4546
- hhvm
4647

4748
jobs:
4849
fast_finish: true
4950
allow_failures:
50-
- php: nightly
51+
# - php: nightly
5152
- php: hhvm
53+
- php: 8.0
5254

5355
install:
5456
- ./bin/ci/install_dependencies.sh

bin/ci/run_tests.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
$timestamp = microtime(true);
1212
$climate = new League\CLImate\CLImate;
1313
$climate->forceAnsiOn();
14+
$phpBinPath = 'php ';
1415
$status = 0;
1516
$dir = __DIR__;
1617
$driver = $argv[ 1 ] ?? 'Files';
18+
$phpBinPath = $_SERVER['PHP_BIN_PATH'] ?? 'php';
1719

1820
/**
1921
* @param string $pattern
@@ -23,17 +25,18 @@
2325
$globCallback = static function (string $pattern, int $flags = 0) use (&$globCallback): array
2426
{
2527
$files = \glob($pattern, $flags);
28+
$subFiles = [];
2629

2730
foreach (\glob(\dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
28-
$files = \array_merge($files, $globCallback($dir . '/' . \basename($pattern), $flags));
31+
$subFiles[] = $globCallback($dir . '/' . \basename($pattern), $flags);
2932
}
3033

31-
return $files;
34+
return \array_merge($files, ...$subFiles);
3235
};
3336

3437
foreach ($globCallback(PFC_TEST_DIR . DIRECTORY_SEPARATOR . '*.test.php') as $filename) {
3538
$climate->backgroundLightYellow()->blue()->out('---');
36-
$command = "php -f {$filename} {$driver}";
39+
$command = "{$phpBinPath} -f {$filename} {$driver}";
3740
$climate->out("<yellow>phpfastcache@unit-test</yellow> <blue>{$dir}</blue> <green>#</green> <red>$command</red>");
3841

3942
\exec($command, $output, $return_var);
@@ -63,4 +66,4 @@
6366
$climate->backgroundRed()->white()->flank('[KO] The build has failed miserably', '~')->out('');
6467
}
6568

66-
exit($status);
69+
exit($status);

lib/Phpfastcache/Drivers/Cookie/Driver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function driverReadExpirationDate($key): int
142142
* @return bool
143143
* @throws PhpfastcacheInvalidArgumentException
144144
*/
145-
protected function driverDelete(CacheItemInterface $item)
145+
protected function driverDelete(CacheItemInterface $item): bool
146146
{
147147
/**
148148
* Check for Cross-Driver type confusion
@@ -183,4 +183,4 @@ protected function driverClear(): bool
183183

184184
return $return;
185185
}
186-
}
186+
}

lib/Phpfastcache/Drivers/Couchbase/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected function driverWrite(CacheItemInterface $item): bool
169169
* @return bool
170170
* @throws PhpfastcacheInvalidArgumentException
171171
*/
172-
protected function driverDelete(CacheItemInterface $item)
172+
protected function driverDelete(CacheItemInterface $item): bool
173173
{
174174
/**
175175
* Check for Cross-Driver type confusion

lib/Phpfastcache/Util/ClassNamespaceResolverTrait.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ trait ClassNamespaceResolverTrait
4545
*/
4646
protected static function createClassMap($dir): array
4747
{
48-
if (is_string($dir)) {
48+
if (\is_string($dir)) {
4949
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
5050
}
5151
$map = [];
5252

53-
if (is_array($dir) || $dir instanceof Traversable) {
53+
if (\is_iterable($dir)) {
5454
foreach ($dir as $file) {
5555
if (!$file->isFile()) {
5656
continue;
@@ -98,10 +98,19 @@ protected static function findClasses(string $path): array
9898
switch ($token[0]) {
9999
case T_NAMESPACE:
100100
$namespace = '';
101-
// If there is a namespace, extract it
102-
while (isset($tokens[++$i][1])) {
103-
if (in_array($tokens[$i][0], [T_STRING, T_NS_SEPARATOR])) {
104-
$namespace .= $tokens[$i][1];
101+
// If there is a namespace, extract it (PHP 8 test)
102+
if(\defined('T_NAME_QUALIFIED')){
103+
while (isset($tokens[++$i][1])) {
104+
if ($tokens[$i][0] === T_NAME_QUALIFIED) {
105+
$namespace = $tokens[$i][1];
106+
break;
107+
}
108+
}
109+
}else{
110+
while (isset($tokens[++$i][1])) {
111+
if (\in_array($tokens[$i][0], [T_STRING, T_NS_SEPARATOR], true)) {
112+
$namespace .= $tokens[$i][1];
113+
}
105114
}
106115
}
107116
$namespace .= '\\';
@@ -118,7 +127,7 @@ protected static function findClasses(string $path): array
118127
if (T_DOUBLE_COLON === $tokens[$j][0]) {
119128
$isClassConstant = true;
120129
break;
121-
} elseif (!in_array($tokens[$j][0], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT], false)) {
130+
} elseif (!\in_array($tokens[$j][0], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT], false)) {
122131
break;
123132
}
124133
}
@@ -140,6 +149,7 @@ protected static function findClasses(string $path): array
140149
break;
141150
}
142151
}
152+
143153
return $classes;
144154
}
145155

tests/DriverListResolver.test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
$driverList = CacheManager::getDriverList();
2222

23+
2324
foreach ($driverList as $driver) {
2425
foreach ($subClasses as $subClass) {
2526
$className = "Phpfastcache\\Drivers\\{$driver}\\{$subClass}";
@@ -31,4 +32,4 @@
3132
}
3233
}
3334

34-
$testHelper->terminateTest();
35+
$testHelper->terminateTest();

0 commit comments

Comments
 (0)