Skip to content

Commit deec7d0

Browse files
authored
Merge pull request #6 from byjg/bump
Fix several incompatibilities with PHP 8.x
2 parents 7c39421 + 8b09690 commit deec7d0

File tree

9 files changed

+87
-35
lines changed

9 files changed

+87
-35
lines changed

.github/workflows/phpunit.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: PHPUnit
2+
on:
3+
push:
4+
branches:
5+
- master
6+
tags:
7+
- "*.*.*"
8+
pull_request:
9+
branches:
10+
- master
11+
12+
jobs:
13+
Build:
14+
runs-on: 'ubuntu-latest'
15+
container: 'byjg/php:${{ matrix.php-version }}-cli'
16+
strategy:
17+
matrix:
18+
php-version:
19+
- "8.1"
20+
- "8.0"
21+
- "7.4"
22+
- "7.3"
23+
- "7.2"
24+
- "7.1"
25+
26+
# Service containers to run
27+
services:
28+
memcached:
29+
image: memcached
30+
redis:
31+
image: redis
32+
options: >-
33+
--health-cmd "redis-cli ping"
34+
--health-interval 10s
35+
--health-timeout 5s
36+
--health-retries 5
37+
38+
steps:
39+
- uses: actions/checkout@v3
40+
- run: composer install
41+
- run: ./vendor/bin/phpunit --stderr
42+
43+
Documentation:
44+
runs-on: 'ubuntu-latest'
45+
needs: Build
46+
if: github.ref == 'refs/heads/master'
47+
env:
48+
DOC_GITHUB_TOKEN: '${{ secrets.DOC_TOKEN }}'
49+
steps:
50+
- uses: actions/checkout@v3
51+
- run: curl https://opensource.byjg.com/add-doc.sh | bash /dev/stdin php cache-engine-php

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ composer.lock
44
vendor
55
config/cacheconfig.php
66
.idea
7+
.phpunit.result.cache

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# Cache Engine
22

3+
[![Build Status](https://github.com/byjg/cache-engine-php/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/cache-engine-php/actions/workflows/phpunit.yml)
34
[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com)
45
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/cache-engine-php/)
56
[![GitHub license](https://img.shields.io/github/license/byjg/cache-engine-php.svg)](https://opensource.byjg.com/opensource/licensing.html)
67
[![GitHub release](https://img.shields.io/github/release/byjg/cache-engine-php.svg)](https://github.com/byjg/cache-engine-php/releases/)
7-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/byjg/cache-engine-php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/byjg/cache-engine-php/?branch=master)
8-
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/f643fd22-8ab1-4f41-9bef-f9f9e127ec0d/mini.png)](https://insight.sensiolabs.com/projects/f643fd22-8ab1-4f41-9bef-f9f9e127ec0d)
9-
[![Build Status](https://travis-ci.com/byjg/cache-engine-php.svg?branch=master)](https://travis-ci.com/byjg/cache-engine-php)
10-
118

129

1310
A multi-purpose cache engine PSR-6 and PSR-16 implementation with several drivers.
@@ -102,14 +99,14 @@ See log examples [here](docs/setup-log-handler.md)
10299
Just type:
103100

104101
```
105-
composer require "byjg/cache-engine=4.0.*"
102+
composer require "byjg/cache-engine=4.9.*"
106103
```
107104

108105

109106
## Running Unit Testes
110107

111108
```
112-
phpunit --stderr
109+
vendor/bin/phpunit --stderr
113110
```
114111

115112
**Note:** the parameter `--stderr` after `phpunit` is to permit run the tests on SessionCacheEngine.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
},
99
"require": {
1010
"php": ">=5.6.0",
11-
"psr/cache": "1.0.*",
12-
"psr/log": "1.0.*",
13-
"psr/simple-cache": "1.0.*"
11+
"psr/cache": "^1.0",
12+
"psr/log": "^1.1",
13+
"psr/simple-cache": "^1.0"
1414
},
1515
"require-dev": {
16-
"phpunit/phpunit": "5.7.*|7.4.*"
16+
"phpunit/phpunit": "5.7.*|7.4.*|^9.5"
1717
},
1818
"suggest": {
1919
"ext-memcached": "*",

phpunit.xml.dist

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ and open the template in the editor.
77

88
<!-- see http://www.phpunit.de/wiki/Documentation -->
99
<phpunit bootstrap="./vendor/autoload.php"
10-
colors="false"
10+
colors="true"
11+
testdox="true"
1112
convertErrorsToExceptions="true"
1213
convertNoticesToExceptions="true"
1314
convertWarningsToExceptions="true"
15+
convertDeprecationsToExceptions="true"
1416
stopOnFailure="false">
1517

18+
<php>
19+
<ini name="display_errors" value="On" />
20+
<ini name="display_startup_errors" value="On" />
21+
<ini name="error_reporting" value="E_ALL" />
22+
</php>
23+
1624
<filter>
1725
<whitelist>
1826
<directory>./src</directory>

src/Psr16/MemcachedEngine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function set($key, $value, $ttl = null)
8787
{
8888
$this->lazyLoadMemCachedServers();
8989

90-
$this->memCached->set($this->fixKey($key), serialize($value), $ttl);
90+
$this->memCached->set($this->fixKey($key), serialize($value), is_null($ttl) ? 0 : $ttl);
9191
$this->logger->info("[Memcached] Set '$key' result " . $this->memCached->getResultCode());
9292
if ($this->memCached->getResultCode() !== Memcached::RES_SUCCESS) {
9393
$this->logger->error("[Memcached] Set '$key' failed with status " . $this->memCached->getResultCode());

src/Psr16/ShmopCacheEngine.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function get($key, $default = null)
9696
$this->logger->info("[Shmop Cache] Get '$key'");
9797

9898
$serialized = shmop_read($shm_id, 0, shmop_size($shm_id));
99-
shmop_close($shm_id);
99+
// shmop_close($shm_id);
100100

101101
return unserialize($serialized);
102102
}
@@ -158,7 +158,7 @@ public function set($key, $value, $ttl = null)
158158
if ($shm_bytes_written != $size) {
159159
$this->logger->warning("Couldn't write the entire length of data");
160160
}
161-
shmop_close($shm_id);
161+
// shmop_close($shm_id);
162162

163163
$validUntil = $this->addToNow($ttl);
164164
if (!empty($validUntil)) {
@@ -201,7 +201,7 @@ private function deleteFromFilenameToken($file)
201201

202202
if ($shm_id) {
203203
shmop_delete($shm_id);
204-
shmop_close($shm_id);
204+
// shmop_close($shm_id);
205205

206206
$this->logger->info("[Shmop Cache] release confirmed.");
207207
}
@@ -227,7 +227,7 @@ public function has($key)
227227
$exists = !(!$shm_id);
228228

229229
if ($exists) {
230-
shmop_close($shm_id);
230+
// shmop_close($shm_id);
231231
return $this->isValidAge($file);
232232
}
233233

tests/BaseCacheTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,16 @@ abstract class BaseCacheTest extends TestCase
1313
*/
1414
protected $cacheEngine = null;
1515

16-
protected function setUp()
17-
{
18-
19-
}
20-
21-
protected function tearDown()
16+
protected function tearDown(): void
2217
{
2318
$this->cacheEngine->clear();
2419
$this->cacheEngine = null;
2520
}
2621

2722
public function CachePoolProvider()
2823
{
29-
$memcachedServer = ['memcached-container:11211'];
30-
$redisCacheServer = 'redis-container:6379';
24+
$memcachedServer = ['memcached:11211'];
25+
$redisCacheServer = 'redis:6379';
3126
$redisPassword = '';
3227

3328
return [

tests/CachePSR16Test.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testGetOneItem(BaseCacheEngine $cacheEngine)
2121
if ($cacheEngine->isAvailable()) {
2222
// First time
2323
$item = $cacheEngine->get('chave', null);
24-
$this->assertEquals(null, $item);
24+
$this->assertNull($item);
2525
$item = $cacheEngine->get('chave', 'default');
2626
$this->assertEquals('default', $item);
2727

@@ -39,7 +39,7 @@ public function testGetOneItem(BaseCacheEngine $cacheEngine)
3939

4040
// Check Removed
4141
$item = $cacheEngine->get('chave');
42-
$this->assertEquals(null, $item);
42+
$this->assertNull($item);
4343
} else {
4444
$this->markTestIncomplete('Object is not fully functional');
4545
}
@@ -58,8 +58,8 @@ public function testGetMultipleItems(BaseCacheEngine $cacheEngine)
5858
if ($cacheEngine->isAvailable()) {
5959
// First time
6060
$items = $cacheEngine->getMultiple(['chave1', 'chave2']);
61-
$this->assertEquals(null, $items['chave1']);
62-
$this->assertEquals(null, $items['chave2']);
61+
$this->assertNull($items['chave1']);
62+
$this->assertNull($items['chave2']);
6363
$items = $cacheEngine->getMultiple(['chave1', 'chave2'], 'default');
6464
$this->assertEquals('default', $items['chave1']);
6565
$this->assertEquals('default', $items['chave2']);
@@ -80,8 +80,8 @@ public function testGetMultipleItems(BaseCacheEngine $cacheEngine)
8080

8181
// Check Removed
8282
$items = $cacheEngine->getMultiple(['chave1', 'chave2']);
83-
$this->assertEquals(null, $items['chave1']);
84-
$this->assertEquals(null, $items['chave2']);
83+
$this->assertNull($items['chave1']);
84+
$this->assertNull($items['chave2']);
8585
} else {
8686
$this->markTestIncomplete('Object is not fully functional');
8787
}
@@ -99,10 +99,10 @@ public function testTtl(BaseCacheEngine $cacheEngine)
9999
if ($cacheEngine->isAvailable()) {
100100
// First time
101101
$item = $cacheEngine->get('chave');
102-
$this->assertEquals(null, $item);
102+
$this->assertNull($item);
103103
$this->assertFalse($cacheEngine->has('chave'));
104104
$item2 = $cacheEngine->get('chave2');
105-
$this->assertEquals(null, $item2);
105+
$this->assertNull($item2);
106106
$this->assertFalse($cacheEngine->has('chave2'));
107107

108108
// Set object
@@ -116,7 +116,7 @@ public function testTtl(BaseCacheEngine $cacheEngine)
116116
$this->assertTrue($cacheEngine->has('chave2'));
117117
sleep(3);
118118
$item2 = $cacheEngine->get('chave');
119-
$this->assertEquals(null, $item2);
119+
$this->assertNull($item2);
120120
$this->assertFalse($cacheEngine->has('chave2'));
121121
}
122122
} else {
@@ -136,7 +136,7 @@ public function testCacheObject(BaseCacheEngine $cacheEngine)
136136
if ($cacheEngine->isAvailable()) {
137137
// First time
138138
$item = $cacheEngine->get('chave');
139-
$this->assertEquals(null, $item);
139+
$this->assertNull($item);
140140

141141
// Set object
142142
$model = new Model(10, 20);
@@ -151,7 +151,7 @@ public function testCacheObject(BaseCacheEngine $cacheEngine)
151151
// Delete
152152
$cacheEngine->delete('chave');
153153
$item = $cacheEngine->get('chave');
154-
$this->assertEquals(null, $item);
154+
$this->assertNull($item);
155155
} else {
156156
$this->markTestIncomplete('Object is not fully functional');
157157
}

0 commit comments

Comments
 (0)