Skip to content

Commit 1972c51

Browse files
committed
Fix test from randomly failing by a milisecond
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent 5b8be89 commit 1972c51

1 file changed

Lines changed: 35 additions & 12 deletions

File tree

tests/event/listener_test.php

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function get_ucp_template_data_data()
188188
'method_data' => [
189189
'id' => 'notification.method.phpbb.wpn.webpush',
190190
],
191-
[['endpoint' => 'https://web.push.test.localhost/foo2', 'expirationTime' => 0]],
191+
[['endpoint' => 'https://web.push.test.localhost/foo2', 'expirationTime' => '0']],
192192
true,
193193
],
194194
[ // wrong method, but with a valid webpush subscription, expect no code execution
@@ -204,7 +204,7 @@ public function get_ucp_template_data_data()
204204
'method_data' => [
205205
'id' => 'notification.method.phpbb.wpn.webpush',
206206
],
207-
[['endpoint' => 'https://web.push.test.localhost/foo3', 'expirationTime' => 1]],
207+
[['endpoint' => 'https://web.push.test.localhost/foo3', 'expirationTime' => '1']],
208208
true,
209209
],
210210
[ // webpush method with an invalid webpush subscription, expect code execution but no subscription data
@@ -244,14 +244,37 @@ public function test_load_template_data($user_id, $method_data, $subscriptions,
244244

245245
$this->template->expects($expected ? self::once() : self::never())
246246
->method('assign_vars')
247-
->with([
248-
'NOTIFICATIONS_WEBPUSH_ENABLE' => true,
249-
'U_WEBPUSH_SUBSCRIBE' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_subscribe_controller'),
250-
'U_WEBPUSH_UNSUBSCRIBE' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_unsubscribe_controller'),
251-
'VAPID_PUBLIC_KEY' => $this->config['wpn_webpush_vapid_public'],
252-
'U_WEBPUSH_WORKER_URL' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_worker_controller'),
253-
'SUBSCRIPTIONS' => $subscriptions,
254-
'WEBPUSH_FORM_TOKENS' => $this->form_helper->get_form_tokens(\phpbb\webpushnotifications\ucp\controller\webpush::FORM_TOKEN_UCP),
247+
->withConsecutive([
248+
$this->callback(function($arg) use ($subscriptions) {
249+
$expectedValues = [
250+
'NOTIFICATIONS_WEBPUSH_ENABLE' => true,
251+
'U_WEBPUSH_SUBSCRIBE' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_subscribe_controller'),
252+
'U_WEBPUSH_UNSUBSCRIBE' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_unsubscribe_controller'),
253+
'VAPID_PUBLIC_KEY' => $this->config['wpn_webpush_vapid_public'],
254+
'U_WEBPUSH_WORKER_URL' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_worker_controller'),
255+
'SUBSCRIPTIONS' => $subscriptions,
256+
];
257+
258+
foreach ($expectedValues as $key => $value)
259+
{
260+
if (!array_key_exists($key, $arg))
261+
{
262+
$this->fail("Expected key '$key' is missing from the argument array");
263+
}
264+
if ($arg[$key] !== $value)
265+
{
266+
$this->fail("Mismatch for key '$key'. Expected: " . var_export($value, true) . ", Actual: " . var_export($arg[$key], true));
267+
}
268+
}
269+
270+
// Check if WEBPUSH_FORM_TOKENS exists, but don't check its value
271+
if (!array_key_exists('WEBPUSH_FORM_TOKENS', $arg))
272+
{
273+
$this->fail("Expected key 'WEBPUSH_FORM_TOKENS' is missing from the argument array");
274+
}
275+
276+
return true;
277+
})
255278
]);
256279

257280
$dispatcher = new \phpbb\event\dispatcher();
@@ -390,8 +413,8 @@ public function test_validate_pwa_options($validate, $cfg_array, $expected_error
390413
$config_name = key($cfg_array);
391414
$config_definition = ['validate' => $validate];
392415

393-
$pwa_icon_small = isset($cfg_array['pwa_icon_small']) ? $cfg_array['pwa_icon_small'] : '';
394-
$pwa_icon_large = isset($cfg_array['pwa_icon_large']) ? $cfg_array['pwa_icon_large'] : '';
416+
$pwa_icon_small = $cfg_array['pwa_icon_small'] ?? '';
417+
$pwa_icon_large = $cfg_array['pwa_icon_large'] ?? '';
395418

396419
[$small_image_name, $small_image_ext] = $pwa_icon_small ? explode('.', $pwa_icon_small, 2) : ['', ''];
397420
[$large_image_name, $large_image_ext] = $pwa_icon_large ? explode('.', $pwa_icon_large, 2) : ['', ''];

0 commit comments

Comments
 (0)