This repository has been archived by the owner on Nov 12, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 28adf3f
Showing
5 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[production] | ||
|
||
host = 127.0.0.1 | ||
port = 6379 | ||
|
||
[testing : production] | ||
|
||
port = 31337 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[production] | ||
module = foo | ||
|
||
[testing : production] |