Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://git.zendframework.com/zf
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahar Evron committed Jul 25, 2010
3 parents 88ec12d + 8f4a51f + 17cbc64 commit 31ab35e
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 31 deletions.
32 changes: 31 additions & 1 deletion src/Writer/Ini.php
Expand Up @@ -96,7 +96,8 @@ public function render()
. $this->_addBranch($this->_config)
. "\n";
} else {
foreach ($this->_config as $sectionName => $data) {
$config = $this->_sortRootElements($this->_config);
foreach ($config as $sectionName => $data) {
if (!($data instanceof Config\Config)) {
$iniString .= $sectionName
. ' = '
Expand Down Expand Up @@ -161,4 +162,33 @@ protected function _prepareValue($value)
throw new Config\Exception('Value can not contain double quotes "');
}
}

/**
* Root elements that are not assigned to any section needs to be
* on the top of config.
*
* @see http://framework.zend.com/issues/browse/ZF-6289
* @param Zend_Config
* @return Zend_Config
*/
protected function _sortRootElements(Zend_Config $config)
{
$configArray = $config->toArray();
$sections = array();

// remove sections from config array
foreach ($configArray as $key => $value) {
if (is_array($value)) {
$sections[$key] = $value;
unset($configArray[$key]);
}
}

// readd sections to the end
foreach ($sections as $key => $value) {
$configArray[$key] = $value;
}

return new Zend_Config($configArray);
}
}
24 changes: 12 additions & 12 deletions test/IniTest.php
Expand Up @@ -40,14 +40,14 @@ class IniTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->_iniFileConfig = dirname(__FILE__) . '/_files/config.ini';
$this->_iniFileAllSectionsConfig = dirname(__FILE__) . '/_files/allsections.ini';
$this->_iniFileCircularConfig = dirname(__FILE__) . '/_files/circular.ini';
$this->_iniFileMultipleInheritanceConfig = dirname(__FILE__) . '/_files/multipleinheritance.ini';
$this->_iniFileSeparatorConfig = dirname(__FILE__) . '/_files/separator.ini';
$this->_nonReadableConfig = dirname(__FILE__) . '/_files/nonreadable.ini';
$this->_iniFileNoSectionsConfig = dirname(__FILE__) . '/_files/nosections.ini';
$this->_iniFileInvalid = dirname(__FILE__) . '/_files/invalid.ini';
$this->_iniFileConfig = __DIR__ . '/_files/config.ini';
$this->_iniFileAllSectionsConfig = __DIR__ . '/_files/allsections.ini';
$this->_iniFileCircularConfig = __DIR__ . '/_files/circular.ini';
$this->_iniFileMultipleInheritanceConfig = __DIR__ . '/_files/multipleinheritance.ini';
$this->_iniFileSeparatorConfig = __DIR__ . '/_files/separator.ini';
$this->_nonReadableConfig = __DIR__ . '/_files/nonreadable.ini';
$this->_iniFileNoSectionsConfig = __DIR__ . '/_files/nosections.ini';
$this->_iniFileInvalid = __DIR__ . '/_files/invalid.ini';
}

public function testLoadSingleSection()
Expand Down Expand Up @@ -205,7 +205,7 @@ public function testZF2508NoSections()

public function testZF2843NoSectionNoTree()
{
$filename = dirname(__FILE__) . '/_files/zf2843.ini';
$filename = __DIR__ . '/_files/zf2843.ini';
$config = new Ini($filename, null, array('nestSeparator' => '.'));

$this->assertEquals('123', $config->abc);
Expand All @@ -229,7 +229,7 @@ public function testZF3196_InvalidIniFile()
public function testZF8159()
{
$config = new Ini(
dirname(__FILE__) . '/_files/zf8159.ini',
__DIR__ . '/_files/zf8159.ini',
array('first', 'second')
);

Expand All @@ -249,7 +249,7 @@ public function testZF8159()
*/
public function testArraysOfKeysCreatedUsingAttributesAndKeys()
{
$filename = dirname(__FILE__) . '/_files/zf5800.ini';
$filename = __DIR__ . '/_files/zf5800.ini';
$config = new Ini($filename, 'dev');
$this->assertEquals('nice.guy@company.com', $config->receiver->{0}->mail);
$this->assertEquals('1', $config->receiver->{0}->html);
Expand All @@ -261,7 +261,7 @@ public function testArraysOfKeysCreatedUsingAttributesAndKeys()
*/
public function testPreservationOfIntegerKeys()
{
$filename = dirname(__FILE__) . '/_files/zf6508.ini';
$filename = __DIR__ . '/_files/zf6508.ini';
$config = new Ini($filename, 'all');
$this->assertEquals(true, isset($config->{1002}));

Expand Down
2 changes: 1 addition & 1 deletion test/Writer/ArrayWriterTest.php
Expand Up @@ -39,7 +39,7 @@ class ArrayWriterTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->_tempName = tempnam(dirname(__FILE__) . '/temp', 'tmp');
$this->_tempName = tempnam(__DIR__ . '/temp', 'tmp');
}

public function tearDown()
Expand Down
43 changes: 39 additions & 4 deletions test/Writer/IniTest.php
Expand Up @@ -40,7 +40,7 @@ class IniTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->_tempName = tempnam(dirname(__FILE__) . '/temp', 'tmp');
$this->_tempName = tempnam(__DIR__ . '/temp', 'tmp');
}

public function tearDown()
Expand Down Expand Up @@ -97,7 +97,7 @@ public function testNoSection()

public function testWriteAndReadOriginalFile()
{
$config = new IniConfig(dirname(__FILE__) . '/files/allsections.ini', null, array('skipExtends' => true));
$config = new IniConfig(__DIR__ . '/files/allsections.ini', null, array('skipExtends' => true));

$writer = new Ini(array('config' => $config, 'filename' => $this->_tempName));
$writer->write();
Expand All @@ -112,7 +112,7 @@ public function testWriteAndReadOriginalFile()

public function testWriteAndReadSingleSection()
{
$config = new IniConfig(dirname(__FILE__) . '/files/allsections.ini', 'staging', array('skipExtends' => true));
$config = new IniConfig(__DIR__ . '/files/allsections.ini', 'staging', array('skipExtends' => true));

$writer = new Ini(array('config' => $config, 'filename' => $this->_tempName));
$writer->write();
Expand Down Expand Up @@ -175,7 +175,7 @@ public function testRenderWithoutSections()

public function testRenderWithoutSections2()
{
$config = new IniConfig(dirname(__FILE__) . '/files/allsections.ini', null, array('skipExtends' => true));
$config = new IniConfig(__DIR__ . '/files/allsections.ini', null, array('skipExtends' => true));

$writer = new Ini();
$writer->setRenderWithoutSections();
Expand Down Expand Up @@ -217,4 +217,39 @@ public function testNoDoubleQuoutesInValue()
$writer = new Ini(array('config' => $config, 'filename' => $this->_tempName));
$writer->write();
}

/**
* @group ZF-6289
*/
public function testZF6289_NonSectionElementsAndSectionJumbling()
{
$config = new Zend_Config(array(
'one' => 'element',
'two' => array('type' => 'section'),
'three' => 'element',
'four' => array('type' => 'section'),
'five' => 'element'
));

$writer = new Zend_Config_Writer_Ini;
$iniString = $writer->setConfig($config)->render($config);

$expected = <<<ECS
one = "element"
three = "element"
five = "element"
[two]
type = "section"
[four]
type = "section"
ECS;

$this->assertEquals(
$expected,
$iniString
);
}
}
6 changes: 3 additions & 3 deletions test/Writer/XmlTest.php
Expand Up @@ -40,7 +40,7 @@ class XmlTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->_tempName = tempnam(dirname(__FILE__) . '/temp', 'tmp');
$this->_tempName = tempnam(__DIR__ . '/temp', 'tmp');
}

public function tearDown()
Expand Down Expand Up @@ -99,7 +99,7 @@ public function testNoSection()

public function testWriteAndReadOriginalFile()
{
$config = new XmlConfig(dirname(__FILE__) . '/files/allsections.xml', null, array('skipExtends' => true));
$config = new XmlConfig(__DIR__ . '/files/allsections.xml', null, array('skipExtends' => true));

$writer = new Xml(array('config' => $config, 'filename' => $this->_tempName));
$writer->write();
Expand All @@ -113,7 +113,7 @@ public function testWriteAndReadOriginalFile()

public function testWriteAndReadSingleSection()
{
$config = new XmlConfig(dirname(__FILE__) . '/files/allsections.xml', 'staging', array('skipExtends' => true));
$config = new XmlConfig(__DIR__ . '/files/allsections.xml', 'staging', array('skipExtends' => true));

$writer = new Xml(array('config' => $config, 'filename' => $this->_tempName));
$writer->write();
Expand Down
20 changes: 10 additions & 10 deletions test/XmlTest.php
Expand Up @@ -41,16 +41,16 @@ class XmlTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->_xmlFileConfig = dirname(__FILE__) . '/_files/config.xml';
$this->_xmlFileAllSectionsConfig = dirname(__FILE__) . '/_files/allsections.xml';
$this->_xmlFileCircularConfig = dirname(__FILE__) . '/_files/circular.xml';
$this->_xmlFileTopLevelStringConfig = dirname(__FILE__) . '/_files/toplevelstring.xml';
$this->_xmlFileOneTopLevelStringConfig = dirname(__FILE__) . '/_files/onetoplevelstring.xml';
$this->_nonReadableConfig = dirname(__FILE__) . '/_files/nonreadable.xml';
$this->_xmlFileSameNameKeysConfig = dirname(__FILE__) . '/_files/array.xml';
$this->_xmlFileShortParamsOneConfig = dirname(__FILE__) . '/_files/shortparamsone.xml';
$this->_xmlFileShortParamsTwoConfig = dirname(__FILE__) . '/_files/shortparamstwo.xml';
$this->_xmlFileInvalid = dirname(__FILE__) . '/_files/invalid.xml';
$this->_xmlFileConfig = __DIR__ . '/_files/config.xml';
$this->_xmlFileAllSectionsConfig = __DIR__ . '/_files/allsections.xml';
$this->_xmlFileCircularConfig = __DIR__ . '/_files/circular.xml';
$this->_xmlFileTopLevelStringConfig = __DIR__ . '/_files/toplevelstring.xml';
$this->_xmlFileOneTopLevelStringConfig = __DIR__ . '/_files/onetoplevelstring.xml';
$this->_nonReadableConfig = __DIR__ . '/_files/nonreadable.xml';
$this->_xmlFileSameNameKeysConfig = __DIR__ . '/_files/array.xml';
$this->_xmlFileShortParamsOneConfig = __DIR__ . '/_files/shortparamsone.xml';
$this->_xmlFileShortParamsTwoConfig = __DIR__ . '/_files/shortparamstwo.xml';
$this->_xmlFileInvalid = __DIR__ . '/_files/invalid.xml';
}

public function testLoadSingleSection()
Expand Down

0 comments on commit 31ab35e

Please sign in to comment.