Skip to content

Commit b65da0c

Browse files
Merge pull request #324 from hype09
Fix debug-flag in configuration files (#323)
2 parents c620715 + 00919f7 commit b65da0c

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

phpbu.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
<xs:attribute name="bootstrap" type="xs:anyURI"/>
123123
<xs:attribute name="verbose" type="xs:boolean" default="false"/>
124124
<xs:attribute name="colors" type="xs:boolean" default="false"/>
125+
<xs:attribute name="debug" type="xs:boolean" default="false"/>
125126
</xs:attributeGroup>
126127

127128
<xs:group name="configGroup">

src/Configuration/Loader/Json.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ public function setAppSettings(Configuration $configuration)
121121
if (isset($this->json['colors'])) {
122122
$configuration->setColors($this->json['colors']);
123123
}
124+
if (isset($this->json['debug'])) {
125+
$configuration->setDebug($this->json['debug']);
126+
}
124127
}
125128

126129
/**

src/Configuration/Loader/Xml.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ public function setAppSettings(Configuration $configuration)
139139
if ($root->hasAttribute('colors')) {
140140
$configuration->setColors(Str::toBoolean($root->getAttribute('colors'), false));
141141
}
142+
if ($root->hasAttribute('debug')) {
143+
$configuration->setDebug(Str::toBoolean($root->getAttribute('debug'), false));
144+
}
142145
}
143146

144147
/**
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"debug": true,
3+
"backups": [
4+
{
5+
"name": "tarball",
6+
"source": {
7+
"type": "tar",
8+
"options": {
9+
"path": "src"
10+
}
11+
},
12+
"target": {
13+
"dirname": "backup/src",
14+
"filename": "tarball-%Y%m%d-%H%i.tar",
15+
"compress": "bzip2"
16+
}
17+
}
18+
]
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpbu bootstrap="backup/bootstrap.php" debug="true">
3+
<backups>
4+
<backup name="tarball">
5+
<source type="tar">
6+
<option name="path" value="src"/>
7+
</source>
8+
<target dirname="backup/src" filename="tarball-%Y%m%d-%H%i.tar" compress="bzip2"/>
9+
</backup>
10+
</backups>
11+
</phpbu>

tests/phpbu/Configuration/Loader/JsonTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ public function testFileNoSyncType()
139139
$config = $loader->getConfiguration(self::$factory);
140140
}
141141

142+
public function testWithDebug(): void
143+
{
144+
$loader = new Json(PHPBU_TEST_FILES . '/conf/json/config-with-debug.json', $this->getBootstrapperMock(true));
145+
$config = $loader->getConfiguration(self::$factory);
146+
$this->assertTrue($config->getDebug());
147+
}
148+
142149
/**
143150
* Tests Json::getConfiguration
144151
*/
@@ -152,6 +159,7 @@ public function testAppSettings()
152159
$this->assertEquals($dir . '/backup/bootstrap.php', $config->getBootstrap());
153160
$this->assertTrue($config->getColors());
154161
$this->assertFalse($config->getVerbose());
162+
$this->assertFalse($config->getDebug());
155163
}
156164

157165
/**

tests/phpbu/Configuration/Loader/XmlTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ public function testCustomAdapter()
146146
$this->assertEquals('demo', $source->options['password']);
147147
}
148148

149+
public function testWithDebug(): void
150+
{
151+
$loader = new Xml(PHPBU_TEST_FILES . '/conf/xml/config-with-debug.xml', $this->getBootstrapperMock(true));
152+
$config = $loader->getConfiguration(self::$factory);
153+
154+
$this->assertFalse($loader->hasValidationErrors());
155+
$this->assertTrue($config->getDebug());
156+
}
157+
149158
/**
150159
* Tests Xml::getConfiguration
151160
*/
@@ -161,6 +170,7 @@ public function testAppSettings()
161170
$this->assertEquals($dir . '/backup/bootstrap.php', $config->getBootstrap());
162171
$this->assertTrue($config->getColors());
163172
$this->assertFalse($config->getVerbose());
173+
$this->assertFalse($config->getDebug());
164174
}
165175

166176
/**

0 commit comments

Comments
 (0)