From fcde48018cb72038df338959bf708157ac6afda3 Mon Sep 17 00:00:00 2001 From: l3l0 Date: Tue, 4 Sep 2012 15:18:10 +0200 Subject: [PATCH 1/5] Moved and renamed functional tests. Simplified ConfigurationTest --- Tests/FilesystemMapTest.php | 43 ++++++++++ Tests/Functional/ConfigurationTest.php | 79 +++++++++++++++++++ .../Resources/config/config.yml | 0 .../Resources/config/config_dev.yml | 0 .../Resources/config/config_test.yml | 0 Tests/{ => Functional}/TestKernel.php | 2 +- Tests/FunctionalTest.php | 66 ---------------- phpunit.xml.dist | 29 +++++++ 8 files changed, 152 insertions(+), 67 deletions(-) create mode 100644 Tests/FilesystemMapTest.php create mode 100644 Tests/Functional/ConfigurationTest.php rename Tests/{ => Functional}/Resources/config/config.yml (100%) rename Tests/{ => Functional}/Resources/config/config_dev.yml (100%) rename Tests/{ => Functional}/Resources/config/config_test.yml (100%) rename Tests/{ => Functional}/TestKernel.php (90%) delete mode 100644 Tests/FunctionalTest.php create mode 100644 phpunit.xml.dist 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/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..2fb1f7c --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,29 @@ + + + + + + ./Tests + + + + + + . + + ./Resources + ./Tests + + + + From 5e4d9c832c82e7ac37b33985d46bc7104a8b4c27 Mon Sep 17 00:00:00 2001 From: l3l0 Date: Tue, 4 Sep 2012 15:19:11 +0200 Subject: [PATCH 2/5] Allow for change filesystem_map service implementation. Prepare FilesystemMap for extending --- FilesystemMap.php | 2 +- Resources/config/gaufrette.xml | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) 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..8d67963 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 @@ - + From ccd2a66f082e2ba6b85e93b2d6675c46c17454fb Mon Sep 17 00:00:00 2001 From: l3l0 Date: Tue, 4 Sep 2012 15:27:19 +0200 Subject: [PATCH 3/5] Added travis support --- .travis.yml | 12 ++++++++++++ composer.json | 3 +++ 2 files changed, 15 insertions(+) create mode 100644 .travis.yml 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/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": "" From a37631685955a5214890496d6f4c419f9d4a8c83 Mon Sep 17 00:00:00 2001 From: l3l0 Date: Tue, 4 Sep 2012 15:42:45 +0200 Subject: [PATCH 4/5] Remove tabs from config --- Resources/config/gaufrette.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/config/gaufrette.xml b/Resources/config/gaufrette.xml index 8d67963..5fbdde6 100644 --- a/Resources/config/gaufrette.xml +++ b/Resources/config/gaufrette.xml @@ -4,8 +4,8 @@ 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 + + Knp\Bundle\GaufretteBundle\FilesystemMap From 4743d7384ad0ca7c24fe9dbf26b9dd1811517c4a Mon Sep 17 00:00:00 2001 From: l3l0 Date: Tue, 4 Sep 2012 15:49:05 +0200 Subject: [PATCH 5/5] Change name of testsuite --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2fb1f7c..c7be983 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -12,7 +12,7 @@ bootstrap="vendor/autoload.php" > - + ./Tests