cache-memcached.php

Memcached driver for my cache library
git clone git://git.finwo.net/lib/cache-memcached.php
Log | Files | Refs | README

commit d36b980708566b31adcc8c90c04ca01b733f2beb
parent 80369f2afabfa5de4c8d08b70e3370a73a010dc6
Author: finwo <finwo@pm.me>
Date:   Mon, 20 Jun 2016 10:59:03 +0200

Merge pull request #1 from finwo/develop

RC
Diffstat:
A.travis.yml | 11+++++++++++
AREADME.md | 23+++++++++++++++++++++++
Mcomposer.json | 4++--
Mcomposer.lock | 15+++++++++------
Aphpunit.xml | 19+++++++++++++++++++
Msrc/Memcached.php | 12++++++------
Atests/LintTest.php | 33+++++++++++++++++++++++++++++++++
7 files changed, 103 insertions(+), 14 deletions(-)

diff --git a/.travis.yml b/.travis.yml @@ -0,0 +1,11 @@ +language: php +php: + - '5.3' + - '5.4' + - '5.5' + - '5.6' + - '7.0' + +install: + - yes '' | pecl install -f memcached + - composer update --prefer-dist diff --git a/README.md b/README.md @@ -0,0 +1,23 @@ +# finwo / cache-memcached + +[![Build Status](https://travis-ci.org/finwo/php-cache-memcached.svg?branch=master)](https://travis-ci.org/finwo/php-cache-memcached) + +----- + +Memcached driver for [finwo/cache](https://github.com/finwo/php-cache) + +----- + +### Contributing + +After checking the [Github issues](https://github.com/finwo/php-cache-memcached/issues) and confirming that your request isn't already being worked on, feel free to spawn a new fork of the develop branch & send in a pull request. + + +The develop branch is merged periodically into the master after confirming it's stable, to make sure the master always contains a production-ready version. + +----- + +### Changelog +- 2016-06-20 + - Created README + - Added CI tests diff --git a/composer.json b/composer.json @@ -11,8 +11,8 @@ "psr-4": { "Finwo\\Cache\\": "src" } }, "require": { - "php": ">=5.3", + "php": ">=5.3", "ext-memcached": "*", - "finwo/cache": "*" + "finwo/cache": "*" } } diff --git a/composer.lock b/composer.lock @@ -4,26 +4,29 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "2f539c9bc9114dabe04045b0018bbadb", + "hash": "899d50e9cdbdb7d9fbcfbe3e63f19085", "content-hash": "a89efc2080e35f50a3fdbf1064c2ee17", "packages": [ { "name": "finwo/cache", - "version": "v0.2", + "version": "v0.3.1", "source": { "type": "git", "url": "https://github.com/finwo/php-cache.git", - "reference": "9342ec1ae2f0f682f4fe5cfcbd4829c977055304" + "reference": "caccc641cb0fd6973a654a2f333c4a91e32798d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/finwo/php-cache/zipball/9342ec1ae2f0f682f4fe5cfcbd4829c977055304", - "reference": "9342ec1ae2f0f682f4fe5cfcbd4829c977055304", + "url": "https://api.github.com/repos/finwo/php-cache/zipball/caccc641cb0fd6973a654a2f333c4a91e32798d3", + "reference": "caccc641cb0fd6973a654a2f333c4a91e32798d3", "shasum": "" }, "require": { "php": ">=5.3" }, + "require-dev": { + "phpunit/phpunit": "*" + }, "type": "library", "autoload": { "psr-4": { @@ -37,7 +40,7 @@ "email": "robin@finwo.nl" } ], - "time": "2016-05-30 14:59:20" + "time": "2016-06-20 08:54:06" } ], "packages-dev": [], diff --git a/phpunit.xml b/phpunit.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<phpunit bootstrap="vendor/autoload.php" colors="true"> + + <testsuites> + <testsuite name="finwo/cache-memcached test suite"> + <directory>./tests/</directory> + </testsuite> + </testsuites> + + <filter> + <whitelist> + <directory>./</directory> + <exclude> + <directory>./tests</directory> + </exclude> + </whitelist> + </filter> +</phpunit> diff --git a/src/Memcached.php b/src/Memcached.php @@ -52,9 +52,9 @@ class Memcached extends Cache public function fetch($key = '', $ttl = 30) { // Generate seperate keys for fetching - $key_lock = md5(sprintf("%s_lock", $key)); - $key_data = md5(sprintf("%s_data", $key)); - $key_ttl = md5(sprintf("%s_ttl", $key)); + $key_lock = \md5(\sprintf("%s_lock", $key)); + $key_data = \md5(\sprintf("%s_data", $key)); + $key_ttl = \md5(\sprintf("%s_ttl", $key)); // Fetch memcached object $memcached = $this->getMemcached(); @@ -86,11 +86,11 @@ class Memcached extends Cache public function store($key = '', $value, $ttl = 30) { // Generate seperate keys for storing - $key_data = md5(sprintf("%s_data", $key)); - $key_ttl = md5(sprintf("%s_ttl", $key)); + $key_data = \md5(\sprintf("%s_data", $key)); + $key_ttl = \md5(\sprintf("%s_ttl", $key)); // Pre-generate time - $time_data = max(3600, $ttl*10); + $time_data = \max(3600, $ttl*10); // Fetch memcached object $memcached = $this->getMemcached(); diff --git a/tests/LintTest.php b/tests/LintTest.php @@ -0,0 +1,33 @@ +<?php + +class LintTest extends \PHPUnit_Framework_TestCase +{ + public function testSrc() + { + // Main entry + $fileList = \glob('src/'); + + // Loop through known files + while ( $inode = \array_shift($fileList) ) { + + // Try to iterate deeper + if ( is_dir($inode) ) { + $fileList = \array_merge($fileList, \glob(\realpath($inode).'/*')); + continue; + } + + // If we're a PHP file + if (\preg_match('/^.+\.(php|inc)$/i', $inode)) { + // Run a unit test + $this->lintFile($inode); + } + + } + } + + private function lintFile($filename = '') + { + // And actually run the test (with proper error message) + $this->assertContains('No syntax errors', \exec(\sprintf('php -l "%s"', $filename), $out), \sprintf("%s contains syntax errors", $filename)); + } +}