Add info about cache adapter to README. Added tests for cache and ftp

adapter.
This commit is contained in:
l3l0 2012-09-05 20:29:39 +02:00
parent dc98b98d3d
commit 0f3c770a24
3 changed files with 90 additions and 18 deletions

View File

@ -338,3 +338,42 @@ knp_gaufrette:
prefix: APC 'namespace' prefix prefix: APC 'namespace' prefix
ttl: 0 ttl: 0
``` ```
## Cache
Adapter which allow to cache other adapters
### Parameters
* `source` The source adapter that must be cached *(required)*
* `cache` The adapter used to cache the source *(required)*
* `ttl` Time to live *(default 0)*
* `serializer` The adapter used to cache serializations *(default null)*
### Example
``` yaml
# app/config/config.yml
knp_gaufrette:
adapters:
media_ftp:
ftp:
host: example.com
username: user
password: pass
directory: /example/ftp
create: true
mode: FTP_BINARY
media_apc:
apc:
prefix: APC 'namespace' prefix
ttl: 0
media_cache:
cache:
source: media_ftp
cache: media_apc
ttl: 7200
filesystems:
media:
adapter: media_cache
```

View File

@ -7,6 +7,7 @@ use Symfony\Component\HttpKernel\Util\Filesystem;
class ConfigurationTest extends \PHPUnit_Framework_TestCase class ConfigurationTest extends \PHPUnit_Framework_TestCase
{ {
private $cacheDir; private $cacheDir;
private $kernel;
public function setUp() public function setUp()
{ {
@ -17,6 +18,9 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
} }
mkdir($this->cacheDir, 0777, true); mkdir($this->cacheDir, 0777, true);
$this->kernel = new TestKernel('test', false);
$this->kernel->boot();
} }
public function tearDown() public function tearDown()
@ -32,12 +36,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
*/ */
public function shouldAllowForFilesystemAlias() public function shouldAllowForFilesystemAlias()
{ {
$kernel = new TestKernel('test', false); $this->assertInstanceOf('Gaufrette\Filesystem', $this->kernel->getContainer()->get('foo_filesystem'));
$kernel->boot();
$container = $kernel->getContainer();
$this->assertInstanceOf('Gaufrette\Filesystem', $container->get('foo_filesystem'));
} }
/** /**
@ -57,12 +56,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
*/ */
public function shouldAllowAccessToAllPublicServices() public function shouldAllowAccessToAllPublicServices()
{ {
$kernel = new TestKernel('dev', false); $this->assertInstanceOf('Knp\Bundle\GaufretteBundle\FilesystemMap', $this->kernel->getContainer()->get('knp_gaufrette.filesystem_map'));
$kernel->boot();
$container = $kernel->getContainer();
$this->assertInstanceOf('Gaufrette\Filesystem', $container->get('foo_filesystem'));
$this->assertInstanceOf('Knp\Bundle\GaufretteBundle\FilesystemMap', $container->get('knp_gaufrette.filesystem_map'));
} }
/** /**
@ -70,10 +64,30 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
*/ */
public function shouldAllowAccessToFilesystemThoughFilesystemMap() public function shouldAllowAccessToFilesystemThoughFilesystemMap()
{ {
$kernel = new TestKernel('test', false); $this->assertInstanceOf('Gaufrette\Filesystem', $this->kernel->getContainer()->get('knp_gaufrette.filesystem_map')->get('foo'));
$kernel->boot(); }
$container = $kernel->getContainer(); /**
$this->assertInstanceOf('Gaufrette\Filesystem', $container->get('knp_gaufrette.filesystem_map')->get('foo')); * @test
*/
public function shouldAllowAccessToLocalFilesystem()
{
$this->assertInstanceOf('Gaufrette\Adapter\Local', $this->kernel->getContainer()->get('foo_filesystem')->getAdapter());
}
/**
* @test
*/
public function shouldAllowAccessToCacheFilesystem()
{
$this->assertInstanceOf('Gaufrette\Adapter\Cache', $this->kernel->getContainer()->get('cache_filesystem')->getAdapter());
}
/**
* @test
*/
public function shouldAllowAccessToFtpFilesystem()
{
$this->assertInstanceOf('Gaufrette\Adapter\Ftp', $this->kernel->getContainer()->get('ftp_filesystem')->getAdapter());
} }
} }

View File

@ -1,11 +1,30 @@
knp_gaufrette: knp_gaufrette:
adapters: adapters:
foo: foo_local:
local: local:
directory: %kernel.root_dir% directory: %kernel.root_dir%
create: true create: true
foo_ftp:
ftp:
host: example.com
username: user
password: pass
directory: /example/ftp
create: true
mode: FTP_BINARY
foo_cache:
cache:
source: foo_ftp
cache: foo_local
ttl: 7200
filesystems: filesystems:
foo: foo:
adapter: foo adapter: foo_local
alias: foo_filesystem alias: foo_filesystem
cache:
adapter: foo_cache
alias: cache_filesystem
ftp:
adapter: foo_ftp
alias: ftp_filesystem