From 86db5052deb312c2ae9ca3d46de562c8d6b64fb2 Mon Sep 17 00:00:00 2001 From: Daif Date: Mon, 12 Dec 2022 17:16:30 +0100 Subject: [PATCH] CardsV1 is deprecated we must use cardsV2 instead. Based on google developers api documentation. https://developers.google.com/chat/api/reference/rest/v1/cards-v1 CardsV1 is deprecated we must use cardsV2 instead. --- .../Notifier/Bridge/GoogleChat/CHANGELOG.md | 5 +++ .../Bridge/GoogleChat/GoogleChatOptions.php | 14 ++++++ .../Tests/GoogleChatOptionsTest.php | 44 +++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md b/src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md index 5759f578770fe..c01ece62d544a 100644 --- a/src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md +++ b/src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +6.3 +--- + + * Deprecate `GoogleChatOptions::card()` in favor of `cardV2()` + 5.3 --- diff --git a/src/Symfony/Component/Notifier/Bridge/GoogleChat/GoogleChatOptions.php b/src/Symfony/Component/Notifier/Bridge/GoogleChat/GoogleChatOptions.php index da479d1311a93..0550d725a0d6c 100644 --- a/src/Symfony/Component/Notifier/Bridge/GoogleChat/GoogleChatOptions.php +++ b/src/Symfony/Component/Notifier/Bridge/GoogleChat/GoogleChatOptions.php @@ -62,15 +62,29 @@ public function toArray(): array } /** + * @deprecated since Symfony 6.3, use "cardV2()" instead + * * @return $this */ public function card(array $card): static { + trigger_deprecation('symfony/google-chat-notifier', '6.3', '"%s()" is deprecated, use "cardV2()" instead.', __METHOD__); + $this->options['cards'][] = $card; return $this; } + /** + * @return $this + */ + public function cardV2(array $card): static + { + $this->options['cardsV2'][] = $card; + + return $this; + } + /** * @return $this */ diff --git a/src/Symfony/Component/Notifier/Bridge/GoogleChat/Tests/GoogleChatOptionsTest.php b/src/Symfony/Component/Notifier/Bridge/GoogleChat/Tests/GoogleChatOptionsTest.php index 691958c46a079..00984a60044c9 100644 --- a/src/Symfony/Component/Notifier/Bridge/GoogleChat/Tests/GoogleChatOptionsTest.php +++ b/src/Symfony/Component/Notifier/Bridge/GoogleChat/Tests/GoogleChatOptionsTest.php @@ -16,6 +16,9 @@ final class GoogleChatOptionsTest extends TestCase { + /** + * @group legacy + */ public function testToArray() { $options = new GoogleChatOptions(); @@ -34,6 +37,47 @@ public function testToArray() $this->assertSame($expected, $options->toArray()); } + public function testToArrayWithCardV2() + { + $options = new GoogleChatOptions(); + + $cardV2 = [ + 'header' => [ + 'title' => 'Sasha', + 'subtitle' => 'Software Engineer', + 'imageUrl' => 'https://developers.google.com/chat/images/quickstart-app-avatar.png', + 'imageType' => 'CIRCLE', + 'imageAltText' => 'Avatar for Sasha', + ], + 'sections' => [ + [ + 'header' => 'Contact Info', + 'collapsible' => true, + 'widgets' => [ + 'decoratedText' => [ + 'startIcon' => ['knownIcon' => 'EMAIL'], + 'text' => 'sasha@example.com', + ], + ], + ], + ], + ]; + + $options + ->text('Hello Bot') + ->cardV2($cardV2) + ; + + $expected = [ + 'text' => 'Hello Bot', + 'cardsV2' => [ + $cardV2, + ], + ]; + + $this->assertSame($expected, $options->toArray()); + } + public function testOptionsWithThread() { $thread = 'fgh.ijk';