Add dump() to PhpReader.

This commit is contained in:
mark_story 2012-04-19 22:07:05 -04:00
parent c703a633bd
commit 578dac9259
2 changed files with 53 additions and 0 deletions

View file

@ -87,4 +87,15 @@ class PhpReader implements ConfigReaderInterface {
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) . ';';
}
}

View file

@ -96,4 +96,46 @@ class PhpReaderTest extends CakeTestCase {
$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);
}
}