Page MenuHomeDevCentral

D241.id752.diff
No OneTemporary

D241.id752.diff

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,13 +4,12 @@
use Illuminate\Console\Command;
-use Nasqueron\Notifications\Phabricator\ProjectsMap;
use Nasqueron\Notifications\Features;
use Config;
+use ProjectsMap;
use Services;
-
class ConfigShow extends Command
{
/**
@@ -67,7 +66,7 @@
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.";
}
diff --git a/tests/Console/Commands/ConfigShowTest.php b/tests/Console/Commands/ConfigShowTest.php
new file mode 100644
--- /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

Mime Type
text/plain
Expires
Sun, Nov 24, 14:42 (2 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260409
Default Alt Text
D241.id752.diff (4 KB)

Event Timeline