mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Add dump() to PhpReader.
This commit is contained in:
parent
c703a633bd
commit
578dac9259
2 changed files with 53 additions and 0 deletions
|
@ -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) . ';';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue