Skip to content

Commit

Permalink
CardsV1 is deprecated we must use cardsV2 instead.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
daifma authored and nicolas-grekas committed Dec 22, 2022
1 parent 233b9eb commit 86db505
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.3
---

* Deprecate `GoogleChatOptions::card()` in favor of `cardV2()`

5.3
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

final class GoogleChatOptionsTest extends TestCase
{
/**
* @group legacy
*/
public function testToArray()
{
$options = new GoogleChatOptions();
Expand All @@ -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';
Expand Down

0 comments on commit 86db505

Please sign in to comment.