From fcde48018cb72038df338959bf708157ac6afda3 Mon Sep 17 00:00:00 2001 From: l3l0 Date: Tue, 4 Sep 2012 15:18:10 +0200 Subject: [PATCH] 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 + + + +