Page MenuHomeDevCentral

D2530.diff
No OneTemporary

D2530.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,71 @@
+<?php
+
+
+namespace Keruald\Reporting\Output;
+
+
+class XMLOutput extends Output {
+
+ public function render () : string {
+ $report = $this->report;
+ $document = xmlwriter_open_memory();
+
+ xmlwriter_set_indent($document, true);
+ xmlwriter_set_indent_string($document, ' ');
+
+ xmlwriter_start_document($document, '1.0', 'UTF-8');
+
+ xmlwriter_start_element($document, 'report');
+ xmlwriter_start_attribute($document, 'title');
+ xmlwriter_text($document, $report->title);
+ xmlwriter_end_attribute($document);
+
+ foreach ($report->sections as $section) {
+ xmlwriter_start_element($document, 'section');
+ xmlwriter_start_attribute($document, 'title');
+ xmlwriter_text($document, $section->title);
+ xmlwriter_end_attribute($document);
+
+ foreach ($section->entries as $entry) {
+ xmlwriter_start_element($document, 'entry');
+
+ xmlwriter_start_attribute($document, 'title');
+ xmlwriter_text($document, $entry->title);
+ xmlwriter_end_attribute($document);
+
+ xmlwriter_start_element($document, 'text');
+ xmlwriter_text($document, $entry->text);
+ xmlwriter_end_element($document);
+
+ xmlwriter_end_element($document);
+ }
+ xmlwriter_end_element($document); // section
+ }
+
+ xmlwriter_start_element($document, 'data');
+ xmlwriter_start_attribute($document, 'title');
+ xmlwriter_text($document, "Properties");
+ xmlwriter_end_attribute($document);
+
+ foreach ($report->properties as $key => $value) {
+ xmlwriter_start_element($document, 'entry');
+
+ xmlwriter_start_element($document, 'key');
+ xmlwriter_text($document, $key);
+ xmlwriter_end_element($document);
+
+ xmlwriter_start_element($document, 'value');
+ xmlwriter_text($document, $value);
+ xmlwriter_end_element($document);
+
+ xmlwriter_end_element($document);
+ }
+ xmlwriter_end_element($document); // data
+
+ xmlwriter_end_element($document); // report
+ xmlwriter_end_document($document);
+
+ return xmlwriter_output_memory($document);
+ }
+
+}
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,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<report title="Sneakers">
+ <section title="Air Max">
+ <entry title="Air Max 90">
+ <text>One of the more icon color is the infrared.</text>
+ </entry>
+ <entry title="Air Max 95">
+ <text>Launched in 1995, designed by Sergio Lozano.</text>
+ </entry>
+ <entry title="Air Max 97">
+ <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">
+ <text>Because there are other sneakers than Air Max.</text>
+ </entry>
+ <entry title="Air Force 1">
+ <text>« Air Force 1. Zéro fan, que des fanatiques. » -- LTA</text>
+ </entry>
+ </section>
+ <section title="👟"/>
+ <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
Fri, Dec 20, 15:08 (20 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2308203
Default Alt Text
D2530.diff (4 KB)

Event Timeline