Browse Source

Add tests related to #9818

While this doesn't cover the magic property being modified, I suspect
that might be related to a PHP issue.
Mark Story 9 years ago
parent
commit
8b2f80b83f
1 changed files with 22 additions and 0 deletions
  1. 22 0
      tests/TestCase/I18n/TimeTest.php

+ 22 - 0
tests/TestCase/I18n/TimeTest.php

@@ -50,10 +50,13 @@ class TimeTest extends TestCase
         Time::setTestNow($this->now);
         Time::setTestNow($this->now);
         Time::setDefaultLocale($this->locale);
         Time::setDefaultLocale($this->locale);
         Time::resetToStringFormat();
         Time::resetToStringFormat();
+        Time::setJsonEncodeFormat("yyyy-MM-dd'T'HH:mm:ssxxx");
 
 
         FrozenTime::setTestNow($this->frozenNow);
         FrozenTime::setTestNow($this->frozenNow);
         FrozenTime::setDefaultLocale($this->locale);
         FrozenTime::setDefaultLocale($this->locale);
         FrozenTime::resetToStringFormat();
         FrozenTime::resetToStringFormat();
+        FrozenTime::setJsonEncodeFormat("yyyy-MM-dd'T'HH:mm:ssxxx");
+
         date_default_timezone_set('UTC');
         date_default_timezone_set('UTC');
         I18n::locale(I18n::DEFAULT_LOCALE);
         I18n::locale(I18n::DEFAULT_LOCALE);
     }
     }
@@ -724,6 +727,25 @@ class TimeTest extends TestCase
     }
     }
 
 
     /**
     /**
+     * Test jsonSerialize no side-effects
+     *
+     * @dataProvider classNameProvider
+     * @return void
+     */
+    public function testJsonEncodeSideEffectFree($class)
+    {
+        if (version_compare(INTL_ICU_VERSION, '50.0', '<')) {
+            $this->markTestSkipped('ICU 5x is needed');
+        }
+        $date = new \Cake\I18n\FrozenTime('2016-11-29 09:00:00');
+        $this->assertInstanceOf('DateTimeZone', $date->timezone);
+
+        $result = json_encode($date);
+        $this->assertEquals('"2016-11-29T09:00:00+00:00"', $result);
+        $this->assertInstanceOf('DateTimeZone', $date->getTimezone());
+    }
+
+    /**
      * Tests debugInfo
      * Tests debugInfo
      *
      *
      * @dataProvider classNameProvider
      * @dataProvider classNameProvider