Skip to content
This repository has been archived by the owner on Nov 12, 2021. It is now read-only.

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
till committed Apr 21, 2012
0 parents commit 28adf3f
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 0 deletions.
5 changes: 5 additions & 0 deletions phpunit.xml
@@ -0,0 +1,5 @@
<phpunit colors="true" debug="false" bootstrap="./tests/TestInit.php">
<testsuite name="LoadConfig">
<file>./tests/EasyBib/Core/Test/LoadConfigTest.php</file>
</testsuite>
</phpunit>
148 changes: 148 additions & 0 deletions tests/EasyBib/Core/Test/LoadConfigTest.php
@@ -0,0 +1,148 @@
<?php
/**
* EasyBib Copyright 2008-2012
*
* PHP Version 5.3
*
* @category Testing
* @package LoadConfig
* @author Till Klampaeckel <till@lagged.biz>
* @license http://www.easybib.com/company/terms Terms of Service
* @version GIT: $Id$
* @link http://www.easybib.com
* @link http://github.com/easybib/EasyBib_Core_LoadConfig
*/
namespace EasyBib\Core\Test;

use EasyBib\Core\LoadConfig;

/**
* LoadConfigTest
*
* @category Testing
* @package LoadConfig
* @author Till Klampaeckel <till@lagged.biz>
* @license http://www.easybib.com/company/terms Terms of Service
* @version Release: @package_version@
* @link http://www.easybib.com
* @link http://github.com/easybib/EasyBib_Core_LoadConfig
*/
class LoadConfigTest extends \PHPUnit_Framework_TestCase
{
/**
* To be used in tests!
* @var LoadConfig
*/
protected $ezConfig;

protected function setUp()
{
$this->ezConfig = new LoadConfig('foo');
$this->ezConfig->setEnvironment('testing');
}

protected function tearDown()
{
unset($this->ezConfig);
}

public function testRedisConf()
{
$this->assertInstanceOf('EasyBib\Core\LoadConfig', $this->ezConfig->setConfigDir('configs'));
$this->assertInstanceOf('EasyBib\Core\LoadConfig', $this->ezConfig->setFile('redis.ini'));
$this->assertInstanceOf('EasyBib\Core\LoadConfig', $this->ezConfig->setModule('bar'));
$this->assertInstanceOf('EasyBib\Core\LoadConfig', $this->ezConfig->setEnvironment('testing'));

$redisConfig = $this->ezConfig->load();
$this->assertEquals('127.0.0.1', $redisConfig->host);
$this->assertEquals('31337', $redisConfig->port);
}

/**
* @expectedException \RuntimeException
*/
public function testUnknownConfigThrowsException()
{
$config = $this->ezConfig->load();
$this->assertFalse($config);
}

/**
* Load impexport/etc/config.ini
*/
public function testModule()
{
$this->ezConfig->setFile('config.ini');
$this->ezConfig->setModule('foo');

$config = $this->ezConfig->load();

$this->assertInstanceOf('Zend_Config_Ini', $config);
}

public function testProduction()
{
if (!extension_loaded('apc')) {
$this->markTestSkipped("Test requires ext/apc.");
return;
}
$this->ezConfig->setEnvironment('production');
$this->ezConfig->setFile('config.ini');
$this->ezConfig->setModule('impexport');

$key = $this->ezConfig->getApcKey();
$this->assertNotEmpty($key);
\apc_delete($key);

$config = $this->ezConfig->load();

$this->assertInstanceOf('Zend_Config_Ini', $config);
}

/**
* Test {@link EasyBib\Core\LoadConfig::save()
*/
public function testProductionAndAlter()
{
if (!extension_loaded('apc')) {
$this->markTestSkipped("Test requires ext/apc.");
return;
}
$this->ezConfig->setEnvironment('production');
$this->ezConfig->setFile('config.ini');
$this->ezConfig->setModule('impexport');

$key = $this->ezConfig->getApcKey();
\apc_delete($key);

$config = $this->ezConfig->load();
$config->foo = 'bar';

$this->assertInstanceOf('EasyBib\Core\LoadConfig', $this->ezConfig->save($config));
}

/**
* make sure the key generated is not just based on 'filename'
*
* @return void
* @see LoadConfig::generateKey()
*/
public function testKeyGeneration()
{
$this->ezConfig->setFile('config.ini');

$key1 = $this->ezConfig->getApcKey();

$this->ezConfig->setModule('wat');

$key2 = $this->ezConfig->getApcKey();

$this->assertNotEquals($key1, $key2);

$this->ezConfig->setModule('default');

$key3 = $this->ezConfig->getApcKey();

$this->assertEquals($key1, $key3);
}
}
13 changes: 13 additions & 0 deletions tests/TestInit.php
@@ -0,0 +1,13 @@
<?php
$autoloader = dirname(__DIR__) . '/vendor/autoload.php';
if (!file_exists($autoloader)) {
echo "Please run 'php composer.phar install'" . PHP_EOL;
exit(1);
}
require_once $autoloader;
require_once 'PHPUnit/Autoload.php';

/**
* @desc Define APPLICATION_PATH and point to fixtures!
*/
define('APPLICATION_PATH', __DIR__ . '/fixtures/app');
8 changes: 8 additions & 0 deletions tests/fixtures/app/modules/bar/configs/redis.ini
@@ -0,0 +1,8 @@
[production]

host = 127.0.0.1
port = 6379

[testing : production]

port = 31337
4 changes: 4 additions & 0 deletions tests/fixtures/app/modules/foo/etc/config.ini
@@ -0,0 +1,4 @@
[production]
module = foo

[testing : production]

0 comments on commit 28adf3f

Please sign in to comment.