Page MenuHomeDevCentral

D790.id2013.diff
No OneTemporary

D790.id2013.diff

diff --git a/app/Config/Reporting/BaseReportEntry.php b/app/Config/Reporting/BaseReportEntry.php
new file mode 100644
--- /dev/null
+++ b/app/Config/Reporting/BaseReportEntry.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Nasqueron\Notifications\Config\Reporting;
+
+abstract class BaseReportEntry {
+
+ ///
+ /// Format
+ ///
+
+ public abstract function toArray () : array;
+ public abstract function toFancyArray () : array;
+
+ ///
+ /// Format helper methods
+ ///
+
+ /**
+ * Returns a fancy string for reports.
+ *
+ * @param string $string The source string
+ * @param string $emptyStringGlyph The glyph to use if the string is empty
+ * @return string
+ */
+ public static function fancyString (string $string, string $emptyStringGlyph) : string {
+ if ($string === "") {
+ return $emptyStringGlyph;
+ }
+
+ return $string;
+ }
+
+ /**
+ * Returns a fancy representation from a boolean for reports.
+ *
+ * @param bool $value The source value
+ * @param string $truthyStringGlyph The glyph to use if the value is true
+ * @param string $falsyStringGlyph The glyph to use if the value is false [facultative, by default an empty string]
+ * @return string The relevant glyph
+ */
+ public static function fancyBool (bool $value, string $truthyStringGlyph, string $falsyStringGlyph = '') : string {
+ if ($value) {
+ return $truthyStringGlyph;
+ }
+
+ return $falsyStringGlyph;
+ }
+
+}
diff --git a/app/Config/Reporting/FeatureReportEntry.php b/app/Config/Reporting/FeatureReportEntry.php
--- a/app/Config/Reporting/FeatureReportEntry.php
+++ b/app/Config/Reporting/FeatureReportEntry.php
@@ -2,7 +2,7 @@
namespace Nasqueron\Notifications\Config\Reporting;
-class FeatureReportEntry {
+final class FeatureReportEntry extends BaseReportEntry {
///
/// Public properties
@@ -33,4 +33,32 @@
$this->enabled = $enabled;
}
+ ///
+ /// Format
+ ///
+
+ /**
+ * Gets the entry as an array.
+ *
+ * @return string[]
+ */
+ public function toArray () : array {
+ return [
+ $this->name,
+ (string)$this->enabled,
+ ];
+ }
+
+ /**
+ * Gets the entry as an array. Formats empty string.
+ *
+ * @return string[]
+ */
+ public function toFancyArray () : array {
+ return [
+ $this->name,
+ self::fancyBool($this->enabled, '✓'),
+ ];
+ }
+
}
diff --git a/app/Config/Reporting/ServiceReportEntry.php b/app/Config/Reporting/ServiceReportEntry.php
--- a/app/Config/Reporting/ServiceReportEntry.php
+++ b/app/Config/Reporting/ServiceReportEntry.php
@@ -6,7 +6,7 @@
use ProjectsMap;
-class ServiceReportEntry {
+final class ServiceReportEntry extends BaseReportEntry {
///
/// Private members
@@ -99,4 +99,36 @@
return !$map->isCached();
}
+ ///
+ /// Format
+ ///
+
+ /**
+ * Gets the entry as an array. Formats empty string.
+ *
+ * @return string[]
+ */
+ public function toArray () : array {
+ return [
+ $this->gate,
+ $this->door,
+ $this->instance,
+ $this->status,
+ ];
+ }
+
+ /**
+ * Gets the entry as an array. Formats empty string.
+ *
+ * @return string[]
+ */
+ public function toFancyArray () : array {
+ return [
+ $this->gate,
+ $this->door,
+ self::fancyString($this->instance, 'ø'),
+ self::fancyString($this->status, '✓'),
+ ];
+ }
+
}
diff --git a/app/Console/Commands/ConfigShow.php b/app/Console/Commands/ConfigShow.php
--- a/app/Console/Commands/ConfigShow.php
+++ b/app/Console/Commands/ConfigShow.php
@@ -4,12 +4,7 @@
use Illuminate\Console\Command;
-use Nasqueron\Notifications\Config\Features;
-use Nasqueron\Notifications\Config\Services\Service;
-
-use Config;
-use ProjectsMap;
-use Services;
+use Nasqueron\Notifications\Config\Reporting\ConfigReport;
class ConfigShow extends Command
{
@@ -28,11 +23,9 @@
protected $description = 'Show notifications center configuration';
/**
- * Creates a new command instance.
+ * @var \Nasqueron\Notifications\Config\Reporting\ConfigReport
*/
- public function __construct () {
- parent::__construct();
- }
+ private $report;
///
/// Prepare information tables
@@ -41,37 +34,16 @@
/**
* Gets the services (defined in credentials.json) as table rows.
*
- * @return \Nasqueron\Notifications\Config\Services\Service[]
+ * @return array
*/
protected function getServicesTableRows () : array {
$rows = [];
- foreach (Services::get() as $service) {
- $rows[] = [
- $service->gate,
- $service->door,
- $service->getInstanceName(),
- $this->getServiveStatus($service)
- ];
- }
- return $rows;
- }
- /**
- * Gets service status.
- *
- * @param \Nasqueron\Notifications\Config\Services\Service $service The service to check
- * @return string A description of the issue if something is wrong; otherwise, "✓".
- */
- protected function getServiveStatus (Service $service) : string {
- if ($service->gate === 'Phabricator') {
- // Ensure the projects map is cached
- $map = \ProjectsMap::fetch($service->door);
- if (!$map->isCached()) {
- return "Projects map not cached.";
- }
+ foreach ($this->report->services as $service) {
+ $rows[] = $service->toFancyArray();
}
- return "✓";
+ return $rows;
}
/**
@@ -81,15 +53,11 @@
*/
protected function getFeaturesTableRows () : array {
$rows = [];
- foreach (Features::getAll() as $key => $value) {
- if ($value) {
- $checkMark = '✓';
- } else {
- $checkMark = '';
- }
-
- $rows[] = [$key, $checkMark];
+
+ foreach ($this->report->features as $feature) {
+ $rows[] = $feature->toFancyArray();
}
+
return $rows;
}
@@ -101,14 +69,20 @@
* Executes the console command.
*/
public function handle () : void {
+ $this->prepareReport();
+
$this->printGates();
$this->printFeatures();
$this->printServices();
}
+ protected final function prepareReport() : void {
+ $this->report = new ConfigReport();
+ }
+
protected final function printGates () : void {
$this->info("Gates:\n");
- foreach (Config::get('gate.controllers') as $gate) {
+ foreach ($this->report->gates as $gate) {
$this->line('- ' . $gate);
}
}
diff --git a/tests/Config/Reporting/BaseReportEntryTest.php b/tests/Config/Reporting/BaseReportEntryTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Config/Reporting/BaseReportEntryTest.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Config\Reporting;
+
+use Nasqueron\Notifications\Config\Reporting\BaseReportEntry;
+use Nasqueron\Notifications\Tests\TestCase;
+
+class BaseReportEntryTest extends TestCase {
+
+ public function testFancyString() {
+ $this->assertSame('ø', BaseReportEntry::fancyString('', 'ø'));
+ $this->assertSame('ø', BaseReportEntry::fancyString('ø', 'ø'));
+ $this->assertSame('o', BaseReportEntry::fancyString('o', 'ø'));
+ $this->assertSame('', BaseReportEntry::fancyString('', ''));
+ }
+
+ public function testFancyBool() {
+ $this->assertSame('ø', BaseReportEntry::fancyBool(false, '✓', 'ø'));
+ $this->assertSame('✓', BaseReportEntry::fancyBool(true, '✓', 'ø'));
+ $this->assertSame('', BaseReportEntry::fancyBool(false, '✓'));
+ $this->assertSame('✓', BaseReportEntry::fancyBool(true, '✓'));
+ $this->assertSame('', BaseReportEntry::fancyBool(true, '', ''));
+ $this->assertSame('', BaseReportEntry::fancyBool(false, '', ''));
+ }
+
+}
diff --git a/tests/Config/Reporting/FeatureReportEntryTest.php b/tests/Config/Reporting/FeatureReportEntryTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Config/Reporting/FeatureReportEntryTest.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Config\Reporting;
+
+use Nasqueron\Notifications\Config\Reporting\FeatureReportEntry;
+use Nasqueron\Notifications\Tests\TestCase;
+
+class FeatureReportEntryTest extends TestCase {
+
+ /**
+ * @var FeatureReportEntry
+ */
+ private $enabledFeatureEntry;
+
+ /**
+ * @var FeatureReportEntry
+ */
+ private $disabledFeatureEntry;
+
+ public function setUp () {
+ $this->enabledFeatureEntry = new FeatureReportEntry("foo", true);
+ $this->disabledFeatureEntry = new FeatureReportEntry("bar", false);
+ }
+
+ public function testToArray() {
+ $this->assertSame(
+ ["foo", (string)true],
+ $this->enabledFeatureEntry->toArray()
+
+ );
+ $this->assertSame(
+ ["bar", (string)false],
+ $this->disabledFeatureEntry->toArray()
+ );
+ }
+
+ public function testToFancyArray() {
+ $this->assertSame(
+ ["foo", "✓"],
+ $this->enabledFeatureEntry->toFancyArray()
+ );
+ $this->assertSame(
+ ["bar", ""],
+ $this->disabledFeatureEntry->toFancyArray()
+ );
+ }
+
+}
diff --git a/tests/Config/Reporting/ServiceReportEntryTest.php b/tests/Config/Reporting/ServiceReportEntryTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Config/Reporting/ServiceReportEntryTest.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Config\Reporting;
+
+use Nasqueron\Notifications\Config\Reporting\ServiceReportEntry;
+use Nasqueron\Notifications\Config\Services\Service;
+use Nasqueron\Notifications\Tests\TestCase;
+
+class ServiceReportEntryTest extends TestCase {
+
+ /**
+ * @var ServiceReportEntry
+ */
+ private $serviceEntry;
+
+ public function setUp () {
+ $service = $this->mockService();
+ $this->serviceEntry = new ServiceReportEntry($service);
+ }
+
+ public function testToArray() {
+ $this->assertSame(
+ ["Storm", "Acme", "http://www.perdu.com", ""],
+ $this->serviceEntry->toArray()
+ );
+ }
+
+ public function testToFancyArray() {
+ $this->assertSame(
+ ["Storm", "Acme", "http://www.perdu.com", "✓"],
+ $this->serviceEntry->toFancyArray()
+ );
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 20, 06:06 (18 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2307308
Default Alt Text
D790.id2013.diff (10 KB)

Event Timeline