@@ -18,9 +18,8 @@ final class PushServiceTest extends PHPUnit\Framework\TestCase
1818{
1919 private static $ timeout = 30 ;
2020 private static $ portNumber = 9012 ;
21- private static $ testSuiteId ;
2221 private static $ testServiceUrl ;
23- private static $ vapidKeys = [
22+ public static $ vapidKeys = [
2423 'subject ' => 'http://test.com ' ,
2524 'publicKey ' => 'BA6jvk34k6YjElHQ6S0oZwmrsqHdCNajxcod6KJnI77Dagikfb--O_kYXcR2eflRz6l3PcI2r8fPCH3BElLQHDk ' ,
2625 'privateKey ' => '-3CdhFOqjzixgAbUSa0Zv9zi-dwDVmWO7672aBxSFPQ ' ,
@@ -37,34 +36,13 @@ public static function setUpBeforeClass(): void
3736 self ::$ testServiceUrl = 'http://localhost: ' .self ::$ portNumber ;
3837 }
3938
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-
6139 public function browserProvider ()
6240 {
6341 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 ' , [ ]],
6846 ];
6947 }
7048
@@ -92,30 +70,25 @@ public function retryTest($retryCount, $test)
9270 * @dataProvider browserProvider
9371 * Run integration tests with browsers
9472 */
95- public function testBrowsers ($ browserId , $ browserVersion , $ options )
73+ public function testBrowsers ($ browserId , $ options )
9674 {
97- $ this ->retryTest (2 , $ this ->createClosureTest ($ browserId , $ browserVersion , $ options ));
75+ $ this ->retryTest (2 , $ this ->createClosureTest ($ browserId , $ options ));
9876 }
9977
100- protected function createClosureTest ($ browserId , $ browserVersion , $ options )
78+ protected function createClosureTest ($ browserId , $ options )
10179 {
102- return function () use ($ browserId , $ browserVersion , $ options ) {
80+ return function () use ($ browserId , $ options ) {
10381 $ this ->webPush = new WebPush ($ options );
10482 $ this ->webPush ->setAutomaticPadding (false );
105-
106- $ subscriptionParameters = [
107- 'testSuiteId ' => self ::$ testSuiteId ,
108- 'browserName ' => $ browserId ,
109- 'browserVersion ' => $ browserVersion ,
110- ];
83+ $ subscriptionParameters = [];
11184
11285 if (array_key_exists ('VAPID ' , $ options )) {
113- $ subscriptionParameters ['vapidPublicKey ' ] = self ::$ vapidKeys ['publicKey ' ];
86+ $ subscriptionParameters ['applicationServerKey ' ] = self ::$ vapidKeys ['publicKey ' ];
11487 }
11588
11689 $ subscriptionParameters = json_encode ($ subscriptionParameters , JSON_THROW_ON_ERROR );
11790
118- $ getSubscriptionCurl = curl_init (self ::$ testServiceUrl .'/api/get-subscription/ ' );
91+ $ getSubscriptionCurl = curl_init (self ::$ testServiceUrl .'/subscribe ' );
11992 curl_setopt_array ($ getSubscriptionCurl , [
12093 CURLOPT_POST => true ,
12194 CURLOPT_POSTFIELDS => $ subscriptionParameters ,
@@ -128,18 +101,17 @@ protected function createClosureTest($browserId, $browserVersion, $options)
128101 ]);
129102
130103 $ parsedResp = $ this ->getResponse ($ getSubscriptionCurl );
131- $ testId = $ parsedResp ->{'data ' }->{'testId ' };
132- $ subscription = $ parsedResp ->{'data ' }->{'subscription ' };
104+ $ subscription = $ parsedResp ->{'data ' };
133105
134- $ supportedContentEncodings = property_exists ($ subscription , 'supportedContentEncodings ' ) ?
135- $ subscription ->{'supportedContentEncodings ' } :
136- ["aesgcm " ];
106+ $ supportedContentEncodings = ['aesgcm ' , 'aes128gcm ' ];
137107
138108 $ endpoint = $ subscription ->{'endpoint ' };
139109 $ keys = $ subscription ->{'keys ' };
140110 $ auth = $ keys ->{'auth ' };
141111 $ p256dh = $ keys ->{'p256dh ' };
112+ $ clientHash = $ subscription ->{'clientHash ' };
142113 $ payload = 'hello ' ;
114+ $ messageIndex = 0 ;
143115
144116 foreach ($ supportedContentEncodings as $ contentEncoding ) {
145117 if (!in_array ($ contentEncoding , ['aesgcm ' , 'aes128gcm ' ])) {
@@ -150,16 +122,14 @@ protected function createClosureTest($browserId, $browserVersion, $options)
150122
151123 $ subscription = new Subscription ($ endpoint , $ p256dh , $ auth , $ contentEncoding );
152124 $ report = $ this ->webPush ->sendOneNotification ($ subscription , $ payload );
153- $ this ->assertInstanceOf (\Generator::class, $ report );
154125 $ this ->assertInstanceOf (\Minishlink \WebPush \MessageSentReport::class, $ report );
155126 $ this ->assertTrue ($ report ->isSuccess ());
156127
157128 $ dataString = json_encode ([
158- 'testSuiteId ' => self ::$ testSuiteId ,
159- 'testId ' => $ testId ,
160- ], JSON_THROW_ON_ERROR );
129+ 'clientHash ' => $ clientHash ,
130+ ]);
161131
162- $ getNotificationCurl = curl_init (self ::$ testServiceUrl .'/api/ get-notification-status/ ' );
132+ $ getNotificationCurl = curl_init (self ::$ testServiceUrl .'/get-notifications ' );
163133 curl_setopt_array ($ getNotificationCurl , [
164134 CURLOPT_POST => true ,
165135 CURLOPT_POSTFIELDS => $ dataString ,
@@ -174,39 +144,16 @@ protected function createClosureTest($browserId, $browserVersion, $options)
174144 $ parsedResp = $ this ->getResponse ($ getNotificationCurl );
175145
176146 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 ));
178148 }
179149
180150 $ 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 );
183153 }
184154 };
185155 }
186156
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-
210157 private function getResponse ($ ch )
211158 {
212159 $ resp = curl_exec ($ ch );
0 commit comments