Page MenuHomeDevCentral

D2527.id6379.diff
No OneTemporary

D2527.id6379.diff

diff --git a/src/Output/XMLOutput.php b/src/Output/XMLOutput.php
new file mode 100644
--- /dev/null
+++ b/src/Output/XMLOutput.php
@@ -0,0 +1,57 @@
+<?php
+
+
+namespace Keruald\Reporting\Output;
+
+
+class XMLOutput extends Output {
+
+ public function render () : string {
+ $report = $this->report;
+ $send = [];
+ $send[] = '<?xml version="1.0" encoding="UTF-8" ?>';
+ $send[] = '<report>';
+ $send[] = str_repeat(" ", 4) .
+ '<title>' . $report->title . '</title>';
+
+ foreach ($report->sections as $key => $section) {
+ $send[] = str_repeat(" ", 4) .
+ '<section title="' . $section->title . '">';
+
+ foreach ($section->entries as $key => $entry) {
+ $send[] = str_repeat(" ", 8) . '<entry>';
+ $send[] = str_repeat(" ", 12) .
+ '<title>' . $entry->title . '</title>';
+
+ $send[] = str_repeat(" ", 12) .
+ '<text>' . $entry->text . '</text>';
+
+ $send[] = str_repeat(" ", 8) . '</entry>';
+ }
+ $send[] = str_repeat(" ", 4) . '</section>';
+ }
+
+ $send[] = '';
+ $send[] = str_repeat(" ", 4) . '<data title="Properties">';
+
+ $properties = $report->properties;
+
+ foreach ($properties as $key => $value) {
+ $send[] = str_repeat(" ", 8) . '<entry>';
+ $send[] = str_repeat(" ", 12) .
+ '<key>' . $key . '</key>';
+
+ $send[] = str_repeat(" ", 12) .
+ '<value>' . $value . '</value>';
+
+ $send[] = str_repeat(" ", 8) . '</entry>';
+ }
+ $send[] = str_repeat(" ", 4) . '</data>';
+ $send[] = '</report>';
+ $send[] = '';
+
+
+ return implode("\n", $send);
+ }
+
+}
diff --git a/tests/Output/XMLOutputTest.php b/tests/Output/XMLOutputTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Output/XMLOutputTest.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Keruald\Reporting\Tests\Output;
+
+
+use Keruald\Reporting\Output\XMLOutput;
+use Keruald\Reporting\Report;
+
+use Keruald\Reporting\Tests\WithSampleReport;
+use PHPUnit\Framework\TestCase;
+
+class XMLOutputTest extends TestCase {
+
+ use WithSampleReport;
+
+ ///
+ /// Initialization
+ //
+
+ public Report $report;
+
+ protected function setUp () : void {
+ $this->report = $this->buildSampleReport();
+ }
+
+ ///
+ /// Tests
+ //
+
+ public function testRender () : void {
+ $actual = XMLOutput::for($this->report)
+ ->render();
+
+ $expected = file_get_contents($this->getDataDir() . "/report.xml");
+
+ $this->assertEquals($expected, $actual);
+ }
+
+}
diff --git a/tests/data/report.xml b/tests/data/report.xml
new file mode 100644
--- /dev/null
+++ b/tests/data/report.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<report>
+ <title>Sneakers</title>
+ <section title="Air Max">
+ <entry>
+ <title>Air Max 90</title>
+ <text>One of the more icon color is the infrared.</text>
+ </entry>
+ <entry>
+ <title>Air Max 95</title>
+ <text>Launched in 1995, designed by Sergio Lozano.</text>
+ </entry>
+ <entry>
+ <title>Air Max 97</title>
+ <text>Well highlighted Air bubble.
+
+Inspired by mountain bikes, while an urban legend quotes Japan bullet trains as inspiration.</text>
+ </entry>
+ </section>
+ <section title="Other Nike Air">
+ <entry>
+ <title>Introduction</title>
+ <text>Because there are other sneakers than Air Max.</text>
+ </entry>
+ <entry>
+ <title>Air Force 1</title>
+ <text>« Air Force 1. Zéro fan, que des fanatiques. » -- LTA</text>
+ </entry>
+ </section>
+ <section title="👟">
+ </section>
+
+ <data title="Properties">
+ <entry>
+ <key>Date</key>
+ <value>9999-99-99</value>
+ </entry>
+ <entry>
+ <key>Topic</key>
+ <value>Urban culture</value>
+ </entry>
+ </data>
+</report>

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 07:13 (12 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259691
Default Alt Text
D2527.id6379.diff (4 KB)

Event Timeline