Skip to content

Commit

Permalink
Merge pull request #1 from henriquemoody/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
henriquemoody committed Jan 28, 2015
2 parents 922fea8 + fc5bcf3 commit b671f72
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 97 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
composer.lock
vendor
Makefile
28 changes: 25 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
language: php
script: make test
sudo:
false

language:
php

php:
- 5.3
- 5.4
- 5.3
- 5.5
- 5.6
- hhvm
- hhvm-nightly

cache:
directories:
- vendor

before_script:
- composer install --dev --no-interaction --prefer-source

script:
- vendor/bin/phpunit --colors

matrix:
allow_failures:
- php: hhvm
- php: hhvm-nightly
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License (MIT)

Copyright (c) 2013-2015, PHPFluent (https://github.com/PHPFluent).

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 0 additions & 2 deletions Makefile

This file was deleted.

44 changes: 27 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
Cache
=====

A fluent cache library for PHP.
# PHPFluent\Cache
[![Build Status](https://api.travis-ci.org/PHPFluent/Cache.png)](https://travis-ci.org/PHPFluent/Cache)

Usage:
```php
use PHPFluent\Cache\Cache;
/**
* @var Doctrine\Common\Cache\Cache $doctrine
*/
$doctrine;
A fluent cache library for PHP built on the shoulders of [Doctrine\Cache](https://github.com/doctrine/cache).

## Installation

Package is available on [Packagist](https://packagist.org/packages/phpfluent/cache), you can install it
using [Composer](http://getcomposer.org).

```bash
composer require phpfluent/cache
```

## Usage

```php
use PHPFluent\Cache\Cache;

/**
* @var Doctrine\Common\Cache\Cache $doctrine
*/
$doctrine;

$cache = new Cache($doctrine);
$cache['foo'] = 'bar'; //Caching the information
$cache = new Cache($doctrine);
$cache['foo'] = 'bar'; //Caching the information

echo isset($cache['foo']);
echo $cache['foo'];
echo isset($cache['foo']);
echo $cache['foo'];

unset($cache['foo']);//Deleting the cache
```
unset($cache['foo']);//Deleting the cache
```
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "phpfluent\/cache",
"name": "phpfluent/cache",
"description": "A conventional project tool for PHP and git.",
"version": "0.1",
"type": "library",
"time": "2013-02-24 21:00:00",
"homepage": "http:\/\/github.com/PHPFluent/Cache",
"homepage": "http://github.com/PHPFluent/Cache",
"license": "New BSD",
"authors": [
{
Expand All @@ -17,14 +15,15 @@
}
],
"autoload": {
"psr-0": {
"PHPFluent\\Cache": "src\/"
"psr-4": {
"PHPFluent\\Cache\\": "src/"
}
},
"require": {
"doctrine/common": "2.3.0"
"php": ">=5.3.2",
"doctrine/cache": "~1.4.0"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
"phpunit/phpunit": "~4.4"
}
}
8 changes: 8 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpunit>
<testsuites>
<testsuite>
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
17 changes: 10 additions & 7 deletions src/PHPFluent/Cache/Cache.php → src/Cache.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
<?php
namespace PHPFluent\Cache;

class Cache implements \ArrayAccess
use ArrayAccess;
use Doctrine\Common\Cache\Cache as DoctrineCache;

class Cache implements ArrayAccess
{
private $cache;
public function __construct(\Doctrine\Common\Cache\Cache $cache)

public function __construct(DoctrineCache $cache)
{
$this->cache = $cache;
}

public function offsetExists($id)
{
return $this->cache->contains($id);
}

public function offsetGet($id)
{
return $this->cache->fetch($id);
}

public function offsetSet($id, $data)
{
return $this->cache->save($id, $data);
}

public function offsetUnset($id)
{
return $this->cache->delete($id);
Expand Down
60 changes: 0 additions & 60 deletions tests/Cache/CacheTest.php

This file was deleted.

58 changes: 58 additions & 0 deletions tests/CacheTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace Cache;

use PHPFluent\Cache\Cache;

class CacheTest extends \PHPUnit_Framework_TestCase
{
public function testShouldReturnFooKey()
{
$mock = $this->getMockBuilder("Doctrine\Common\Cache\Cache")
->disableOriginalConstructor()
->getMock();
$mock->expects($this->any())
->method('contains')
->will($this->returnValue(true));
$mock->expects($this->once())
->method('fetch')
->with('foo')
->will($this->returnValue('bar'));
$mock->expects($this->any())
->method('save')
->will($this->returnValue(true));
$mock->expects($this->any())
->method('delete')
->will($this->returnValue(true));

$cache = new Cache($mock);
$this->assertTrue(isset($cache['foo']));
$this->assertEquals('bar', $cache['foo']);
$cache['foo'] = 'bar';
unset($cache['foo']);
}

public function testShouldReturnBazKey()
{
$mock = $this->getMockBuilder("Doctrine\Common\Cache\Cache")
->disableOriginalConstructor()
->getMock();
$mock->expects($this->any())
->method('contains')
->will($this->returnValue(true));
$mock->expects($this->once())
->method('fetch')
->with('baz')
->will($this->returnValue('weRock'));
$mock->expects($this->any())
->method('save')
->will($this->returnValue(true));
$mock->expects($this->any())
->method('delete')
->will($this->returnValue(true));
$cache = new Cache($mock);
$this->assertTrue(isset($cache['baz']));
$this->assertEquals('weRock', $cache['baz']);
$cache['baz'] = 'weRock';
unset($cache['baz']);
}
}

0 comments on commit b671f72

Please sign in to comment.