Skip to content
Permalink
Browse files

Don't hard fail on missing columns.

If timestamp behavior is attached to a table that doesn't have the
required columns, it should not hard fail in this way. This failure mode
can be percieved as a compatibility break as it happens deep into
runtime, and not during configuration/attach time.

Refs #11800
  • Loading branch information...
markstory committed Mar 7, 2018
1 parent bb5e86f commit 9fbaf7e3e41d6eca417f834ee49e1e19cd5b7df1
Showing with 26 additions and 0 deletions.
  1. +4 −0 src/ORM/Behavior/TimestampBehavior.php
  2. +22 −0 tests/TestCase/ORM/Behavior/TimestampBehaviorTest.php
@@ -198,6 +198,10 @@ protected function _updateField($entity, $field, $refreshTimestamp)
$ts = $this->timestamp(null, $refreshTimestamp);
$columnType = $this->getTable()->getSchema()->getColumnType($field);
if (!$columnType) {
return;
}
/** @var \Cake\Database\Type\DateTimeType $type */
$type = Type::build($columnType);
$class = $type->getDateTimeClassName();
@@ -195,6 +195,28 @@ public function testModifiedPresent()
$this->assertSame($ts->format('c'), $entity->modified->format('c'), 'Modified timestamp is expected to be updated');
}
/**
* test that timestamp creation doesn't fail on missing columns
*
* @return void
*/
public function testModifiedMissingColumn()
{
$table = $this->getTable();
$table->getSchema()->removeColumn('created')->removeColumn('modified');
$this->Behavior = new TimestampBehavior($table);
$ts = new \DateTime('2000-01-01');
$this->Behavior->timestamp($ts);
$event = new Event('Model.beforeSave');
$entity = new Entity(['name' => 'Foo']);
$return = $this->Behavior->handleEvent($event, $entity);
$this->assertTrue($return, 'Handle Event is expected to always return true');
$this->assertNull($entity->created);
$this->assertNull($entity->modified);
}
/**
* testUseImmutable
*

0 comments on commit 9fbaf7e

Please sign in to comment.
You can’t perform that action at this time.