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 committed Dec 16, 2022
1 parent 233b9eb commit 61fe05e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,28 @@ 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', '"card()" is deprecated and can be removed, use "cardV2()" instead.');
$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,7 +16,7 @@

final class GoogleChatOptionsTest extends TestCase
{
public function testToArray()
public function testToArray(): void
{
$options = new GoogleChatOptions();

Expand All @@ -34,7 +34,48 @@ public function testToArray()
$this->assertSame($expected, $options->toArray());
}

public function testOptionsWithThread()
public function testToArrayWithCardV2(): void
{
$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(): void
{
$thread = 'fgh.ijk';
$options = new GoogleChatOptions();
Expand Down

0 comments on commit 61fe05e

Please sign in to comment.