@@ -33,7 +33,7 @@ class PushServiceTest extends PHPUnit_Framework_TestCase
33
33
* detect current OS, we can probably run this automatically
34
34
* for Linux and OS X at a later date.
35
35
*/
36
- /** protected function checkRequirements()
36
+ /**protected function checkRequirements()
37
37
{
38
38
parent::checkRequirements();
39
39
@@ -104,12 +104,37 @@ public function browserProvider()
104
104
);
105
105
}
106
106
107
+ /**
108
+ * Selenium tests are flakey so add retries.
109
+ */
110
+ public function retryTest ($ retryCount , $ test )
111
+ {
112
+ // just like above without checking the annotation
113
+ for ($ i = 0 ; $ i < $ retryCount ; $ i ++) {
114
+ try {
115
+ $ test ();
116
+ return ;
117
+ }
118
+ catch (Exception $ e ) {
119
+ // last one thrown below
120
+ }
121
+ }
122
+ if ($ e ) {
123
+ throw $ e ;
124
+ }
125
+ }
126
+
107
127
/**
108
128
* @dataProvider browserProvider
109
129
* Run integration tests with browsers
110
130
*/
111
131
public function testBrowsers ($ browserId , $ browserVersion , $ options )
112
132
{
133
+ $ this ->retryTest (4 , $ this ->createClosureTest ($ browserId , $ browserVersion , $ options ));
134
+ }
135
+
136
+ protected function createClosureTest ($ browserId , $ browserVersion , $ options ) {
137
+ return function () use ($ browserId , $ browserVersion , $ options ) {
113
138
$ this ->webPush = new WebPush ($ options );
114
139
$ this ->webPush ->setAutomaticPadding (false );
115
140
@@ -140,14 +165,23 @@ public function testBrowsers($browserId, $browserVersion, $options)
140
165
),
141
166
CURLOPT_TIMEOUT => 30 ,
142
167
));
143
-
144
168
$ resp = curl_exec ($ getSubscriptionCurl );
145
169
146
170
// Close request to clear up some resources
147
171
curl_close ($ getSubscriptionCurl );
148
172
149
173
$ parsedResp = json_decode ($ resp );
150
174
175
+
176
+
177
+ if (!array_key_exists ('data ' , $ parsedResp )) {
178
+ echo "\n\n" ;
179
+ echo "Unexpected response from web-push-testing-service............. " ;
180
+ var_dump ($ resp );
181
+ echo "\n\n" ;
182
+ throw new Error ('Unexpected response from web-push-testing-service. ' );
183
+ }
184
+
151
185
$ testId = $ parsedResp ->{'data ' }->{'testId ' };
152
186
$ subscription = $ parsedResp ->{'data ' }->{'subscription ' };
153
187
$ endpoint = $ subscription ->{'endpoint ' };
@@ -201,6 +235,7 @@ public function testBrowsers($browserId, $browserVersion, $options)
201
235
throw $ e ;
202
236
}
203
237
}
238
+ };
204
239
}
205
240
206
241
protected function tearDown ()
0 commit comments