@@ -18,9 +18,8 @@ final class PushServiceTest extends PHPUnit\Framework\TestCase
18
18
{
19
19
private static $ timeout = 30 ;
20
20
private static $ portNumber = 9012 ;
21
- private static $ testSuiteId ;
22
21
private static $ testServiceUrl ;
23
- private static $ vapidKeys = [
22
+ public static $ vapidKeys = [
24
23
'subject ' => 'http://test.com ' ,
25
24
'publicKey ' => 'BA6jvk34k6YjElHQ6S0oZwmrsqHdCNajxcod6KJnI77Dagikfb--O_kYXcR2eflRz6l3PcI2r8fPCH3BElLQHDk ' ,
26
25
'privateKey ' => '-3CdhFOqjzixgAbUSa0Zv9zi-dwDVmWO7672aBxSFPQ ' ,
@@ -37,34 +36,13 @@ public static function setUpBeforeClass(): void
37
36
self ::$ testServiceUrl = 'http://localhost: ' .self ::$ portNumber ;
38
37
}
39
38
40
- /**
41
- * {@inheritdoc}
42
- */
43
- protected function setUp (): void
44
- {
45
- if (!(getenv ('TRAVIS ' ) || getenv ('CI ' ))) {
46
- $ this ->markTestSkipped ('This test does not run on Travis. ' );
47
- }
48
-
49
- $ startApiCurl = curl_init (self ::$ testServiceUrl .'/api/start-test-suite/ ' );
50
- curl_setopt_array ($ startApiCurl , [
51
- CURLOPT_POST => true ,
52
- CURLOPT_POSTFIELDS => [],
53
- CURLOPT_RETURNTRANSFER => true ,
54
- CURLOPT_TIMEOUT => self ::$ timeout ,
55
- ]);
56
-
57
- $ parsedResp = $ this ->getResponse ($ startApiCurl );
58
- self ::$ testSuiteId = $ parsedResp ->{'data ' }->{'testSuiteId ' };
59
- }
60
-
61
39
public function browserProvider ()
62
40
{
63
41
return [
64
- ['firefox ' , ' stable ' , ['VAPID ' => self ::$ vapidKeys ]],
65
- ['firefox ' , ' beta ' , ['VAPID ' => self ::$ vapidKeys ]],
66
- ['chrome ' , ' stable ' , [ ' VAPID ' => self :: $ vapidKeys ]],
67
- ['chrome ' , ' beta ' , [ ' VAPID ' => self :: $ vapidKeys ]],
42
+ ['firefox ' , ['VAPID ' => self ::$ vapidKeys ]],
43
+ ['chrome ' , ['VAPID ' => self ::$ vapidKeys ]],
44
+ ['firefox ' , [ ]],
45
+ ['chrome ' , [ ]],
68
46
];
69
47
}
70
48
@@ -92,30 +70,25 @@ public function retryTest($retryCount, $test)
92
70
* @dataProvider browserProvider
93
71
* Run integration tests with browsers
94
72
*/
95
- public function testBrowsers ($ browserId , $ browserVersion , $ options )
73
+ public function testBrowsers ($ browserId , $ options )
96
74
{
97
- $ this ->retryTest (2 , $ this ->createClosureTest ($ browserId , $ browserVersion , $ options ));
75
+ $ this ->retryTest (2 , $ this ->createClosureTest ($ browserId , $ options ));
98
76
}
99
77
100
- protected function createClosureTest ($ browserId , $ browserVersion , $ options )
78
+ protected function createClosureTest ($ browserId , $ options )
101
79
{
102
- return function () use ($ browserId , $ browserVersion , $ options ) {
80
+ return function () use ($ browserId , $ options ) {
103
81
$ this ->webPush = new WebPush ($ options );
104
82
$ this ->webPush ->setAutomaticPadding (false );
105
-
106
- $ subscriptionParameters = [
107
- 'testSuiteId ' => self ::$ testSuiteId ,
108
- 'browserName ' => $ browserId ,
109
- 'browserVersion ' => $ browserVersion ,
110
- ];
83
+ $ subscriptionParameters = [];
111
84
112
85
if (array_key_exists ('VAPID ' , $ options )) {
113
- $ subscriptionParameters ['vapidPublicKey ' ] = self ::$ vapidKeys ['publicKey ' ];
86
+ $ subscriptionParameters ['applicationServerKey ' ] = self ::$ vapidKeys ['publicKey ' ];
114
87
}
115
88
116
89
$ subscriptionParameters = json_encode ($ subscriptionParameters , JSON_THROW_ON_ERROR );
117
90
118
- $ getSubscriptionCurl = curl_init (self ::$ testServiceUrl .'/api/get-subscription/ ' );
91
+ $ getSubscriptionCurl = curl_init (self ::$ testServiceUrl .'/subscribe ' );
119
92
curl_setopt_array ($ getSubscriptionCurl , [
120
93
CURLOPT_POST => true ,
121
94
CURLOPT_POSTFIELDS => $ subscriptionParameters ,
@@ -128,18 +101,17 @@ protected function createClosureTest($browserId, $browserVersion, $options)
128
101
]);
129
102
130
103
$ parsedResp = $ this ->getResponse ($ getSubscriptionCurl );
131
- $ testId = $ parsedResp ->{'data ' }->{'testId ' };
132
- $ subscription = $ parsedResp ->{'data ' }->{'subscription ' };
104
+ $ subscription = $ parsedResp ->{'data ' };
133
105
134
- $ supportedContentEncodings = property_exists ($ subscription , 'supportedContentEncodings ' ) ?
135
- $ subscription ->{'supportedContentEncodings ' } :
136
- ["aesgcm " ];
106
+ $ supportedContentEncodings = ['aesgcm ' , 'aes128gcm ' ];
137
107
138
108
$ endpoint = $ subscription ->{'endpoint ' };
139
109
$ keys = $ subscription ->{'keys ' };
140
110
$ auth = $ keys ->{'auth ' };
141
111
$ p256dh = $ keys ->{'p256dh ' };
112
+ $ clientHash = $ subscription ->{'clientHash ' };
142
113
$ payload = 'hello ' ;
114
+ $ messageIndex = 0 ;
143
115
144
116
foreach ($ supportedContentEncodings as $ contentEncoding ) {
145
117
if (!in_array ($ contentEncoding , ['aesgcm ' , 'aes128gcm ' ])) {
@@ -150,16 +122,14 @@ protected function createClosureTest($browserId, $browserVersion, $options)
150
122
151
123
$ subscription = new Subscription ($ endpoint , $ p256dh , $ auth , $ contentEncoding );
152
124
$ report = $ this ->webPush ->sendOneNotification ($ subscription , $ payload );
153
- $ this ->assertInstanceOf (\Generator::class, $ report );
154
125
$ this ->assertInstanceOf (\Minishlink \WebPush \MessageSentReport::class, $ report );
155
126
$ this ->assertTrue ($ report ->isSuccess ());
156
127
157
128
$ dataString = json_encode ([
158
- 'testSuiteId ' => self ::$ testSuiteId ,
159
- 'testId ' => $ testId ,
160
- ], JSON_THROW_ON_ERROR );
129
+ 'clientHash ' => $ clientHash ,
130
+ ]);
161
131
162
- $ getNotificationCurl = curl_init (self ::$ testServiceUrl .'/api/ get-notification-status/ ' );
132
+ $ getNotificationCurl = curl_init (self ::$ testServiceUrl .'/get-notifications ' );
163
133
curl_setopt_array ($ getNotificationCurl , [
164
134
CURLOPT_POST => true ,
165
135
CURLOPT_POSTFIELDS => $ dataString ,
@@ -174,39 +144,16 @@ protected function createClosureTest($browserId, $browserVersion, $options)
174
144
$ parsedResp = $ this ->getResponse ($ getNotificationCurl );
175
145
176
146
if (!property_exists ($ parsedResp ->{'data ' }, 'messages ' )) {
177
- throw new Exception ('web-push-testing-service error, no messages: ' .json_encode ($ parsedResp, JSON_THROW_ON_ERROR ));
147
+ throw new Exception ('web-push-testing error, no messages: ' .json_encode ($ parsedResp ));
178
148
}
179
149
180
150
$ messages = $ parsedResp ->{'data ' }->{'messages ' };
181
- $ this ->assertEquals (1 , is_countable ( $ messages) ? count ( $ messages ) : 0 );
182
- $ this ->assertEquals ( $ payload , $ messages[ 0 ] );
151
+ $ this ->assertEquals ($ payload , $ messages[ $ messageIndex ] );
152
+ $ this ->assertCount (++ $ messageIndex , $ messages );
183
153
}
184
154
};
185
155
}
186
156
187
- protected function tearDown (): void
188
- {
189
- $ dataString = '{ "testSuiteId": ' .self ::$ testSuiteId .' } ' ;
190
- $ curl = curl_init (self ::$ testServiceUrl .'/api/end-test-suite/ ' );
191
- curl_setopt_array ($ curl , [
192
- CURLOPT_POST => true ,
193
- CURLOPT_POSTFIELDS => $ dataString ,
194
- CURLOPT_RETURNTRANSFER => true ,
195
- CURLOPT_HTTPHEADER => [
196
- 'Content-Type: application/json ' ,
197
- 'Content-Length: ' .strlen ($ dataString ),
198
- ],
199
- CURLOPT_TIMEOUT => self ::$ timeout ,
200
- ]);
201
- $ this ->getResponse ($ curl );
202
- self ::$ testSuiteId = null ;
203
- }
204
-
205
- public static function tearDownAfterClass (): void
206
- {
207
- exec ('web-push-testing-service stop phpunit ' );
208
- }
209
-
210
157
private function getResponse ($ ch )
211
158
{
212
159
$ resp = curl_exec ($ ch );
0 commit comments