Browse Source

Tests TImestampBehavior use immutable or mutable type

Hideki Kinjyo 8 years ago
parent
commit
925a2e29d1
1 changed files with 29 additions and 0 deletions
  1. 29 0
      tests/TestCase/ORM/Behavior/TimestampBehaviorTest.php

+ 29 - 0
tests/TestCase/ORM/Behavior/TimestampBehaviorTest.php

@@ -14,7 +14,9 @@
  */
 namespace Cake\Test\TestCase\ORM\Behavior;
 
+use Cake\Database\Type;
 use Cake\Event\Event;
+use Cake\I18n\FrozenTime;
 use Cake\I18n\Time;
 use Cake\ORM\Behavior\TimestampBehavior;
 use Cake\ORM\Entity;
@@ -296,6 +298,33 @@ class TimestampBehaviorTest extends TestCase
     }
 
     /**
+     * testGetTimestampFollowingDatetimeClassSetting
+     *
+     * @return void
+     */
+    public function testGetTimestampFollowingDatetimeClassSetting()
+    {
+        $table = $this->getMockBuilder('Cake\ORM\Table')->getMock();
+        $behavior = new TimestampBehavior($table);
+
+        Type::build('datetime')->useImmutable();
+        $return = $behavior->timestamp(null, true);
+        $this->assertInstanceOf(
+            FrozenTime::class,
+            $return,
+            'Should return a immutable datetime object'
+        );
+
+        Type::build('datetime')->useMutable();
+        $return = $behavior->timestamp(null, true);
+        $this->assertInstanceOf(
+            Time::class,
+            $return,
+            'Should return a mutable datetime object'
+        );
+    }
+
+    /**
      * testTouch
      *
      * @return void