Merge pull request #19 from l3l0/improvements

Improvements
This commit is contained in:
Leszek Prabucki 2012-09-05 05:42:25 -07:00
commit aef3f1408c
12 changed files with 172 additions and 69 deletions

12
.travis.yml Normal file
View File

@ -0,0 +1,12 @@
language: php
php:
- 5.3
- 5.4
before_script:
- curl -s http://getcomposer.org/installer | php -- --quiet
- php composer.phar install --dev
script:
- phpunit

View File

@ -13,7 +13,7 @@ class FilesystemMap
*
* @var array
*/
private $map;
protected $map;
/**
* Instanciates a new filesystem map

View File

@ -4,6 +4,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="knp_gaufrette.filesystem_map.class">Knp\Bundle\GaufretteBundle\FilesystemMap</parameter>
</parameters>
<services>
<service id="knp_gaufrette.filesystem" class="Gaufrette\Filesystem" abstract="true">
<argument /><!-- The Adapter -->
@ -31,7 +34,7 @@
<argument /><!-- prefix -->
<argument /><!-- ttl -->
</service>
<service id="knp_gaufrette.filesystem_map" class="Knp\Bundle\GaufretteBundle\FilesystemMap">
<service id="knp_gaufrette.filesystem_map" class="%knp_gaufrette.filesystem_map.class%">
<argument /> <!-- map of filesystems -->
</service>
</services>

View File

@ -0,0 +1,43 @@
<?php
namespace Knp\Bundle\GaufretteBundle\Tests;
use Knp\Bundle\GaufretteBundle\FilesystemMap;
class FilesystemMapTest extends \PHPUnit_Framework_TestCase
{
private $filesystemMap;
public function setUp()
{
$this->filesystemMap = new FilesystemMap(array('amazon_fs' => $this->getFilesystem(), 'local_fs' => $this->getFilesystem()));
}
/**
* @test
*/
public function shouldGetFilesystemByKey()
{
$this->assertInstanceOf('Gaufrette\Filesystem', $this->filesystemMap->get('amazon_fs'), 'should get filesystem object by key');
$this->assertInstanceOf('Gaufrette\Filesystem', $this->filesystemMap->get('local_fs'), 'should get filesystem object by key');
}
/**
* @test
* @expectedException \InvalidArgumentException
*/
public function shouldNotGetFilesystemWhenKeyWasNotSet()
{
$this->filesystemMap->get('test');
}
/**
* @return Gaufrette\Filesystem
*/
private function getFilesystem()
{
return $this->getMockBuilder('Gaufrette\Filesystem')
->disableOriginalConstructor()
->getMock();
}
}

View File

@ -0,0 +1,79 @@
<?php
namespace Knp\Bundle\GaufretteBundle\Tests\Functional;
use Symfony\Component\HttpKernel\Util\Filesystem;
class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
private $cacheDir;
public function setUp()
{
$this->cacheDir = __DIR__.'/Resources/cache';
if (file_exists($this->cacheDir)) {
$filesystem = new Filesystem();
$filesystem->remove($this->cacheDir);
}
mkdir($this->cacheDir, 0777, true);
}
public function tearDown()
{
if (file_exists($this->cacheDir)) {
$filesystem = new Filesystem();
$filesystem->remove($this->cacheDir);
}
}
/**
* @test
*/
public function shouldAllowForFilesystemAlias()
{
$kernel = new TestKernel('test', false);
$kernel->boot();
$container = $kernel->getContainer();
$this->assertInstanceOf('Gaufrette\Filesystem', $container->get('foo_filesystem'));
}
/**
* @test
*/
public function shouldWorkForOtherEnv()
{
$kernel = new TestKernel('dev', false);
$kernel->boot();
$container = $kernel->getContainer();
$this->assertInstanceOf('Gaufrette\Filesystem', $container->get('foo_filesystem'));
}
/**
* @test
*/
public function shouldAllowAccessToAllPublicServices()
{
$kernel = new TestKernel('dev', false);
$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'));
}
/**
* @test
*/
public function shouldAllowAccessToFilesystemThoughFilesystemMap()
{
$kernel = new TestKernel('test', false);
$kernel->boot();
$container = $kernel->getContainer();
$this->assertInstanceOf('Gaufrette\Filesystem', $container->get('knp_gaufrette.filesystem_map')->get('foo'));
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Knp\Bundle\GaufretteBundle\Tests;
namespace Knp\Bundle\GaufretteBundle\Tests\Functional;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

View File

@ -1,66 +0,0 @@
<?php
namespace Knp\Bundle\GaufretteBundle\Tests;
use Symfony\Component\HttpKernel\Util\Filesystem;
class FunctionalTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->cacheDir = __DIR__.'/Resources/cache';
if (file_exists($this->cacheDir)) {
$filesystem = new Filesystem();
$filesystem->remove($this->cacheDir);
}
mkdir($this->cacheDir, 0777, true);
}
/**
* @dataProvider getConfigurationData
*/
public function testConfiguration($env, array $filesystems)
{
$kernel = new TestKernel($env, false);
$kernel->boot();
$container = $kernel->getContainer();
foreach ($filesystems as $id => $adapterClass) {
$this->assertTrue($container->has($id), sprintf('Filesystem service \'%s\' exists.', $id));
$filesystem = $container->get($id);
$this->assertInstanceOf('Gaufrette\Filesystem\Filesystem', $filesystem);
$reflProperty = new \ReflectionProperty($filesystem, 'adapter');
$reflProperty->setAccessible(true);
$adapter = $reflProperty->getValue($filesystem);
$reflProperty->setAccessible(false);
$this->assertInstanceOf($adapterClass, $adapter);
}
}
public function getConfigurationData()
{
return array(
array(
'dev',
array(
'gaufrette.foo_filesystem' => 'Gaufrette\Filesystem\Adapter\Local',
'foo_filesystem' => 'Gaufrette\Filesystem\Adapter\Local',
)
),
array(
'test',
array(
'gaufrette.foo_filesystem' => 'Gaufrette\Filesystem\Adapter\InMemory',
'foo_filesystem' => 'Gaufrette\Filesystem\Adapter\InMemory',
)
)
);
}
}

View File

@ -19,6 +19,9 @@
"symfony/framework-bundle": "2.*",
"knplabs/gaufrette": "*"
},
"require-dev": {
"symfony/yaml": "2.*"
},
"autoload": {
"psr-0": {
"Knp\\Bundle\\GaufretteBundle": ""

29
phpunit.xml.dist Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="KnpGaufretteBundle Test Suite">
<directory>./Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">.</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>