Initial commit

This commit is contained in:
Antoine Hérault
2011-05-08 23:04:37 +02:00
commit ae7440f4d7
22 changed files with 1019 additions and 0 deletions

66
Tests/FunctionalTest.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
namespace Knplabs\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

@@ -0,0 +1,69 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
class ResourcesTestProjectContainer extends Container
{
public function __construct()
{
$this->parameters = $this->getDefaultParameters();
$this->services =
$this->scopedServices =
$this->scopeStacks = array();
$this->set('service_container', $this);
$this->scopes = array();
$this->scopeChildren = array();
}
protected function getGaufrette_FooFilesystemService()
{
return $this->services['gaufrette.foo_filesystem'] = new \Gaufrette\Filesystem\Filesystem($this->get('knplabs_gaufrette.adapter.local.foo'));
}
protected function getKnplabsGaufrette_Adapter_Local_FooService()
{
return $this->services['knplabs_gaufrette.adapter.local.foo'] = new \Gaufrette\Filesystem\Adapter\InMemory(array());
}
protected function getFooFilesystemService()
{
return $this->get('gaufrette.foo_filesystem');
}
public function getParameter($name)
{
$name = strtolower($name);
if (!array_key_exists($name, $this->parameters)) {
throw new \InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
return $this->parameters[$name];
}
public function hasParameter($name)
{
return array_key_exists(strtolower($name), $this->parameters);
}
public function setParameter($name, $value)
{
throw new \LogicException('Impossible to call set() on a frozen ParameterBag.');
}
protected function getDefaultParameters()
{
return array(
'kernel.root_dir' => '/home/antoine/htdocs/symfony/vendor/bundles/Knplabs/Bundle/GaufretteBundle/Tests/Resources',
'kernel.environment' => 'test',
'kernel.debug' => false,
'kernel.name' => 'Resources',
'kernel.cache_dir' => '/home/antoine/htdocs/symfony/vendor/bundles/Knplabs/Bundle/GaufretteBundle/Tests/Resources/cache/test',
'kernel.logs_dir' => '/home/antoine/htdocs/symfony/vendor/bundles/Knplabs/Bundle/GaufretteBundle/Tests/Resources/logs',
'kernel.bundles' => array(
'KnplabsGaufretteBundle' => 'Knplabs\\Bundle\\GaufretteBundle\\KnplabsGaufretteBundle',
),
'kernel.charset' => 'UTF-8',
'kernel.container_class' => 'ResourcesTestProjectContainer',
'knplabs_gaufrette.filesystem.class' => 'Gaufrette\\Filesystem\\Filesystem',
'knplabs_gaufrette.adapter.in_memory.class' => 'Gaufrette\\Filesystem\\Adapter\\InMemory',
'knplabs_gaufrette.adapter.local.class' => 'Gaufrette\\Filesystem\\Adapter\\Local',
'knplabs_gaufrette.adapter.safe_local.class' => 'Gaufrette\\Filesystem\\Adapter\\SafeLocal',
'kernel.compiled_classes' => array(
),
);
}
}

View File

@@ -0,0 +1,11 @@
knplabs_gaufrette:
adapters:
foo:
local:
directory: %kernel.root_dir%
create: true
filesystems:
foo:
adapter: foo
alias: foo_filesystem

View File

@@ -0,0 +1,2 @@
imports:
- { resource: config.yml }

View File

@@ -0,0 +1,7 @@
imports:
- { resource: config.yml }
knplabs_gaufrette:
adapters:
foo:
in_memory: ~

26
Tests/TestKernel.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
namespace Knplabs\Bundle\GaufretteBundle\Tests;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;
class TestKernel extends Kernel
{
public function getRootDir()
{
return __DIR__.'/Resources';
}
public function registerBundles()
{
return array(
new \Knplabs\Bundle\GaufretteBundle\KnplabsGaufretteBundle(),
);
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/Resources/config/config_'.$this->getEnvironment().'.yml');
}
}