Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4060929
D334.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D334.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Mon, Jan 27, 08:53 (3 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2380221
Default Alt Text
D334.diff (2 KB)
Attached To
Mode
D334: API dependency injection for ProjectsMap
Attached
Detach File
Event Timeline
Log In to Comment