Page MenuHomeDevCentral

D2503.id6303.diff
No OneTemporary

D2503.id6303.diff

diff --git a/src/Output/HTMLOutput.php b/src/Output/HTMLOutput.php
new file mode 100644
--- /dev/null
+++ b/src/Output/HTMLOutput.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace Keruald\Reporting\Output;
+
+class HTMLOutput extends Output {
+
+ public function print () : string {
+ // TODO: Implement print() method.
+ return "";
+ }
+
+}
diff --git a/src/Output/MarkdownOutput.php b/src/Output/MarkdownOutput.php
new file mode 100644
--- /dev/null
+++ b/src/Output/MarkdownOutput.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace Keruald\Reporting\Output;
+
+class MarkdownOutput extends Output {
+
+ public function print () : string {
+ // TODO: Implement print() method.
+ return "";
+ }
+}
diff --git a/src/Output/Output.php b/src/Output/Output.php
new file mode 100644
--- /dev/null
+++ b/src/Output/Output.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Keruald\Reporting\Output;
+
+use Keruald\Reporting\Report;
+
+abstract class Output {
+
+ ///
+ /// Properties
+ ///
+
+ protected Report $report;
+
+ ///
+ /// Abstract methods to implement
+ ///
+
+ public abstract function print() : string;
+
+ ///
+ /// Constructors
+ ///
+
+ public static function for (Report $report) : Output {
+ $output = new static();
+ $output->report = $report;
+
+ return $output;
+ }
+}
diff --git a/tests/Output/HTMLOutputTest.php b/tests/Output/HTMLOutputTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Output/HTMLOutputTest.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Keruald\Reporting\Tests\Output;
+
+use Keruald\Reporting\Output\HTMLOutput;
+use Keruald\Reporting\Report;
+
+use Keruald\Reporting\Tests\WithSampleReport;
+use PHPUnit\Framework\TestCase;
+
+class HTMLOutputTest extends TestCase {
+
+ use WithSampleReport;
+
+ ///
+ /// Initialization
+ //
+
+ public Report $report;
+
+ protected function setUp () : void {
+ $this->report = $this->buildSampleReport();
+ }
+
+ ///
+ /// Tests
+ //
+
+ public function testPrint() : void {
+ $actual = HTMLOutput::for($this->report)
+ ->print();
+
+ $expected = file_get_contents($this->getDataDir() . "/report.html");
+
+ $this->assertEquals($expected, $actual);
+ }
+}
diff --git a/tests/Output/MarkdownOutputTest.php b/tests/Output/MarkdownOutputTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Output/MarkdownOutputTest.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Keruald\Reporting\Tests\Output;
+
+use Keruald\Reporting\Output\MarkdownOutput;
+use Keruald\Reporting\Report;
+
+use Keruald\Reporting\Tests\WithSampleReport;
+use PHPUnit\Framework\TestCase;
+
+class MarkdownOutputTest extends TestCase {
+
+ use WithSampleReport;
+
+ ///
+ /// Initialization
+ //
+
+ public Report $report;
+
+ protected function setUp () : void {
+ $this->report = $this->buildSampleReport();
+ }
+
+ ///
+ /// Tests
+ //
+
+ public function testPrint() : void {
+ $actual = MarkdownOutput::for($this->report)
+ ->print();
+
+ $expected = file_get_contents($this->getDataDir() . "/report.md");
+
+ $this->assertEquals($expected, $actual);
+ }
+}
diff --git a/tests/WithSampleReport.php b/tests/WithSampleReport.php
new file mode 100644
--- /dev/null
+++ b/tests/WithSampleReport.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Keruald\Reporting\Tests;
+
+use Keruald\Reporting\Report;
+use Keruald\Reporting\ReportEntry;
+use Keruald\Reporting\ReportSection;
+
+trait WithSampleReport {
+
+ public function getDataDir () : string {
+ return __DIR__ . "/data";
+ }
+
+ public function buildSampleReport () : Report {
+ $report = new Report("Sneakers");
+
+ // Section 1
+ $section = new ReportSection("Air Max");
+ $section->entries = [
+ new ReportEntry("Air Max 90", "One of the more icon color is the infrared."),
+ new ReportEntry("Air Max 95", "Launched in 1995, designed by Sergio Lozano."),
+ new ReportEntry("Air Max 97", <<<EOF
+Well highlighted Air bubble.
+
+Inspired by mountain bikes, while an urban legend quotes Japan bullet trains as inspiration.
+EOF
+),
+ ];
+ $report->push($section);
+
+ // Section 2
+ $section = new ReportSection("Other Nike Air");
+ $section->entries = [
+ new ReportEntry("Introduction", "Because there are other sneakers than Air Max."),
+ new ReportEntry("Air Force 1", "« Air Force 1. Zéro fan, que des fanatiques. » -- LTA"),
+ ];
+ $report->push($section);
+
+ // Section 3 — should be ignored as blank
+ $section = new ReportSection("Not cool sneakers");
+ // As all sneakers are cool, this is empty.
+ $report->pushIfNotEmpty($section);
+
+ // Section 4 — should be included even if blank
+ $section = new ReportSection("👟");
+ $report->push($section);
+
+ // Metadata
+ $report->properties = [
+ "Date" => "9999-99-99",
+ "Topic" => "Urban culture",
+ ];
+
+ return $report;
+ }
+
+}
diff --git a/tests/data/report.html b/tests/data/report.html
new file mode 100644
--- /dev/null
+++ b/tests/data/report.html
@@ -0,0 +1,43 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport"
+ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
+ <meta name="X-Report-Date" content="9999-99-99">
+ <meta name="X-Report-Topic" content="Urban culture">
+ <title>Sneakers</title>
+</head>
+<body>
+<h1 id="sneakers">Sneakers</h1>
+<h2 id="air-max">Air Max</h2>
+<h3 id="air-max-90">Air Max 90</h3>
+<p>One of the more icon color is the infrared.</p>
+<h3 id="air-max-95">Air Max 95</h3>
+<p>Launched in 1995, designed by Sergio Lozano.</p>
+<h3 id="air-max-97">Air Max 97</h3>
+<p>Well highlighted Air bubble.</p>
+<p>Inspired by mountain bikes, while an urban legend quotes Japan bullet trains as inspiration.</p>
+<h2 id="other-nike-air">Other Nike Air</h2>
+<h3 id="introduction">Introduction</h3>
+<p>Because there are other sneakers than Air Max.</p>
+<h3 id="air-force-1">Air Force 1</h3>
+<p>« Air Force 1. Zéro fan, que des fanatiques. » -- LTA</p>
+<h3 id="👟">👟</h3>
+<hr>
+<h2 id="ReportProperties">Report properties</h2>
+<table>
+ <tbody>
+ <tr>
+ <th>Date</th>
+ <td>9999-99-99</td>
+ </tr>
+ <tr>
+ <th>Topic</th>
+ <td>Urban culture</td>
+ </tr>
+ </tbody>
+</table>
+</body>
+</html>
diff --git a/tests/data/report.md b/tests/data/report.md
new file mode 100644
--- /dev/null
+++ b/tests/data/report.md
@@ -0,0 +1,36 @@
+# Sneakers
+
+## Air Max
+
+### Air Max 90
+
+One of the more icon color is the infrared.
+
+### Air Max 95
+
+Launched in 1995, designed by Sergio Lozano.
+
+### Air Max 97
+
+Well highlighted Air bubble.
+
+Inspired by mountain bikes, while an urban legend quotes Japan bullet trains as inspiration.
+
+## Other Nike Air
+
+### Introduction
+
+Because there are other sneakers than Air Max.
+
+### Air Force 1
+
+« Air Force 1. Zéro fan, que des fanatiques. » -- LTA
+
+### 👟
+
+---
+
+| Property | |
+|----------|---------------|
+| Date | 9999-99-99 |
+| Topic | Urban culture |

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 08:31 (20 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2247287
Default Alt Text
D2503.id6303.diff (7 KB)

Event Timeline