Skip to content

Commit

Permalink
Merge pull request #6 from byjg/bump
Browse files Browse the repository at this point in the history
Fix several incompatibilities with PHP 8.x
  • Loading branch information
byjg authored May 21, 2023
2 parents 7c39421 + 8b09690 commit deec7d0
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 35 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: PHPUnit
on:
push:
branches:
- master
tags:
- "*.*.*"
pull_request:
branches:
- master

jobs:
Build:
runs-on: 'ubuntu-latest'
container: 'byjg/php:${{ matrix.php-version }}-cli'
strategy:
matrix:
php-version:
- "8.1"
- "8.0"
- "7.4"
- "7.3"
- "7.2"
- "7.1"

# Service containers to run
services:
memcached:
image: memcached
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- run: composer install
- run: ./vendor/bin/phpunit --stderr

Documentation:
runs-on: 'ubuntu-latest'
needs: Build
if: github.ref == 'refs/heads/master'
env:
DOC_GITHUB_TOKEN: '${{ secrets.DOC_TOKEN }}'
steps:
- uses: actions/checkout@v3
- run: curl https://opensource.byjg.com/add-doc.sh | bash /dev/stdin php cache-engine-php
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
vendor
config/cacheconfig.php
.idea
.phpunit.result.cache
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Cache Engine

[![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)
[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com)
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/cache-engine-php/)
[![GitHub license](https://img.shields.io/github/license/byjg/cache-engine-php.svg)](https://opensource.byjg.com/opensource/licensing.html)
[![GitHub release](https://img.shields.io/github/release/byjg/cache-engine-php.svg)](https://github.com/byjg/cache-engine-php/releases/)
[![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)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/f643fd22-8ab1-4f41-9bef-f9f9e127ec0d/mini.png)](https://insight.sensiolabs.com/projects/f643fd22-8ab1-4f41-9bef-f9f9e127ec0d)
[![Build Status](https://travis-ci.com/byjg/cache-engine-php.svg?branch=master)](https://travis-ci.com/byjg/cache-engine-php)



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

```
composer require "byjg/cache-engine=4.0.*"
composer require "byjg/cache-engine=4.9.*"
```


## Running Unit Testes

```
phpunit --stderr
vendor/bin/phpunit --stderr
```

**Note:** the parameter `--stderr` after `phpunit` is to permit run the tests on SessionCacheEngine.
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
},
"require": {
"php": ">=5.6.0",
"psr/cache": "1.0.*",
"psr/log": "1.0.*",
"psr/simple-cache": "1.0.*"
"psr/cache": "^1.0",
"psr/log": "^1.1",
"psr/simple-cache": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "5.7.*|7.4.*"
"phpunit/phpunit": "5.7.*|7.4.*|^9.5"
},
"suggest": {
"ext-memcached": "*",
Expand Down
10 changes: 9 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ and open the template in the editor.

<!-- see http://www.phpunit.de/wiki/Documentation -->
<phpunit bootstrap="./vendor/autoload.php"
colors="false"
colors="true"
testdox="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
stopOnFailure="false">

<php>
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
<ini name="error_reporting" value="E_ALL" />
</php>

<filter>
<whitelist>
<directory>./src</directory>
Expand Down
2 changes: 1 addition & 1 deletion src/Psr16/MemcachedEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function set($key, $value, $ttl = null)
{
$this->lazyLoadMemCachedServers();

$this->memCached->set($this->fixKey($key), serialize($value), $ttl);
$this->memCached->set($this->fixKey($key), serialize($value), is_null($ttl) ? 0 : $ttl);
$this->logger->info("[Memcached] Set '$key' result " . $this->memCached->getResultCode());
if ($this->memCached->getResultCode() !== Memcached::RES_SUCCESS) {
$this->logger->error("[Memcached] Set '$key' failed with status " . $this->memCached->getResultCode());
Expand Down
8 changes: 4 additions & 4 deletions src/Psr16/ShmopCacheEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function get($key, $default = null)
$this->logger->info("[Shmop Cache] Get '$key'");

$serialized = shmop_read($shm_id, 0, shmop_size($shm_id));
shmop_close($shm_id);
// shmop_close($shm_id);

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

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

if ($shm_id) {
shmop_delete($shm_id);
shmop_close($shm_id);
// shmop_close($shm_id);

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

if ($exists) {
shmop_close($shm_id);
// shmop_close($shm_id);
return $this->isValidAge($file);
}

Expand Down
11 changes: 3 additions & 8 deletions tests/BaseCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,16 @@ abstract class BaseCacheTest extends TestCase
*/
protected $cacheEngine = null;

protected function setUp()
{

}

protected function tearDown()
protected function tearDown(): void
{
$this->cacheEngine->clear();
$this->cacheEngine = null;
}

public function CachePoolProvider()
{
$memcachedServer = ['memcached-container:11211'];
$redisCacheServer = 'redis-container:6379';
$memcachedServer = ['memcached:11211'];
$redisCacheServer = 'redis:6379';
$redisPassword = '';

return [
Expand Down
22 changes: 11 additions & 11 deletions tests/CachePSR16Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testGetOneItem(BaseCacheEngine $cacheEngine)
if ($cacheEngine->isAvailable()) {
// First time
$item = $cacheEngine->get('chave', null);
$this->assertEquals(null, $item);
$this->assertNull($item);
$item = $cacheEngine->get('chave', 'default');
$this->assertEquals('default', $item);

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

// Check Removed
$item = $cacheEngine->get('chave');
$this->assertEquals(null, $item);
$this->assertNull($item);
} else {
$this->markTestIncomplete('Object is not fully functional');
}
Expand All @@ -58,8 +58,8 @@ public function testGetMultipleItems(BaseCacheEngine $cacheEngine)
if ($cacheEngine->isAvailable()) {
// First time
$items = $cacheEngine->getMultiple(['chave1', 'chave2']);
$this->assertEquals(null, $items['chave1']);
$this->assertEquals(null, $items['chave2']);
$this->assertNull($items['chave1']);
$this->assertNull($items['chave2']);
$items = $cacheEngine->getMultiple(['chave1', 'chave2'], 'default');
$this->assertEquals('default', $items['chave1']);
$this->assertEquals('default', $items['chave2']);
Expand All @@ -80,8 +80,8 @@ public function testGetMultipleItems(BaseCacheEngine $cacheEngine)

// Check Removed
$items = $cacheEngine->getMultiple(['chave1', 'chave2']);
$this->assertEquals(null, $items['chave1']);
$this->assertEquals(null, $items['chave2']);
$this->assertNull($items['chave1']);
$this->assertNull($items['chave2']);
} else {
$this->markTestIncomplete('Object is not fully functional');
}
Expand All @@ -99,10 +99,10 @@ public function testTtl(BaseCacheEngine $cacheEngine)
if ($cacheEngine->isAvailable()) {
// First time
$item = $cacheEngine->get('chave');
$this->assertEquals(null, $item);
$this->assertNull($item);
$this->assertFalse($cacheEngine->has('chave'));
$item2 = $cacheEngine->get('chave2');
$this->assertEquals(null, $item2);
$this->assertNull($item2);
$this->assertFalse($cacheEngine->has('chave2'));

// Set object
Expand All @@ -116,7 +116,7 @@ public function testTtl(BaseCacheEngine $cacheEngine)
$this->assertTrue($cacheEngine->has('chave2'));
sleep(3);
$item2 = $cacheEngine->get('chave');
$this->assertEquals(null, $item2);
$this->assertNull($item2);
$this->assertFalse($cacheEngine->has('chave2'));
}
} else {
Expand All @@ -136,7 +136,7 @@ public function testCacheObject(BaseCacheEngine $cacheEngine)
if ($cacheEngine->isAvailable()) {
// First time
$item = $cacheEngine->get('chave');
$this->assertEquals(null, $item);
$this->assertNull($item);

// Set object
$model = new Model(10, 20);
Expand All @@ -151,7 +151,7 @@ public function testCacheObject(BaseCacheEngine $cacheEngine)
// Delete
$cacheEngine->delete('chave');
$item = $cacheEngine->get('chave');
$this->assertEquals(null, $item);
$this->assertNull($item);
} else {
$this->markTestIncomplete('Object is not fully functional');
}
Expand Down

0 comments on commit deec7d0

Please sign in to comment.