Page MenuHomeDevCentral

No OneTemporary

diff --git a/app/Console/Commands/ConfigShow.php b/app/Console/Commands/ConfigShow.php
index b7e571e..8c6bc9c 100644
--- a/app/Console/Commands/ConfigShow.php
+++ b/app/Console/Commands/ConfigShow.php
@@ -1,140 +1,135 @@
<?php
namespace Nasqueron\Notifications\Console\Commands;
use Illuminate\Console\Command;
use Nasqueron\Notifications\Phabricator\ProjectsMap;
use Nasqueron\Notifications\Features;
use Config;
use Services;
class ConfigShow extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'config:show';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Show notifications center configuration';
/**
* Creates a new command instance.
*
* @return void
*/
public function __construct () {
parent::__construct();
}
///
/// Prepare information tables
///
/**
* Gets the services (defined in credentials.json) as table rows
*
* @return array
*/
protected function getServicesTableRows () {
$rows = [];
foreach (Services::get() as $service) {
- if (isset($service->instance)) {
- $instance = $service->instance;
- } else {
- $instance = 'ø';
- }
$rows[] = [
$service->gate,
$service->door,
- $instance,
+ $service->getInstanceName(),
$this->getServiveStatus($service)
];
}
return $rows;
}
/**
* Gets service status
*
* @param $service The service to check
* @return string A description of the issue if something is wrong; otherwise, "✓".
*/
protected function getServiveStatus ($service) {
if ($service->gate === 'Phabricator') {
// Ensure the projects map is cached
$map = ProjectsMap::fetch($service->instance);
if (!$map->isCached()) {
return "Projects map not cached.";
}
}
return "✓";
}
/**
* Gets features as table rows
*
* @return array
*/
protected function getFeaturesTableRows () {
$rows = [];
foreach (Features::getAll() as $key => $value) {
if ($value) {
$checkMark = '✓';
} else {
$checkMark = '';
}
$rows[] = [$key, $checkMark];
}
return $rows;
}
///
/// Handle the command
///
/**
* Executes the console command.
*
* @return mixed
*/
public function handle () {
$this->printGates();
$this->printFeatures();
$this->printServices();
}
protected final function printGates () {
$this->info("Gates:\n");
foreach (Config::get('gate.controllers') as $gate) {
$this->line('- ' . $gate);
}
}
protected final function printFeatures () {
$this->info("\nFeatures:\n");
$this->table(
['Feature', 'Enabled'],
$this->getFeaturesTableRows()
);
}
protected final function printServices () {
$this->info("\nServices declared in credentials:\n");
$this->table(
['Gate', 'Door', 'Instance', 'Status'],
$this->getServicesTableRows()
);
}
}
diff --git a/app/Services/Service.php b/app/Services/Service.php
index efc95d6..52675b2 100644
--- a/app/Services/Service.php
+++ b/app/Services/Service.php
@@ -1,25 +1,38 @@
<?php
namespace Nasqueron\Notifications\Services;
class Service {
/**
* @var string
*/
public $gate;
/**
* @var string
*/
public $door;
/**
* @var string
*/
public $instance;
/**
* @var string
*/
public $secret;
+
+ /**
+ * Gets instance name
+ *
+ * @return string The instance name or "ø" if omitted
+ */
+ public function getInstanceName () {
+ if (!isset($this->instance)) {
+ return "ø";
+ }
+
+ return $this->instance;
+ }
}
diff --git a/tests/Services/ServiceTest.php b/tests/Services/ServiceTest.php
new file mode 100644
index 0000000..0e0f57b
--- /dev/null
+++ b/tests/Services/ServiceTest.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Services;
+
+use Nasqueron\Notifications\Services\Service;
+use Nasqueron\Notifications\Tests\TestCase;
+
+class ServiceTest extends TestCase {
+
+ /**
+ * @var Nasqueron\Notifications\Services\Service
+ */
+ private $serviceWithInstance;
+
+ /**
+ * @var Nasqueron\Notifications\Services\Service
+ */
+ private $serviceWithoutInstance;
+
+ public function setUp () {
+ $this->serviceWithoutInstance = new Service();
+
+ $this->serviceWithInstance = clone $this->serviceWithoutInstance;
+ $this->serviceWithInstance->instance = "http://www.perdu.com";
+ }
+
+ ///
+ /// Tests for getInstanceName()
+ ///
+
+ public function testGetInstanceName () {
+ $this->assertSame(
+ "http://www.perdu.com",
+ $this->serviceWithInstance->getInstanceName()
+ );
+ }
+
+ public function testGetInstanceNameWhenThereIsNoInstance () {
+ $this->assertSame(
+ "ø",
+ $this->serviceWithoutInstance->getInstanceName()
+ );
+ }
+
+}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Feb 28, 20:36 (21 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2447794
Default Alt Text
(5 KB)

Event Timeline