Skip to content

Commit

Permalink
Tests TImestampBehavior use immutable or mutable type
Browse files Browse the repository at this point in the history
  • Loading branch information
o0h committed Dec 30, 2017
1 parent 743b1f9 commit 925a2e2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/TestCase/ORM/Behavior/TimestampBehaviorTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 925a2e2

Please sign in to comment.