-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubscriptionTest.php
More file actions
100 lines (91 loc) · 3.49 KB
/
SubscriptionTest.php
File metadata and controls
100 lines (91 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
declare(strict_types=1);
namespace Keboola\NotificationClient\Tests\Responses;
use Keboola\NotificationClient\Exception\ClientException;
use Keboola\NotificationClient\Responses\Recipient\EmailRecipient;
use Keboola\NotificationClient\Responses\Recipient\WebhookRecipient;
use Keboola\NotificationClient\Responses\Subscription;
use PHPUnit\Framework\TestCase;
class SubscriptionTest extends TestCase
{
public function testEmailRecipientAccessors(): void
{
$data = [
'id' => '123',
'event' => 'some_event',
'recipient' => [
'channel' => 'email',
'address' => 'john.doe@example.com',
],
'filters' => [
2 => [
'field' => 'bar',
'value' => 'Kochba',
],
],
];
$subscription = new Subscription($data);
self::assertSame('123', $subscription->getId());
self::assertSame('some_event', $subscription->getEvent());
self::assertSame('email', $subscription->getRecipientChannel());
self::assertSame('john.doe@example.com', $subscription->getRecipientAddress());
self::assertCount(1, $subscription->getFilters());
self::assertSame('bar', $subscription->getFilters()[0]->getField());
self::assertSame('Kochba', $subscription->getFilters()[0]->getValue());
$recipient = $subscription->getRecipient();
self::assertInstanceOf(EmailRecipient::class, $recipient);
self::assertSame('email', $recipient->getChannel());
self::assertSame('john.doe@example.com', $recipient->getAddress());
}
public function testWebhookRecipientAccessors(): void
{
$data = [
'id' => '29746',
'event' => 'job-succeeded',
'recipient' => [
'channel' => 'webhook',
'url' => 'https://asd.as',
],
'filters' => [],
];
$subscription = new Subscription($data);
self::assertSame('29746', $subscription->getId());
self::assertSame('job-succeeded', $subscription->getEvent());
self::assertSame('webhook', $subscription->getRecipientChannel());
self::assertNull($subscription->getRecipientAddress());
self::assertSame([], $subscription->getFilters());
$recipient = $subscription->getRecipient();
self::assertInstanceOf(WebhookRecipient::class, $recipient);
self::assertSame('webhook', $recipient->getChannel());
self::assertSame('https://asd.as', $recipient->getUrl());
}
public function testUnknownChannelThrows(): void
{
$data = [
'id' => '1',
'event' => 'some_event',
'recipient' => [
'channel' => 'boo',
'address' => 'foo',
],
'filters' => [],
];
$this->expectException(ClientException::class);
$this->expectExceptionMessageMatches('#Unrecognized response:.*?boo#');
$this->expectExceptionCode(0);
new Subscription($data);
}
public function testInvalidData(): void
{
$data = [
'id' => 123,
'event' => 'some_event',
];
$this->expectException(ClientException::class);
$this->expectExceptionMessageMatches(
'#Unrecognized response:.*?(\$id must be string, int used|\$id of type string)#',
);
$this->expectExceptionCode(0);
new Subscription($data);
}
}