Skip to content

Commit

Permalink
Revert timestamp() not to check useImmutable
Browse files Browse the repository at this point in the history
  • Loading branch information
o0h committed Dec 31, 2017
1 parent 19645fa commit 31e7331
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 43 deletions.
20 changes: 8 additions & 12 deletions src/ORM/Behavior/TimestampBehavior.php
Expand Up @@ -14,11 +14,11 @@
*/
namespace Cake\ORM\Behavior;

use Cake\Database\Type;
use Cake\Datasource\EntityInterface;
use Cake\Event\Event;
use Cake\I18n\Time;
use Cake\ORM\Behavior;
use DateTimeInterface;
use DateTime;
use UnexpectedValueException;

class TimestampBehavior extends Behavior
Expand Down Expand Up @@ -57,7 +57,7 @@ class TimestampBehavior extends Behavior
/**
* Current timestamp
*
* @var \DateTimeInterface
* @var \DateTime
*/
protected $_ts;

Expand Down Expand Up @@ -130,23 +130,19 @@ public function implementedEvents()
* If an explicit date time is passed, the config option `refreshTimestamp` is
* automatically set to false.
*
* @param \DateTimeInterface|null $ts Timestamp
* @param \DateTime|null $ts Timestamp
* @param bool $refreshTimestamp If true timestamp is refreshed.
* @return \DateTimeInterface
* @return \DateTime
*/
public function timestamp(DateTimeInterface $ts = null, $refreshTimestamp = false)
public function timestamp(DateTime $ts = null, $refreshTimestamp = false)
{
/** @var \Cake\Database\Type\DateTimeType $type */
$type = Type::build('datetime');
$class = $type->getDateTimeClassName();

if ($ts) {
if ($this->_config['refreshTimestamp']) {
$this->_config['refreshTimestamp'] = false;
}
$this->_ts = new $class($ts);
$this->_ts = new Time($ts);
} elseif ($this->_ts === null || $refreshTimestamp) {
$this->_ts = new $class();
$this->_ts = new Time();
}

return $this->_ts;
Expand Down
31 changes: 0 additions & 31 deletions tests/TestCase/ORM/Behavior/TimestampBehaviorTest.php
Expand Up @@ -14,9 +14,7 @@
*/
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 @@ -297,35 +295,6 @@ public function testSetTimestampExplicit()
);
}

/**
* testGetTimestampFollowingDatetimeClassSetting
*
* @return void
*/
public function testGetTimestampFollowingDatetimeClassSetting()
{
$table = $this->getMockBuilder('Cake\ORM\Table')->getMock();
$behavior = new TimestampBehavior($table);
/** @var \Cake\Database\Type\DateTimeType $type */
$type = Type::build('datetime');

$type->useImmutable();
$return = $behavior->timestamp(null, true);
$this->assertInstanceOf(
FrozenTime::class,
$return,
'Should return a immutable datetime object'
);

$type->useMutable();
$return = $behavior->timestamp(null, true);
$this->assertInstanceOf(
Time::class,
$return,
'Should return a mutable datetime object'
);
}

/**
* testTouch
*
Expand Down

0 comments on commit 31e7331

Please sign in to comment.