Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4060963
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/app/Console/Commands/ConfigShow.php b/app/Console/Commands/ConfigShow.php
index 8c6bc9c..38a41a7 100644
--- a/app/Console/Commands/ConfigShow.php
+++ b/app/Console/Commands/ConfigShow.php
@@ -1,135 +1,134 @@
<?php
namespace Nasqueron\Notifications\Console\Commands;
use Illuminate\Console\Command;
-use Nasqueron\Notifications\Phabricator\ProjectsMap;
use Nasqueron\Notifications\Features;
use Config;
+use ProjectsMap;
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) {
$rows[] = [
$service->gate,
$service->door,
$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);
+ $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/tests/Console/Commands/ConfigShowTest.php b/tests/Console/Commands/ConfigShowTest.php
new file mode 100644
index 0000000..5cd9747
--- /dev/null
+++ b/tests/Console/Commands/ConfigShowTest.php
@@ -0,0 +1,111 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Console\Commands;
+
+use Nasqueron\Notifications\Features;
+use Nasqueron\Notifications\Services\Service;
+
+use Mockery;
+
+class ConfigShowTest extends TestCase {
+
+ /**
+ * @var string
+ */
+ protected $class = 'Nasqueron\Notifications\Console\Commands\ConfigShow';
+
+ /**
+ * Nasqueron\Notifications\Services\Services
+ */
+ private $servicesMock;
+
+ public function setUp () {
+ parent::setUp();
+
+ $this->mockServices();
+ }
+
+ protected function mockServices () {
+ // Inject into our container a mock of Services
+ $this->servicesMock = Mockery::mock('Nasqueron\Notifications\Services\Services');
+ $this->app->instance('services', $this->servicesMock);
+ }
+
+ protected function mockService ($gate = 'Storm') {
+ $service = new Service;
+ $service->gate = $gate;
+ $service->door = 'Acme';
+ $service->instance = "http://www.perdu.com";
+ return $service;
+ }
+
+ public function testRegularExecute () {
+ //Our command calls Services::get()
+ $this->servicesMock->shouldReceive('get')->once()->andReturn([]);
+
+ $this->tester->execute(['command' => $this->command->getName()]);
+
+ $this->assertRegexp('/Gates/', $this->tester->getDisplay());
+ $this->assertRegexp('/Features/', $this->tester->getDisplay());
+ $this->assertRegexp('/Services declared/', $this->tester->getDisplay());
+ }
+
+ public function testRegularExecuteWithService () {
+ $service = $this->mockService();
+ $this->servicesMock
+ ->shouldReceive('get')
+ ->once()
+ ->andReturn([$service]);
+
+ $this->tester->execute(['command' => $this->command->getName()]);
+ $this->assertRegexp('/Storm/', $this->tester->getDisplay());
+ }
+
+ public function testRegularExecuteWithPhabricatorService () {
+ $this->mockPhabricatorAPIForProjectsMap();
+
+ $service = $this->mockService('Phabricator');
+ $this->servicesMock
+ ->shouldReceive('get')
+ ->once()
+ ->andReturn([$service]);
+
+ $this->servicesMock
+ ->shouldReceive('findServiceByProperty');
+
+ $this->tester->execute(['command' => $this->command->getName()]);
+ $this->assertRegexp('/Phabricator.*Projects map not cached./', $this->tester->getDisplay());
+ }
+
+ protected function mockProjectsMap () {
+ $mock = Mockery::mock('Nasqueron\Notifications\Phabricator\ProjectsMap');
+ $this->app->instance('phabricator-projectsmap', $mock);
+
+ return $mock;
+ }
+
+ public function testRegularExecuteWithPhabricatorServiceWhenTheProjectsMapIsCached () {
+ // The services list will return only one, for the Phabricator gate.
+ $service = $this->mockService('Phabricator');
+ $this->servicesMock
+ ->shouldReceive('get')->once()->andReturn([$service]);
+
+ // The project map (built by the factory) will say it's cached.
+ $this->mockProjectsMap()
+ ->shouldReceive('fetch->isCached')->once()->andReturn(true);
+
+ $this->tester->execute(['command' => $this->command->getName()]);
+ $this->assertRegexp('/Phabricator.*✓/', $this->tester->getDisplay());
+ }
+
+ public function testExecuteWhenSomeFeatureIsDisabled () {
+ Features::disable('ActionsReport');
+
+ $this->servicesMock->shouldReceive('get')->once()->andReturn([]);
+
+ $this->tester->execute(['command' => $this->command->getName()]);
+ $this->assertRegexp('/Gate *\| *✓ *\|/', $this->tester->getDisplay());
+ $this->assertRegexp('/ActionsReport *\| *\|/', $this->tester->getDisplay());
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jan 28, 09:13 (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2380242
Default Alt Text
(7 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment