Page MenuHomeDevCentral

D606.id.diff
No OneTemporary

D606.id.diff

diff --git a/app/Phabricator/PhabricatorAPI.php b/app/Phabricator/PhabricatorAPI.php
--- a/app/Phabricator/PhabricatorAPI.php
+++ b/app/Phabricator/PhabricatorAPI.php
@@ -45,7 +45,7 @@
* Gets an API instance for the specific instance
*
* @param string $instance The name of the instance (this matches that parameter in credentials.json)
- * @return PhabricatorAPI|null A PhabricatorAPI instance for the project if found; otherwise, null.
+ * @return PhabricatorAPI A PhabricatorAPI instance for the project if found; otherwise, null.
*/
public static function forInstance ($instance) {
$service = Services::findServiceByProperty('Phabricator', 'instance', $instance);
@@ -59,12 +59,12 @@
* Gets an API instance for the specific project
*
* @param string $project The name of the project (this matches the door parameter in credentials.json)
- * @return PhabricatorAPI|null A PhabricatorAPI instance for the project if found; otherwise, null.
+ * @return PhabricatorAPI A PhabricatorAPI instance for the project if found; otherwise, null.
*/
public static function forProject ($project) {
$service = Services::findServiceByDoor('Phabricator', $project);
if ($service === null) {
- return null;
+ throw new \RuntimeException("No credentials for Phabricator project $project.");
}
return new self($service->instance, $service->secret);
}
diff --git a/tests/Phabricator/PhabricatorAPITest.php b/tests/Phabricator/PhabricatorAPITest.php
new file mode 100644
--- /dev/null
+++ b/tests/Phabricator/PhabricatorAPITest.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Phabricator;
+
+use Nasqueron\Notifications\Phabricator\PhabricatorAPI;
+use Nasqueron\Notifications\Tests\TestCase;
+
+class PhabricatorAPITest extends TestCase {
+ public function testForInstance () {
+ $this->assertInstanceOf(
+ '\Nasqueron\Notifications\Phabricator\PhabricatorAPI',
+ PhabricatorAPI::forInstance("https://phabricator.acme.tld")
+ );
+ }
+
+ public function testForProject () {
+ $this->assertInstanceOf(
+ '\Nasqueron\Notifications\Phabricator\PhabricatorAPI',
+ PhabricatorAPI::forInstance("https://phabricator.acme.tld")
+ );
+ }
+
+ /**
+ * @expectedException \RuntimeException
+ */
+ public function testForInstanceWhere () {
+ PhabricatorAPI::forInstance("https://notfound.acme.tld");
+ }
+
+ /**
+ * @expectedException \RuntimeException
+ */
+ public function testForProjectWhenProjectDoesNotExist () {
+ PhabricatorAPI::forProject("NotFound");
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 7, 02:31 (6 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2179608
Default Alt Text
D606.id.diff (2 KB)

Event Timeline