/** * @depends testNewRecord */ public function testUpdateRecord() { $currentTime = time(); $model = new ActiveRecordTimestamp(); $model->save(false); $enforcedTime = $currentTime - 100; $model->created_at = $enforcedTime; $model->updated_at = $enforcedTime; $model->save(false); $this->assertEquals($enforcedTime, $model->created_at, 'Create time has been set on update!'); $this->assertTrue($model->updated_at >= $currentTime, 'Update time has NOT been set on update!'); }
/** * @depends testNewRecord */ public function testUpdateRecordExpression() { ActiveRecordTimestamp::$tableName = 'test_auto_timestamp_string'; ActiveRecordTimestamp::$behaviors = ['timestamp' => ['class' => TimestampBehavior::className(), 'value' => new Expression("strftime('%Y')")]]; $model = new ActiveRecordTimestamp(); $model->save(false); $enforcedTime = date('Y') - 1; $model->created_at = $enforcedTime; $model->updated_at = $enforcedTime; $model->save(false); $this->assertEquals($enforcedTime, $model->created_at, 'Create time has been set on update!'); $this->assertInstanceOf(Expression::className(), $model->updated_at); $model->refresh(); $this->assertEquals($enforcedTime, $model->created_at, 'Create time has been set on update!'); $this->assertEquals(date('Y'), $model->updated_at); }