Skip to content

Commit

Permalink
Trigger errors on deprecated fixture formats.
Browse files Browse the repository at this point in the history
Update fixtures in tests. Instead of adding shims, Jose and I have
decided it is better to provide features in the UpgradeShell to migrate
fixtures. Fixtures will now trigger errors on known to be old formats.
  • Loading branch information
markstory committed May 27, 2013
1 parent a7f9b51 commit 74b2e90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Test/TestCase/TestSuite/TestFixtureTest.php
Expand Up @@ -41,7 +41,7 @@ class ArticleFixture extends TestFixture {
* @var array
*/
public $fields = [
'id' => ['type' => 'integer', 'key' => 'primary'],
'id' => ['type' => 'integer'],
'name' => ['type' => 'string', 'length' => '255'],
'created' => ['type' => 'datetime'],
'constraints' => [
Expand Down Expand Up @@ -82,7 +82,7 @@ class StringsTestFixture extends TestFixture {
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'id' => array('type' => 'integer'),
'name' => array('type' => 'string', 'length' => '255'),
'email' => array('type' => 'string', 'length' => '255'),
'age' => array('type' => 'integer', 'default' => 10)
Expand Down
14 changes: 10 additions & 4 deletions lib/Cake/TestSuite/Fixture/TestFixture.php
Expand Up @@ -147,8 +147,11 @@ protected function _schemaFromFields() {
if ($field === 'constraints' || $field === 'indexes') {
continue;
}
// TODO issue E_USER_NOTICE if a column defines 'key'?
// Or handle the case correctly?
// Trigger errors on deprecated usage.
if (is_array($data) && isset($data['key'])) {
$msg = __d('cake_dev', 'Usage of the `key` options in columns is not supported. Try using the upgrade shell to migrate your fixtures.`');
trigger_error($msg, E_USER_NOTICE);
}
$this->_schema->addColumn($field, $data);
}
if (!empty($this->fields['constraints'])) {
Expand All @@ -157,8 +160,11 @@ protected function _schemaFromFields() {
}
}
if (!empty($this->fields['indexes'])) {
// TODO 2.x indexes contains indexes + constraints.
// Should we issue an error or handle the case?
// Trigger errors on deprecated usage.
if (empty($data['type'])) {
$msg = __d('cake_dev', 'Indexes must define a type. Try using the upgrade shell to migrate your fixtures.');
trigger_error($msg, E_USER_NOTICE);
}
foreach ($this->fields['indexes'] as $name => $data) {
$this->_schema->addIndex($name, $data);
}
Expand Down

0 comments on commit 74b2e90

Please sign in to comment.