From 6503f23d13d9cd55a2a1ea908e91ce21be81217b Mon Sep 17 00:00:00 2001 From: "Vladyslav G." Date: Wed, 2 Sep 2026 04:32:38 +0200 Subject: [PATCH] fix(channel): read reactions from the reactions endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getReactions() bound Endpoint::CHANNEL_MESSAGES, which has one slot, with a channel, a message and an emoji. The message and the emoji were dropped, so the call went to channels/:id/messages and came back with the channel's last messages mapped into User objects — never the reactions, and never an error either. The test asserted only the return type. Nothing here checked which endpoint a method reached, which is how a method could bind the wrong constant and still pass; the harness now takes an optional url to assert against, filled in for this one and worth filling in elsewhere. --- src/Rest/Channel.php | 2 +- tests/Rest/ChannelTest.php | 1 + tests/Rest/HttpHelperTestCase.php | 26 ++++++++++++++++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Rest/Channel.php b/src/Rest/Channel.php index 509697a..df9c21d 100644 --- a/src/Rest/Channel.php +++ b/src/Rest/Channel.php @@ -253,7 +253,7 @@ public function getReactions( return $this->mapArrayPromise( $this->http->get( Endpoint::bind( - Endpoint::CHANNEL_MESSAGES, + Endpoint::MESSAGE_REACTION_EMOJI, $channelId, $messageId, (string) $emoji diff --git a/tests/Rest/ChannelTest.php b/tests/Rest/ChannelTest.php index 457151b..ff9f4da 100644 --- a/tests/Rest/ChannelTest.php +++ b/tests/Rest/ChannelTest.php @@ -323,6 +323,7 @@ public static function httpBindingsProvider(): array 'validationOptions' => [ 'returnType' => User::class, 'array' => true, + 'url' => 'channels/::channel id::/messages/::message id::/reactions/%3A%3Aid%3A%3A', ] ], 'Delete all reactions' => [ diff --git a/tests/Rest/HttpHelperTestCase.php b/tests/Rest/HttpHelperTestCase.php index 272fa42..eff051a 100644 --- a/tests/Rest/HttpHelperTestCase.php +++ b/tests/Rest/HttpHelperTestCase.php @@ -47,16 +47,34 @@ abstract public static function httpBindingsProvider(): array; #[DataProvider('httpBindingsProvider')] public function testFunctions(string $method, array $args, array $mockOptions, array $validationOptions): void { - $this->http->shouldReceive($mockOptions['method'])->andReturns( - new Promise(static function ($resolve) use ($mockOptions) { - $resolve($mockOptions['return']); + $requestedUrl = null; + + $this->http->shouldReceive($mockOptions['method']) + ->withArgs(static function ($url, ...$rest) use (&$requestedUrl) { + $requestedUrl = (string) $url; + + return true; }) - )->once(); + ->andReturns( + new Promise(static function ($resolve) use ($mockOptions) { + $resolve($mockOptions['return']); + }) + )->once(); $response = await(call_user_func_array([$this->httpItem, $method], $args)); $this->http->shouldHaveReceived($mockOptions['method']); + /* + * Optional, and worth filling in: nothing here checked which endpoint a + * method actually called, so a method binding the wrong Endpoint + * constant passed its test while never once reaching the route it was + * named after. + */ + if (isset($validationOptions['url'])) { + $this->assertSame($validationOptions['url'], $requestedUrl); + } + if (!isset($validationOptions['returnType'])) { return; }