From f564e9e8633b36161edde33ddb04549d5dfdb733 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Sat, 30 Jan 2021 08:55:39 -0500 Subject: [PATCH] test fails at end of month --- tests/phpunit/api/v4/Action/DateTest.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/api/v4/Action/DateTest.php b/tests/phpunit/api/v4/Action/DateTest.php index 138fbe2b1af4..3bc2636d6b42 100644 --- a/tests/phpunit/api/v4/Action/DateTest.php +++ b/tests/phpunit/api/v4/Action/DateTest.php @@ -67,15 +67,24 @@ public function testRelativeDateRanges() { ->addValue('last_name', 'one') ->execute() ->first()['id']; + + // Avoid problems with `strtotime()` giving + // impossible dates like April 31 which roll over and then don't match. + $thisMonth = date('m'); + $lastMonth = ($thisMonth === 1 ? 12 : $thisMonth - 1); + $nextMonth = ($thisMonth === 12 ? 1 : $thisMonth + 1); + $lastMonthsYear = ($thisMonth === 1 ? date('Y') - 1 : date('Y')); + $nextMonthsYear = ($thisMonth === 12 ? date('Y') + 1 : date('Y')); + $act = Activity::save() ->setDefaults(['activity_type_id:name' => 'Meeting', 'source_contact_id' => $c1]) - ->addRecord(['activity_date_time' => 'now - 3 year']) - ->addRecord(['activity_date_time' => 'now - 1 year']) - ->addRecord(['activity_date_time' => 'now - 1 month']) + ->addRecord(['activity_date_time' => (date('Y') - 3) . '-' . date('m-01 H:i:s')]) + ->addRecord(['activity_date_time' => (date('Y') - 1) . '-' . date('m-01 H:i:s')]) + ->addRecord(['activity_date_time' => "{$lastMonthsYear}-{$lastMonth}-01 " . date('H:i:s')]) ->addRecord(['activity_date_time' => 'now']) - ->addRecord(['activity_date_time' => 'now + 1 month']) - ->addRecord(['activity_date_time' => 'now + 1 year']) - ->addRecord(['activity_date_time' => 'now + 3 year']) + ->addRecord(['activity_date_time' => "{$nextMonthsYear}-{$nextMonth}-01 " . date('H:i:s')]) + ->addRecord(['activity_date_time' => (date('Y') + 1) . '-' . date('m-01 H:i:s')]) + ->addRecord(['activity_date_time' => (date('Y') + 3) . '-' . date('m-01 H:i:s')]) ->execute()->column('id'); $result = Activity::get(FALSE)->addSelect('id')