Browse Source

Revert timestamp() not to check useImmutable

Hideki Kinjyo 8 years ago
parent
commit
31e733173a

+ 8 - 12
src/ORM/Behavior/TimestampBehavior.php

@@ -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
@@ -57,7 +57,7 @@ class TimestampBehavior extends Behavior
     /**
      * Current timestamp
      *
-     * @var \DateTimeInterface
+     * @var \DateTime
      */
     protected $_ts;
 
@@ -130,23 +130,19 @@ class TimestampBehavior extends Behavior
      * 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;

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

@@ -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;
@@ -298,35 +296,6 @@ class TimestampBehaviorTest extends TestCase
     }
 
     /**
-     * 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
      *
      * @return void