Moved and renamed functional tests. Simplified ConfigurationTest

This commit is contained in:
l3l0 2012-09-04 15:18:10 +02:00
parent ca477696cc
commit fcde48018c
8 changed files with 152 additions and 67 deletions

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',
)
)
);
}
}

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="php-github-api Test Suite">
<directory>./Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">.</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>