diff --git a/src/FormatterManager.php b/src/FormatterManager.php index 19a8125..f4d9336 100644 --- a/src/FormatterManager.php +++ b/src/FormatterManager.php @@ -18,6 +18,7 @@ public function __construct() 'yaml' => '\Consolidation\OutputFormatters\Formatters\YamlFormatter', 'json' => '\Consolidation\OutputFormatters\Formatters\JsonFormatter', 'print-r' => '\Consolidation\OutputFormatters\Formatters\PrintRFormatter', + 'php' => '\Consolidation\OutputFormatters\Formatters\SerializeFormatter', 'var_export' => '\Consolidation\OutputFormatters\Formatters\VarExportFormatter', 'list' => '\Consolidation\OutputFormatters\Formatters\ListFormatter', 'csv' => '\Consolidation\OutputFormatters\Formatters\CsvFormatter', diff --git a/src/Formatters/SerializeFormatter.php b/src/Formatters/SerializeFormatter.php new file mode 100644 index 0000000..8fa922b --- /dev/null +++ b/src/Formatters/SerializeFormatter.php @@ -0,0 +1,16 @@ +writeln(serialize($data)); + } +} diff --git a/tests/testFormatters.php b/tests/testFormatters.php index 2d6701f..0b43782 100644 --- a/tests/testFormatters.php +++ b/tests/testFormatters.php @@ -95,6 +95,19 @@ function testSimpleJson() $this->assertFormattedOutputMatches($expected, 'json', $data); } + function testSerializeFormat() + { + $data = [ + 'one' => 'a', + 'two' => 'b', + 'three' => 'c', + ]; + + $expected = 'a:3:{s:3:"one";s:1:"a";s:3:"two";s:1:"b";s:5:"three";s:1:"c";}'; + + $this->assertFormattedOutputMatches($expected, 'php', $data); + } + function testNestedJson() { $data = [