Skip to content

Commit

Permalink
Add dump() to PhpReader.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed May 2, 2012
1 parent c703a63 commit 578dac9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Cake/Configure/PhpReader.php
Expand Up @@ -87,4 +87,15 @@ public function read($key) {
return $config;
}

/**
* Converts the provided $data into a string of PHP code that can
* be used saved into a file and loaded later.
*
* @param array $data Data to dump.
* @return string String or PHP code.
*/
public function dump($data) {
return '<?php' . "\n" . '$config = ' . var_export($data, true) . ';';
}

}
42 changes: 42 additions & 0 deletions lib/Cake/Test/Case/Configure/PhpReaderTest.php
Expand Up @@ -96,4 +96,46 @@ public function testReadPluginValue() {
$this->assertTrue(isset($result['plugin_load']));
CakePlugin::unload();
}

/**
* Test dumping data to PHP format.
*
* @return void
*/
public function testDump() {
$reader = new PhpReader($this->path);
$data = array(
'One' => array(
'two' => 'value',
'three' => array(
'four' => 'value four'
),
'null' => null
),
'Asset' => array(
'timestamp' => 'force'
),
);
$result = $reader->dump($data);
$expected = <<<PHP
<?php
\$config = array (
'One' =>
array (
'two' => 'value',
'three' =>
array (
'four' => 'value four',
),
'null' => NULL,
),
'Asset' =>
array (
'timestamp' => 'force',
),
);
PHP;
$this->assertEquals($expected, $result);
}

}

0 comments on commit 578dac9

Please sign in to comment.