Skip to content

Commit

Permalink
:octocat:
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Feb 13, 2024
1 parent fca6963 commit 82822c4
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 59 deletions.
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/.build export-ignore
/.github export-ignore
/.phan export-ignore
/.phpdoc export-ignore
/docs export-ignore
/examples export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.readthedocs.yml export-ignore
/phpcs.xml.dist export-ignore
/phpdoc.xml.dist export-ignore
/phpmd.xml.dist export-ignore
/phpunit.xml.dist export-ignore

*.php diff=php
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
php-version:
- "8.1"
- "8.2"
- "8.3"

env:
PHAN_ALLOW_XDEBUG: 0
Expand Down Expand Up @@ -59,13 +60,13 @@ jobs:
- name: "Install PHP"
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
php-version: "8.1"
coverage: none
tools: phpDocumentor
extensions: apcu, memcached, redis

- name: "Build Docs"
run: phpdoc --config=phpdoc.xml
run: phpdoc --config=phpdoc.xml.dist

- name: "Publish Docs to gh-pages"
uses: JamesIves/github-pages-deploy-action@v4
Expand All @@ -86,6 +87,7 @@ jobs:
php-version:
- "8.1"
- "8.2"
- "8.3"

steps:
- name: "Checkout"
Expand All @@ -111,7 +113,7 @@ jobs:
uses: ramsey/composer-install@v2

- name: "Run tests with phpunit"
run: php vendor/phpunit/phpunit/phpunit --configuration=phpunit.xml
run: php vendor/phpunit/phpunit/phpunit --configuration=phpunit.xml.dist

- name: "Send code coverage report to Codecov.io"
uses: codecov/codecov-action@v3
16 changes: 0 additions & 16 deletions .scrutinizer.yml

This file was deleted.

3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ A psr/simple-cache implementation for PHP 8.1+.
[![version][packagist-badge]][packagist]
[![license][license-badge]][license]
[![Coverage][coverage-badge]][coverage]
[![Scrunitizer][scrutinizer-badge]][scrutinizer]
[![Packagist downloads][downloads-badge]][downloads]<br/>
[![Continuous Integration][gh-action-badge]][gh-action]

Expand All @@ -18,8 +17,6 @@ A psr/simple-cache implementation for PHP 8.1+.
[license]: https://github.com/chillerlan/php-cache/blob/master/LICENSE
[coverage-badge]: https://img.shields.io/codecov/c/github/chillerlan/php-cache.svg?logo=codecov
[coverage]: https://codecov.io/github/chillerlan/php-cache
[scrutinizer-badge]: https://img.shields.io/scrutinizer/g/chillerlan/php-cache.svg?logo=scrutinizer
[scrutinizer]: https://scrutinizer-ci.com/g/chillerlan/php-cache
[downloads-badge]: https://img.shields.io/packagist/dt/chillerlan/php-cache.svg?logo=packagist
[downloads]: https://packagist.org/packages/chillerlan/php-cache/stats
[gh-action-badge]: https://github.com/chillerlan/php-cache/workflows/Continuous%20Integration/badge.svg
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chillerlan/php-cache",
"description": "A psr/simple-cache implementation. PHP 7.4+",
"description": "A psr/simple-cache implementation. PHP 8.1+",
"homepage": "https://github.com/chillerlan/php-cache",
"license": "MIT",
"type": "library",
Expand All @@ -23,11 +23,11 @@
"php": "^8.1",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"psr/simple-cache": "^1.0",
"chillerlan/php-settings-container": "^3.0"
"chillerlan/php-settings-container": "^3.1"
},
"require-dev": {
"phan/phan": "^5.4",
"phpunit/phpunit": "^10.0"
"phpunit/phpunit": "^10.5"
},
"autoload": {
"psr-4": {
Expand Down
20 changes: 0 additions & 20 deletions phpdoc.xml

This file was deleted.

25 changes: 25 additions & 0 deletions phpdoc.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/phpDocumentor/phpDocumentor/master/data/xsd/phpdoc.xsd"
configVersion="3"
>
<!-- https://docs.phpdoc.org/3.0/guide/references/configuration.html#configuration -->
<paths>
<output>.build/phpdocs</output>
<cache>.build/phpdocs-cache</cache>
</paths>
<version number="3.0.0">
<api>
<source dsn=".">
<path>src</path>
<path>tests</path>
</source>
<extensions>
<extension>php</extension>
</extensions>
</api>
</version>
<setting name="template.color" value="deep-purple"/>
<template name="default" />
</phpdocumentor>
14 changes: 7 additions & 7 deletions phpunit.xml → phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".build/phpunit.result.cache"
cacheDirectory=".build/phpunit-cache"
colors="true"
>
<testsuites>
<testsuite name="php-cache test suite">
<directory suffix=".php">./tests</directory>
<exclude>tests/NonpersistentTestAbstract.php</exclude>
<exclude>tests/SimpleCacheTestAbstract.php</exclude>
<directory>./tests</directory>
</testsuite>
</testsuites>
<coverage>
<source>
<include>
<directory suffix=".php">./src</directory>
<directory>src</directory>
</include>
</source>
<coverage>
<report>
<clover outputFile=".build/coverage/clover.xml"/>
<xml outputDirectory=".build/coverage/coverage-xml"/>
Expand Down
36 changes: 31 additions & 5 deletions src/APCUCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace chillerlan\SimpleCache;

use function apcu_clear_cache, apcu_delete, apcu_fetch, apcu_store;
use function apcu_clear_cache, apcu_delete, apcu_fetch, apcu_store, implode, is_array, is_bool, sprintf;

class APCUCache extends CacheDriverAbstract{

Expand All @@ -27,14 +27,40 @@ public function get($key, $default = null){
return $default;
}

/** @inheritdoc */
/**
* @inheritdoc
* @throws \Psr\SimpleCache\CacheException
*/
public function set($key, $value, $ttl = null):bool{
return (bool)apcu_store($this->checkKey($key), $value, $this->getTTL($ttl) ?? 0);
$ret = apcu_store($this->checkKey($key), $value, $this->getTTL($ttl) ?? 0);

if(is_bool($ret)){
return $ret;
}

if(is_array($ret)){
throw new CacheException(sprintf('error keys: %s', implode(', ', $ret)));
}

throw new CacheException('unknown apcu_store() error');
}

/** @inheritdoc */
/**
* @inheritdoc
* @throws \chillerlan\SimpleCache\CacheException
*/
public function delete($key):bool{
return (bool)apcu_delete($this->checkKey($key));
$ret = apcu_delete($this->checkKey($key));

if(is_bool($ret)){
return $ret;
}

if(is_array($ret)){
throw new CacheException(sprintf('error keys: %s', implode(', ', $ret)));
}

throw new CacheException('unknown apcu_delete() error');
}

/** @inheritdoc */
Expand Down
3 changes: 2 additions & 1 deletion tests/APCUTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
class APCUTest extends SimpleCacheTestAbstract{

protected function setUp():void{
parent::setUp();

if(!extension_loaded('apcu')){
$this->markTestSkipped('APCU not installed/enabled');
}

parent::setUp();

$this->cache = new APCUCache;
}

Expand Down
3 changes: 2 additions & 1 deletion tests/MemcachedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
class MemcachedTest extends SimpleCacheTestAbstract{

protected function setUp():void{
parent::setUp();

if(!extension_loaded('memcached')){
$this->markTestSkipped('Memcached not installed/enabled');
}

parent::setUp();

$memcached = new Memcached('test');
$memcached->addServer('localhost', 11211);

Expand Down

0 comments on commit 82822c4

Please sign in to comment.