Page MenuHomeDevCentral

D334.diff
No OneTemporary

D334.diff

diff --git a/app/Phabricator/ProjectsMap.php b/app/Phabricator/ProjectsMap.php
--- a/app/Phabricator/ProjectsMap.php
+++ b/app/Phabricator/ProjectsMap.php
@@ -139,10 +139,12 @@
* Gets a new ProjectsMap instance and queries Phabricator API to fill it
*
* @param string $phabricatorURL The Phabricator URL (e.g. http://secure.phabricator.com)
+ * @param Nasqueron\Notifications\Contracts\APIClient $apiClient The Phabricator API client
* @return ProjectsMap
*/
- public static function fetch ($phabricatorURL) {
+ public static function fetch ($phabricatorURL, APIClient $apiClient = null) {
$instance = new self($phabricatorURL);
+ $instance->setAPIClient($apiClient);
$instance->fetchFromAPI();
return $instance;
}
@@ -165,7 +167,7 @@
/**
* @param Nasqueron\Notifications\Contracts\APIClient $apiClient
*/
- public function setAPIClient (APIClient $apiClient) {
+ public function setAPIClient (APIClient $apiClient = null) {
$this->apiClient = $apiClient;
}
diff --git a/tests/Phabricator/ProjectsMapTest.php b/tests/Phabricator/ProjectsMapTest.php
--- a/tests/Phabricator/ProjectsMapTest.php
+++ b/tests/Phabricator/ProjectsMapTest.php
@@ -5,6 +5,8 @@
use Nasqueron\Notifications\Phabricator\ProjectsMap;
use Nasqueron\Notifications\Tests\TestCase;
+use Mockery;
+
class ProjectsMapTest extends TestCase {
/**
@@ -161,4 +163,30 @@
);
}
+ ///
+ /// Tests API
+ ///
+
+ private function mockPhabricatorAPIWithReply ($reply) {
+ return Mockery::mock('Nasqueron\Notifications\Contract\APIClient')
+ ->shouldReceive('call')
+ ->andReturn($reply);
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testFetchFromAPIWithoutReply () {
+ $mock = $this->mockPhabricatorAPIWithReply(false);
+ ProjectsMap::fetch("http://phabricator.acme.tld", $mock);
+ }
+
+ /**
+ * @expectedException Exception
+ */
+ public function testFetchFromAPIInvalidReply () {
+ $mock = $this->mockPhabricatorAPIWithReply(new \stdClass);
+ ProjectsMap::fetch("http://phabricator.acme.tld", $mock);
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Mon, Sep 30, 01:36 (20 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2164192
Default Alt Text
D334.diff (2 KB)

Event Timeline