Skip testGetFromTo on date transition
authoreileen <emcnaughton@wikimedia.org>
Fri, 7 Jun 2019 00:37:24 +0000 (12:37 +1200)
committereileen <emcnaughton@wikimedia.org>
Fri, 7 Jun 2019 00:37:24 +0000 (12:37 +1200)
This avoids fails when the expectations were calculated right at the end of a day but then are compared with the new day's values.

Results in this case look like

CRM_Report_FormTest::testGetFromTo with data set #1 ('20190606000000', '20190606235959', 'this.day', '', '')
fail on data set [ this.day ,  ,  ]. Local php time is 2019-06-07 00:00:13 and mysql time is 2019-06-07 00:00:13
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => '20190606000000'
-    1 => '20190606235959'
+    0 => '20190607000000'
+    1 => '20190607235959'

tests/phpunit/CRM/Report/FormTest.php

index bed5587d5924613ee22a9ddd132004e158961161..5d0b0313a4e680daa5749c99a55f62b22418b6e2 100644 (file)
@@ -74,14 +74,18 @@ class CRM_Report_FormTest extends CiviUnitTestCase {
    * Test that getFromTo returns the correct dates.
    *
    * @dataProvider fromToData
-   * @param $expectedFrom
-   * @param $expectedTo
-   * @param $relative
-   * @param $from
-   * @param $to
+   *
+   * @param string $expectedFrom
+   * @param string $expectedTo
+   * @param string $relative
+   * @param string $from
+   * @param string $to
    */
   public function testGetFromTo($expectedFrom, $expectedTo, $relative, $from, $to) {
     $obj = new CRM_Report_Form();
+    if (date('H-i') === '00:00') {
+      $this->markTestIncomplete('The date might have changed since the dataprovider was called. Skip to avoid flakiness');
+    }
     list($calculatedFrom, $calculatedTo) = $obj->getFromTo($relative, $from, $to);
     $this->assertEquals([$expectedFrom, $expectedTo], [$calculatedFrom, $calculatedTo], "fail on data set [ $relative , $from , $to ]. Local php time is " . date('Y-m-d H:i:s') . ' and mysql time is ' . CRM_Core_DAO::singleValueQuery('SELECT NOW()'));
   }