From 925a2e29d127a74dcd332df38db1e2a06d3ad219 Mon Sep 17 00:00:00 2001 From: Hideki Kinjyo Date: Sat, 30 Dec 2017 16:21:04 +0900 Subject: [PATCH] Tests TImestampBehavior use immutable or mutable type --- .../ORM/Behavior/TimestampBehaviorTest.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/TestCase/ORM/Behavior/TimestampBehaviorTest.php b/tests/TestCase/ORM/Behavior/TimestampBehaviorTest.php index f2215d51f6b..5c2019fc972 100644 --- a/tests/TestCase/ORM/Behavior/TimestampBehaviorTest.php +++ b/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; @@ -295,6 +297,33 @@ public function testSetTimestampExplicit() ); } + /** + * 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 *