Page MenuHomeDevCentral

D2933.diff
No OneTemporary

D2933.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
Wed, Nov 6, 16:31 (19 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2232105
Default Alt Text
D2933.diff (1 KB)

Event Timeline