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://github.com/zendframework/zf2 into zf11884
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Yaml.php
Expand Up @@ -278,6 +278,7 @@ protected static function _decodeYaml($currentIndent, &$lines)
$inIndent = false;
while (list($n, $line) = each($lines)) {
$lineno = $n + 1;
$line = rtrim(preg_replace("/#.*$/", "", $line));
if (strlen($line) == 0) {
continue;
}
Expand Down Expand Up @@ -308,7 +309,7 @@ protected static function _decodeYaml($currentIndent, &$lines)
// key: value
if (strlen($m[2])) {
// simple key: value
$value = $m[2];
$value = rtrim(preg_replace("/#.*$/", "", $m[2]));
// Check for booleans and constants
if (preg_match('/^(t(rue)?|on|y(es)?)$/i', $value)) {
$value = true;
Expand All @@ -330,7 +331,15 @@ protected static function _decodeYaml($currentIndent, &$lines)
// item in the list:
// - FOO
if (strlen($line) > 2) {
$config[] = substr($line, 2);
$value = substr($line, 2);
if (preg_match('/^(t(rue)?|on|y(es)?)$/i', $value)) {
$value = true;
} elseif (preg_match('/^(f(alse)?|off|n(o)?)$/i', $value)) {
$value = false;
} elseif (!self::$_ignoreConstants) {
$value = self::_replaceConstants($value);
}
$config[] = $value;
} else {
$config[] = self::_decodeYaml($currentIndent + 1, $lines);
}
Expand Down
80 changes: 80 additions & 0 deletions test/YamlTest.php
Expand Up @@ -46,6 +46,11 @@ public function setUp()
$this->_badIndentationConfig = __DIR__ . '/_files/badindentation.yaml';
$this->_booleansConfig = __DIR__ . '/_files/booleans.yaml';
$this->_constantsConfig = __DIR__ . '/_files/constants.yaml';
$this->_yamlInlineCommentsConfig = dirname(__FILE__) . '/_files/inlinecomments.yaml';
$this->_yamlIndentedCommentsConfig = dirname(__FILE__) . '/_files/indentedcomments.yaml';
$this->_yamlListConstantsConfig = dirname(__FILE__) . '/_files/listconstants.yaml';
$this->_listBooleansConfig = dirname(__FILE__) . '/_files/listbooleans.yaml';

}

public function testLoadSingleSection()
Expand Down Expand Up @@ -337,4 +342,79 @@ public function testAllowsIgnoringConstantStrings()
$this->assertEquals('ZEND_CONFIG_YAML_ENV', $config->env);
$this->assertEquals('ZEND_CONFIG_YAML_ENV_PATH/test/this', $config->path);
}

/**
* @group ZF-11329
*/
public function testAllowsInlineCommentsInValuesUsingHash()
{
$config = new YamlConfig($this->_yamlInlineCommentsConfig, null);
$this->assertSame(
'APPLICATION_PATH/controllers',
$config->resources->frontController->controllerDirectory
);
}

/**
* @group ZF-11384
*/
public function testAllowsIndentedCommentsUsingHash()
{
$config = new YamlConfig($this->_yamlIndentedCommentsConfig, null);
$this->assertSame(
'APPLICATION_PATH/controllers',
$config->resources->frontController->controllerDirectory
);
}

/**
* @group ZF-11702
*/
public function testAllowsConstantsInLists()
{
if (!defined('ZEND_CONFIG_YAML_TEST_PATH')) {
define('ZEND_CONFIG_YAML_TEST_PATH', 'testing');
}
$config = new YamlConfig($this->_yamlListConstantsConfig, 'production');

$this->assertEquals(ZEND_CONFIG_YAML_TEST_PATH, $config->paths->{0});
$this->assertEquals(ZEND_CONFIG_YAML_TEST_PATH . '/library/test', $config->paths->{1});
}

/**
* @group ZF-11702
*/
public function testAllowsBooleansInLists()
{
$config = new YamlConfig($this->_listBooleansConfig, 'production');

$this->assertTrue($config->usingLowerCasedYes->{0});
$this->assertTrue($config->usingTitleCasedYes->{0});
$this->assertTrue($config->usingCapitalYes->{0});
$this->assertTrue($config->usingLowerY->{0});
$this->assertTrue($config->usingUpperY->{0});

$this->assertFalse($config->usingLowerCasedNo->{0});
$this->assertFalse($config->usingTitleCasedNo->{0});
$this->assertFalse($config->usingCapitalNo->{0});
$this->assertFalse($config->usingLowerN->{0});
$this->assertFalse($config->usingUpperN->{0});

$this->assertTrue($config->usingLowerCasedTrue->{0});
$this->assertTrue($config->usingTitleCasedTrue->{0});
$this->assertTrue($config->usingCapitalTrue->{0});

$this->assertFalse($config->usingLowerCasedFalse->{0});
$this->assertFalse($config->usingTitleCasedFalse->{0});
$this->assertFalse($config->usingCapitalFalse->{0});

$this->assertTrue($config->usingLowerCasedOn->{0});
$this->assertTrue($config->usingTitleCasedOn->{0});
$this->assertTrue($config->usingCapitalOn->{0});

$this->assertFalse($config->usingLowerCasedOff->{0});
$this->assertFalse($config->usingTitleCasedOff->{0});
$this->assertFalse($config->usingCapitalOff->{0});
}

}
4 changes: 4 additions & 0 deletions test/_files/indentedcomments.yaml
@@ -0,0 +1,4 @@
resources:
#frontcontroller!
frontController:
controllerDirectory: APPLICATION_PATH/controllers
3 changes: 3 additions & 0 deletions test/_files/inlinecomments.yaml
@@ -0,0 +1,3 @@
resources:
frontController:
controllerDirectory: APPLICATION_PATH/controllers #heynow!
51 changes: 51 additions & 0 deletions test/_files/listbooleans.yaml
@@ -0,0 +1,51 @@
production:
usingLowerCasedYes:
- yes
usingTitleCasedYes:
- Yes
usingCapitalYes:
- YES
usingLowerY:
- y
usingUpperY:
- Y

usingLowerCasedNo:
- no
usingTitleCasedNo:
- No
usingCapitalNo:
- NO
usingLowerN:
- n
usingUpperN:
- N

usingLowerCasedTrue:
- true
usingTitleCasedTrue:
- True
usingCapitalTrue:
- TRUE

usingLowerCasedFalse:
- false
usingTitleCasedFalse:
- False
usingCapitalFalse:
- FALSE

usingLowerCasedOn:
- on
usingTitleCasedOn:
- On
usingCapitalOn:
- ON

usingLowerCasedOff:
- off
usingTitleCasedOff:
- Off
usingCapitalOff:
- OFF

4 changes: 4 additions & 0 deletions test/_files/listconstants.yaml
@@ -0,0 +1,4 @@
production:
paths:
- ZEND_CONFIG_YAML_TEST_PATH
- ZEND_CONFIG_YAML_TEST_PATH/library/test

0 comments on commit e7aa329

Please sign in to comment.