diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6bfadb9 --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/FilesystemMap.php b/FilesystemMap.php index 5cf9de1..d64117d 100644 --- a/FilesystemMap.php +++ b/FilesystemMap.php @@ -13,7 +13,7 @@ class FilesystemMap * * @var array */ - private $map; + protected $map; /** * Instanciates a new filesystem map diff --git a/Resources/config/gaufrette.xml b/Resources/config/gaufrette.xml index c901c08..5fbdde6 100644 --- a/Resources/config/gaufrette.xml +++ b/Resources/config/gaufrette.xml @@ -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"> + + Knp\Bundle\GaufretteBundle\FilesystemMap + @@ -31,7 +34,7 @@ - + diff --git a/Tests/FilesystemMapTest.php b/Tests/FilesystemMapTest.php new file mode 100644 index 0000000..321d4e8 --- /dev/null +++ b/Tests/FilesystemMapTest.php @@ -0,0 +1,43 @@ +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(); + } +} diff --git a/Tests/Functional/ConfigurationTest.php b/Tests/Functional/ConfigurationTest.php new file mode 100644 index 0000000..cc63ce4 --- /dev/null +++ b/Tests/Functional/ConfigurationTest.php @@ -0,0 +1,79 @@ +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')); + } +} diff --git a/Tests/Resources/config/config.yml b/Tests/Functional/Resources/config/config.yml similarity index 100% rename from Tests/Resources/config/config.yml rename to Tests/Functional/Resources/config/config.yml diff --git a/Tests/Resources/config/config_dev.yml b/Tests/Functional/Resources/config/config_dev.yml similarity index 100% rename from Tests/Resources/config/config_dev.yml rename to Tests/Functional/Resources/config/config_dev.yml diff --git a/Tests/Resources/config/config_test.yml b/Tests/Functional/Resources/config/config_test.yml similarity index 100% rename from Tests/Resources/config/config_test.yml rename to Tests/Functional/Resources/config/config_test.yml diff --git a/Tests/TestKernel.php b/Tests/Functional/TestKernel.php similarity index 90% rename from Tests/TestKernel.php rename to Tests/Functional/TestKernel.php index daa80e5..a923a43 100644 --- a/Tests/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -1,6 +1,6 @@ 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', - ) - ) - ); - } -} diff --git a/composer.json b/composer.json index 263386b..84bff0a 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,9 @@ "symfony/framework-bundle": "2.*", "knplabs/gaufrette": "*" }, + "require-dev": { + "symfony/yaml": "2.*" + }, "autoload": { "psr-0": { "Knp\\Bundle\\GaufretteBundle": "" diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..c7be983 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,29 @@ + + + + + + ./Tests + + + + + + . + + ./Resources + ./Tests + + + +