Skip to content

Commit

Permalink
Extended unit tests of factory
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreda committed Mar 22, 2016
1 parent 13957d5 commit f597f6d
Showing 1 changed file with 104 additions and 6 deletions.
110 changes: 104 additions & 6 deletions tests/FactoryTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class FactoryTests extends PHPUnit_Framework_TestCase
protected $adapterType = 'Filesystem';

/**
* Returns a valid configuration with a single cache adapter using Filesystem
* Returns valid configuration(s).
*
* @return array
*/
protected function getValidSingleAdapterConfig()
public function validConfigurationDataProvider()
{
return array(
$config1 = array(
Config::INDEX_CACHE => array(
Config::INDEX_ADAPTER => array(
$this->adapterName => array(
Expand All @@ -27,19 +27,117 @@ protected function getValidSingleAdapterConfig()
)
)
);

return array(array($config1));
}

/**
* Returns invalid configuration(s).
*
* @return array
*/
public function invalidConfigurationDataProvider()
{
$config1 = array(
Config::INDEX_CACHE => array(
Config::INDEX_ADAPTER => array(
$this->adapterName => array(
'typo' => $this->adapterType,
)
)
)
);
$config2 = array(
Config::INDEX_CACHE => array(
'adaptor' => array(
$this->adapterName => array(
Config::INDEX_TYPE => $this->adapterType,
)
)
)
);
$config3 = array(
'Cahce' => array(
Config::INDEX_ADAPTER => array(
$this->adapterName => array(
Config::INDEX_TYPE => $this->adapterType,
)
)
)
);

return array(
array($config1),
array($config2),
array($config3),
);
}

/**
* Tests that the factory can create a proper PSR-6 compatible Cache Pool based on valid configuration
* Tests that the factory can create a proper PSR-6 compatible Cache Pool based on valid configuration.
*
* @param array $config Adapter configuration
*
* @dataProvider validConfigurationDataProvider
*/
public function testFactoryWithConfigAndSingleFilesystemAdapter()
public function testThatFactoryWorksWithValidConfig(array $config)
{
$cachePoolFactory = new Factory();

$cachePoolFactory->setConfig($this->getValidSingleAdapterConfig());
$cachePoolFactory->setConfig($config);

$cachePool = $cachePoolFactory->make($this->adapterName);

$this->assertInstanceOf('Psr\\Cache\\CacheItemPoolInterface', $cachePool);
}

/**
* Tests that the factory exception when no config array and no config file are set in the factory.
*
* @expectedException RuntimeException
*/
public function testThatFactoryThrowsExceptionWhenNoConfigAndNoConfigFileAreSet()
{
$cachePoolFactory = new Factory();

$cachePoolFactory->make($this->adapterName);
}

/**
* Tests that the factory throws exception when the configuration is invalid.
*
* @param array $config Adapter configuration
*
* @dataProvider invalidConfigurationDataProvider
*
* @expectedException RuntimeException
* @expectedExceptionMessage Invalid configuration
*/
public function testThatFactoryThrowsExceptionWithInvalidConfig(array $config)
{
$cachePoolFactory = new Factory();

$cachePoolFactory->setConfig($config);
$cachePoolFactory->make($this->adapterName);
}

/**
* Tests that the factory throws exception when the adapter specified by the 'type' index is not implemented.
*
* @param array $config Adapter configuration
*
* @dataProvider validConfigurationDataProvider
*
* @expectedException RuntimeException
* @expectedExceptionMessage There is no cache pool factory implementation for the adapter "local"
*/
public function testThatFactoryThrowsExceptionWhenAdapterDoesNotExist(array $config)
{
$config[Config::INDEX_CACHE][Config::INDEX_ADAPTER][$this->adapterName][Config::INDEX_TYPE] = 'local';

$cachePoolFactory = new Factory();

$cachePoolFactory->setConfig($config);
$cachePoolFactory->make($this->adapterName);
}
}

0 comments on commit f597f6d

Please sign in to comment.