Skip to content

Commit

Permalink
Require PHP 5.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CloCkWeRX committed Dec 30, 2011
1 parent e003511 commit 019ebbc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.xml
Expand Up @@ -68,7 +68,7 @@ Currently classes available are:
<dependencies>
<required>
<php>
<min>5.2.0</min>
<min>5.3.0</min>
</php>
<pearinstaller>
<min>1.4.0b1</min>
Expand Down
59 changes: 31 additions & 28 deletions tests/Config_LiteTest.php
Expand Up @@ -24,11 +24,11 @@

/**
* Test class for Config_Lite.
*
*
* PHPUnit 3.3.17 by Sebastian Bergmann.
* The first Tests relies on test.cfg,
* followd by tests on a temporary file.
*
*
* Usage: phpunit AllTests.php
*
* @category Config
Expand All @@ -48,7 +48,7 @@ class Config_LiteTest extends PHPUnit_Framework_TestCase
protected $object;
/**
* temporary filename
*
*
* @access protected
*/
protected $filename;
Expand All @@ -65,9 +65,9 @@ protected function setUp()
$this->config->read(dirname(__FILE__).'/test.cfg');
$this->filename = tempnam(sys_get_temp_dir(), __CLASS__);
if (!is_writable($this->filename)) {
printf('Warning: temporary file not writeable: %s.'."\n",
printf('Warning: temporary file not writeable: %s.'."\n",
$this->filename
);
);
}
}

Expand Down Expand Up @@ -106,21 +106,21 @@ public function testGetDefaultByNonExistingSection()
$counter = $this->config->get('foo', 'nonexisting_counter_option', 3);
$this->assertEquals(3, $counter);
}

public function testGetGlobalOption()
{
$this->config->read(dirname(__FILE__).'/test.cfg');
$this->assertEquals('test.cfg', $this->config['filename']);
// global values with null
$this->assertEquals('test.cfg', $this->config->get(null, 'filename'));
}

public function testGetBoolGlobalOption()
{
$this->config->read(dirname(__FILE__).'/test.cfg');
$this->assertEquals(TRUE, $this->config->getBool(null, 'debug', false));
}

public function testWrite()
{
$assoc_array = array(
Expand All @@ -147,7 +147,7 @@ public function testSave()
$this->config->read($this->filename);
$this->assertEquals(2, $this->config->get('counter', 'count'));
}

public function testSetIndexedArrayWithSet()
{
$this->config->setFilename($this->filename);
Expand All @@ -157,9 +157,9 @@ public function testSetIndexedArrayWithSet()
$this->config->sync();
$this->assertEquals(array('12/09', '12/10', '11/07'), $this->config->get('test array', 'tries'));
}

public function testArrayAccess()
{
{
$this->config->setFilename($this->filename);
$this->config->read();
$this->config['server'] = array('basepath' => '/var/www');
Expand All @@ -177,7 +177,7 @@ public function testSet()
$this->config->set('users', 'name', 'John Doe')
->set('users', 'email', 'john@doe.com');
$this->assertEquals(array('name'=>'John Doe','email'=>'john@doe.com'), $this->config->getSection('users'));
// expected to raise an Invalid Argument exception,
// expected to raise an Invalid Argument exception,
// if Section is Array
try {
$this->config->set(array('counter' => 'count'), 1);
Expand All @@ -186,7 +186,7 @@ public function testSet()
return;
}
$this->fail('An Config_Lite_Exception expected, due to an invalid Argument. Exception has not been raised.');
// if Key is Array
// if Key is Array
try {
$this->config->set('section', array('count' => 1));
}
Expand All @@ -197,7 +197,7 @@ public function testSet()
}

public function testSetSection()
{
{
$this->config->setSection('users', array('email'=> 'john@doe.com','name'=> 'John Doe'));
$this->assertEquals(array('name'=>'John Doe','email'=>'john@doe.com'), $this->config->getSection('users'));
}
Expand All @@ -208,7 +208,7 @@ public function testGetSection()
->set('users', 'email', 'john@doe.com');
$this->assertEquals(array('name'=>'John Doe','email'=>'john@doe.com'), $this->config->getSection('users'));
}

public function testGetBool()
{
// test human readable representation
Expand All @@ -220,7 +220,7 @@ public function testGetBool()
$this->assertEquals(FALSE, $this->config->getBool('general', 'stable'));
$this->config->set('general', 'stable', 0);
$this->assertEquals(FALSE, $this->config->getBool('general', 'stable'));

$this->config->set('general', 'stable', 'Yes');
$this->assertEquals(TRUE, $this->config->getBool('general', 'stable'));
$this->config->set('general', 'stable', 'On');
Expand All @@ -243,29 +243,29 @@ public function testSetArrayAsKeyWithSet()
}
$this->fail('An expected exception has not been raised.');
}

public function testSingleQuotedEscapedInput()
{
$this->config->setFilename($this->filename);
$this->config->setString('quoted', 'single', '/(; "-"s[^\\\'"\\\']d//m\\\'"\'');
$this->config->sync();
$this->assertEquals('/(; "-"s[^\\\'"\\\']d//m\\\'"\'',
$this->assertEquals('/(; "-"s[^\\\'"\\\']d//m\\\'"\'',
$this->config->getString('quoted', 'single')
);
}

public function testDoubleQuotedEscapedInput()
{
$this->config->setFilename($this->filename);
$this->config->setString('quoted', 'double', "/(; \"-\"s[^\'\"\']d//m\'\"'");
$this->config->sync();
$this->assertEquals("/(; \"-\"s[^\'\"\']d//m\'\"'",
$this->assertEquals("/(; \"-\"s[^\'\"\']d//m\'\"'",
$this->config->getString('quoted', 'double')
);
$this->config->removeSection('quoted');
$this->config->sync();
}

public function testSetNumericOptionWithSet()
{
$this->config->set('counter', 'count', 1);
Expand All @@ -285,7 +285,7 @@ public function testSetBoolWithSet()
$this->config->sync();
$this->assertEquals(1, $this->config->get('counter', 'has_counter'));
}

public function testHasOption()
{
$this->config->set('counter', 'count', 1);
Expand All @@ -296,7 +296,7 @@ public function testHasSection()
{
$this->assertEquals(TRUE, $this->config->hasSection('general'));
}

public function testRemove()
{
$this->config->set('general', 'stable', 'Yes');
Expand All @@ -312,20 +312,23 @@ public function testHas()
$this->config->remove('general', 'a_section');
$this->assertEquals(FALSE, $this->config->has('general', 'a_section'));
}

public function testRemoveSection()
{
$this->config->removeSection('counter');
$this->assertEquals(FALSE, $this->config->hasSection('counter'));
}

/**
* to test protected methods
* to test protected methods
*/
protected static function getMethod($name)
protected static function getMethod($name)
{
$class = new ReflectionClass('Config_Lite');
$method = $class->getMethod($name);
if (!method_exists($class, 'setAccessible')) {
$this->markTestSkipped("This test requires PHP 5.3.0+");
}
$method->setAccessible(true);
return $method;
}
Expand All @@ -334,7 +337,7 @@ public function testNormalizeValue()
{
$m = self::getMethod('normalizeValue');
$obj = new Config_Lite();

$b = $m->invokeArgs($obj, array(true));
$this->assertEquals('yes', $b);

Expand Down Expand Up @@ -367,7 +370,7 @@ public function testDoNotProcessSectionsGet()
$counter = $this->config->get(null, 'nonexisting_counter_option', 3);
$this->assertEquals(3, $counter);
}

public function testDoNotDoubleQuoteWrite()
{
$this->config->setQuoteStrings(false)->read($this->filename);
Expand Down

0 comments on commit 019ebbc

Please sign in to comment.