From 103a4b5c92bb937805efdbc7f19f2f616dca5ff4 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Thu, 25 Nov 2021 18:13:51 +0100 Subject: [PATCH] MDL-70658 phpunit: never apply for time() in data providers Data providers are executed at the beginning of the execution of the phpunit run, not when the test is run. So, setting anything on them being dependent of current time has high chances or fail when the test is executed (maybe some hours later in slow databases / systems). Data provider only can contain the relative values and then, when the test is effectively run, they are applied to *current* time. --- mod/bigbluebuttonbn/tests/meeting_test.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mod/bigbluebuttonbn/tests/meeting_test.php b/mod/bigbluebuttonbn/tests/meeting_test.php index 47b9d5b1964..7cded8b284b 100644 --- a/mod/bigbluebuttonbn/tests/meeting_test.php +++ b/mod/bigbluebuttonbn/tests/meeting_test.php @@ -198,6 +198,10 @@ class meeting_test extends \advanced_testcase { * @covers ::can_join */ public function test_can_join_with_dates(int $type, ?string $groupname, int $groupmode, array $canjoin, array $dates) { + // Apply the data provider relative values to now. + array_walk($dates, function(&$val) { + $val = time() + $val; + }); $this->resetAfterTest(); [$meeting, $useringroup, $usernotingroup, $groupid, $activity] = $this->prepare_meeting($type, $groupname, $groupmode, true, $dates); @@ -283,14 +287,14 @@ class meeting_test extends \advanced_testcase { 'groupname' => null, 'groupmode' => NOGROUPS, 'canjoin' => ['useringroup' => false, 'usernotingroup' => false], - 'dates' => ['openingtime' => time() - 7200, 'closingtime' => time() - 3600] + 'dates' => ['openingtime' => -7200, 'closingtime' => -3600] ], 'Instance Type ALL - No Group - Open in future' => [ 'type' => instance::TYPE_ALL, 'groupname' => null, 'groupmode' => NOGROUPS, 'canjoin' => ['useringroup' => false, 'usernotingroup' => false], - 'dates' => ['openingtime' => time() + 3600, 'closingtime' => time() + 7200] + 'dates' => ['openingtime' => 3600, 'closingtime' => 7200] ], ]; }