Page MenuHomeDevCentral

D2933.id7470.diff
No OneTemporary

D2933.id7470.diff

diff --git a/app/Phabricator/PhabricatorAPI.php b/app/Phabricator/PhabricatorAPI.php
--- a/app/Phabricator/PhabricatorAPI.php
+++ b/app/Phabricator/PhabricatorAPI.php
@@ -114,7 +114,7 @@
/**
* Gets the first result of an API reply.
*/
- public static function getFirstResult (iterable $reply) : mixed {
+ public static function getFirstResult (iterable|\stdClass $reply) : mixed {
if (is_object($reply) && property_exists($reply, 'data')) {
$reply = $reply->data;
}
diff --git a/tests/Phabricator/PhabricatorAPITest.php b/tests/Phabricator/PhabricatorAPITest.php
--- a/tests/Phabricator/PhabricatorAPITest.php
+++ b/tests/Phabricator/PhabricatorAPITest.php
@@ -29,4 +29,18 @@
$this->expectException(\RuntimeException::class);
PhabricatorAPI::forProject("NotFound");
}
+
+ public function testGetFirstResultForObject () {
+ $result = new \stdClass;
+ $result->data = ["first", "second", "third"];
+
+ $this->assertEquals("first", PhabricatorAPI::getFirstResult($result));
+ }
+
+ public function testGetFirstResultForIterable () {
+ $result = ["first", "second", "third"];
+
+ $this->assertEquals("first", PhabricatorAPI::getFirstResult($result));
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 18, 22:39 (20 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2251384
Default Alt Text
D2933.id7470.diff (1 KB)

Event Timeline