66
77use Keboola \NotificationClient \Requests \PostSubscription \EmailRecipient ;
88use Keboola \NotificationClient \Requests \PostSubscription \Filter ;
9+ use Keboola \NotificationClient \Requests \PostSubscription \RecipientInterface ;
10+ use Keboola \NotificationClient \Requests \PostSubscription \WebhookRecipient ;
911use Keboola \NotificationClient \Requests \Subscription ;
1012use PHPUnit \Framework \TestCase ;
1113
1214class SubscriptionTest extends TestCase
1315{
14- public function testJsonSerialize (): void
16+ public function recipientProvider (): iterable
17+ {
18+ yield 'email ' => [
19+ new EmailRecipient ('john.doe@example.com ' ),
20+ [
21+ 'channel ' => 'email ' ,
22+ 'address ' => 'john.doe@example.com ' ,
23+ ],
24+ ];
25+
26+ yield 'webhook ' => [
27+ new WebhookRecipient ('https://example.com/webhook ' ),
28+ [
29+ 'channel ' => 'webhook ' ,
30+ 'url ' => 'https://example.com/webhook ' ,
31+ ],
32+ ];
33+ }
34+
35+
36+ /** @dataProvider recipientProvider */
37+ public function testJsonSerialize (RecipientInterface $ recipient , array $ expectedRecipient ): void
1538 {
1639 $ subscriptionRequest = new Subscription (
1740 'job-failed ' ,
18- new EmailRecipient ( ' john.doe@example.com ' ) ,
41+ $ recipient ,
1942 [new Filter ('foo ' , 'bar ' )],
2043 );
2144 self ::assertSame (
@@ -27,20 +50,18 @@ public function testJsonSerialize(): void
2750 'value ' => 'bar ' ,
2851 ],
2952 ],
30- 'recipient ' => [
31- 'channel ' => 'email ' ,
32- 'address ' => 'john.doe@example.com ' ,
33- ],
53+ 'recipient ' => $ expectedRecipient ,
3454 ],
3555 $ subscriptionRequest ->jsonSerialize (),
3656 );
3757 }
3858
39- public function testJsonSerializeStrangeFilters (): void
59+ /** @dataProvider recipientProvider */
60+ public function testJsonSerializeStrangeFilters (RecipientInterface $ recipient , array $ expectedRecipient ): void
4061 {
4162 $ subscriptionRequest = new Subscription (
4263 'job-failed ' ,
43- new EmailRecipient ( ' john.doe@example.com ' ) ,
64+ $ recipient ,
4465 ['a ' => new Filter ('foo ' , 'bar ' ), '4filter ' => new Filter ('bar ' , 'Kochba ' )],
4566 );
4667 self ::assertSame (
@@ -56,20 +77,18 @@ public function testJsonSerializeStrangeFilters(): void
5677 'value ' => 'Kochba ' ,
5778 ],
5879 ],
59- 'recipient ' => [
60- 'channel ' => 'email ' ,
61- 'address ' => 'john.doe@example.com ' ,
62- ],
80+ 'recipient ' => $ expectedRecipient ,
6381 ],
6482 $ subscriptionRequest ->jsonSerialize (),
6583 );
6684 }
6785
68- public function testPhaseJobFailedSubscription (): void
86+ /** @dataProvider recipientProvider */
87+ public function testPhaseJobFailedSubscription (RecipientInterface $ recipient , array $ expectedRecipient ): void
6988 {
7089 $ subscriptionRequest = new Subscription (
7190 'phase-job-failed ' ,
72- new EmailRecipient ( ' john.doe@example.com ' ) ,
91+ $ recipient ,
7392 [
7493 new Filter ('job.component.id ' , 'my.component ' ),
7594 new Filter ('job.configuration.id ' , '12345 ' ),
@@ -93,20 +112,20 @@ public function testPhaseJobFailedSubscription(): void
93112 'value ' => '123 ' ,
94113 ],
95114 ],
96- 'recipient ' => [
97- 'channel ' => 'email ' ,
98- 'address ' => 'john.doe@example.com ' ,
99- ],
115+ 'recipient ' => $ expectedRecipient ,
100116 ],
101117 $ subscriptionRequest ->jsonSerialize (),
102118 );
103119 }
104120
105- public function testPhaseJobSucceededWithWarningSubscription (): void
106- {
121+ /** @dataProvider recipientProvider */
122+ public function testPhaseJobSucceededWithWarningSubscription (
123+ RecipientInterface $ recipient ,
124+ array $ expectedRecipient
125+ ): void {
107126 $ subscriptionRequest = new Subscription (
108127 'phase-job-succeeded-with-warning ' ,
109- new EmailRecipient ( ' john.doe@example.com ' ) ,
128+ $ recipient ,
110129 [
111130 new Filter ('job.component.id ' , 'my.component ' ),
112131 new Filter ('job.configuration.id ' , '12345 ' ),
@@ -130,20 +149,18 @@ public function testPhaseJobSucceededWithWarningSubscription(): void
130149 'value ' => '123 ' ,
131150 ],
132151 ],
133- 'recipient ' => [
134- 'channel ' => 'email ' ,
135- 'address ' => 'john.doe@example.com ' ,
136- ],
152+ 'recipient ' => $ expectedRecipient ,
137153 ],
138154 $ subscriptionRequest ->jsonSerialize (),
139155 );
140156 }
141157
142- public function testJobSucceededSubscription (): void
158+ /** @dataProvider recipientProvider */
159+ public function testJobSucceededSubscription (RecipientInterface $ recipient , array $ expectedRecipient ): void
143160 {
144161 $ subscriptionRequest = new Subscription (
145162 'job-succeeded ' ,
146- new EmailRecipient ( ' john.doe@example.com ' ) ,
163+ $ recipient ,
147164 [
148165 new Filter ('job.component.id ' , 'my.component ' ),
149166 new Filter ('job.configuration.id ' , '12345 ' ),
@@ -163,20 +180,18 @@ public function testJobSucceededSubscription(): void
163180 'value ' => '12345 ' ,
164181 ],
165182 ],
166- 'recipient ' => [
167- 'channel ' => 'email ' ,
168- 'address ' => 'john.doe@example.com ' ,
169- ],
183+ 'recipient ' => $ expectedRecipient ,
170184 ],
171185 $ subscriptionRequest ->jsonSerialize (),
172186 );
173187 }
174188
175- public function testPhaseJobSucceededSubscription (): void
189+ /** @dataProvider recipientProvider */
190+ public function testPhaseJobSucceededSubscription (RecipientInterface $ recipient , array $ expectedRecipient ): void
176191 {
177192 $ subscriptionRequest = new Subscription (
178193 'phase-job-succeeded ' ,
179- new EmailRecipient ( ' john.doe@example.com ' ) ,
194+ $ recipient ,
180195 [
181196 new Filter ('job.component.id ' , 'my.component ' ),
182197 new Filter ('job.configuration.id ' , '12345 ' ),
@@ -201,20 +216,20 @@ public function testPhaseJobSucceededSubscription(): void
201216 'value ' => '123 ' ,
202217 ],
203218 ],
204- 'recipient ' => [
205- 'channel ' => 'email ' ,
206- 'address ' => 'john.doe@example.com ' ,
207- ],
219+ 'recipient ' => $ expectedRecipient ,
208220 ],
209221 $ subscriptionRequest ->jsonSerialize (),
210222 );
211223 }
212224
213- public function testPhaseJobProcessingLongSubscription (): void
214- {
225+ /** @dataProvider recipientProvider */
226+ public function testPhaseJobProcessingLongSubscription (
227+ RecipientInterface $ recipient ,
228+ array $ expectedRecipient
229+ ): void {
215230 $ subscriptionRequest = new Subscription (
216231 'phase-job-processing-long ' ,
217- new EmailRecipient ( ' john.doe@example.com ' ) ,
232+ $ recipient ,
218233 [
219234 new Filter ('job.component.id ' , 'my.component ' ),
220235 new Filter ('job.configuration.id ' , '12345 ' ),
@@ -238,10 +253,7 @@ public function testPhaseJobProcessingLongSubscription(): void
238253 'value ' => '123 ' ,
239254 ],
240255 ],
241- 'recipient ' => [
242- 'channel ' => 'email ' ,
243- 'address ' => 'john.doe@example.com ' ,
244- ],
256+ 'recipient ' => $ expectedRecipient ,
245257 ],
246258 $ subscriptionRequest ->jsonSerialize (),
247259 );
0 commit comments