From 1f674498e7f64f763cfc9bd76b9025fe9482abe6 Mon Sep 17 00:00:00 2001 From: med-dz <204789577+med-dz@users.noreply.github.com> Date: Fri, 27 Nov 2026 21:20:42 +0100 Subject: [PATCH] fix: check Slack response bodies --- contrib/slack.php | 2 +- tests/src/Contrib/SlackTest.php | 53 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/src/Contrib/SlackTest.php diff --git a/contrib/slack.php b/contrib/slack.php index cf87f5257..733aec8a9 100644 --- a/contrib/slack.php +++ b/contrib/slack.php @@ -89,7 +89,7 @@ function checkSlackAnswer(mixed $result): bool { - if ('invalid_token' === $result) { + if ('invalid_token' === (string) $result) { warning('Invalid Slack token'); return false; } diff --git a/tests/src/Contrib/SlackTest.php b/tests/src/Contrib/SlackTest.php new file mode 100644 index 000000000..d3500ad71 --- /dev/null +++ b/tests/src/Contrib/SlackTest.php @@ -0,0 +1,53 @@ +output = new BufferedOutput(); + $deployer['output'] = $this->output; + + require_once __DIR__ . '/../../../contrib/slack.php'; + } + + public function testRejectsInvalidTokenResponse(): void + { + self::assertFalse(checkSlackAnswer(new HttpResponse('invalid_token', ['http_code' => 403]))); + self::assertStringContainsString('Invalid Slack token', $this->output->fetch()); + } + + public function testAcceptsSuccessfulResponse(): void + { + self::assertTrue(checkSlackAnswer(new HttpResponse('ok', ['http_code' => 200]))); + self::assertSame('', $this->output->fetch()); + } + + public function testRejectsInvalidTokenString(): void + { + self::assertFalse(checkSlackAnswer('invalid_token')); + self::assertStringContainsString('Invalid Slack token', $this->output->fetch()); + } + + public function testAcceptsSuccessfulString(): void + { + self::assertTrue(checkSlackAnswer('ok')); + self::assertSame('', $this->output->fetch()); + } +}