Skip to content

Commit

Permalink
Fix deprecation warnings in View & Tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 22, 2017
1 parent 274ea78 commit b89f571
Show file tree
Hide file tree
Showing 14 changed files with 371 additions and 320 deletions.
4 changes: 2 additions & 2 deletions src/View/Form/EntityContext.php
Expand Up @@ -136,7 +136,7 @@ protected function _prepare()
$isEntity = $entity instanceof EntityInterface;

if ($isEntity) {
$table = $entity->source();
$table = $entity->getSource();
}
if (!$table && $isEntity && get_class($entity) !== 'Cake\ORM\Entity') {
list(, $entityClass) = namespaceSplit(get_class($entity));
Expand Down Expand Up @@ -581,7 +581,7 @@ public function error($field)
$entity = $this->entity($parts);

if ($entity instanceof EntityInterface) {
return $entity->errors(array_pop($parts));
return $entity->getError(array_pop($parts));
}

return [];
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Datasource/FactoryLocatorTest.php
Expand Up @@ -86,7 +86,7 @@ public function testLoadModelPlugin()
{
$stub = new Stub();
$stub->setProps('Articles');
$stub->modelType('Table');
$stub->setModelType('Table');

$result = $stub->loadModel('TestPlugin.Comments');
$this->assertInstanceOf('TestPlugin\Model\Table\CommentsTable', $result);
Expand Down Expand Up @@ -136,7 +136,7 @@ public function testModelType()

return $mock;
});
$stub->modelType('Test');
$stub->setModelType('Test');

$result = $stub->loadModel('Magic');
$this->assertInstanceOf('\StdClass', $result);
Expand Down
35 changes: 19 additions & 16 deletions tests/TestCase/Datasource/ModelAwareTraitTest.php
Expand Up @@ -60,7 +60,7 @@ public function testLoadModel()
{
$stub = new Stub();
$stub->setProps('Articles');
$stub->modelType('Table');
$stub->setModelType('Table');

$result = $stub->loadModel();
$this->assertInstanceOf('Cake\ORM\Table', $result);
Expand All @@ -83,7 +83,7 @@ public function testLoadModelPlugin()
{
$stub = new Stub();
$stub->setProps('Articles');
$stub->modelType('Table');
$stub->setModelType('Table');

$result = $stub->loadModel('TestPlugin.Comments');
$this->assertInstanceOf('TestPlugin\Model\Table\CommentsTable', $result);
Expand Down Expand Up @@ -120,25 +120,28 @@ public function testModelFactory()
/**
* test alternate default model type.
*
* @group deprecated
* @return void
*/
public function testModelType()
{
$stub = new Stub();
$stub->setProps('Articles');

FactoryLocator::add('Test', function ($name) {
$mock = new \StdClass();
$mock->name = $name;

return $mock;
$this->deprecated(function () {
$stub = new Stub();
$stub->setProps('Articles');

FactoryLocator::add('Test', function ($name) {
$mock = new \StdClass();
$mock->name = $name;

return $mock;
});
$stub->modelType('Test');

$result = $stub->loadModel('Magic');
$this->assertInstanceOf('\StdClass', $result);
$this->assertInstanceOf('\StdClass', $stub->Magic);
$this->assertEquals('Magic', $stub->Magic->name);
});
$stub->modelType('Test');

$result = $stub->loadModel('Magic');
$this->assertInstanceOf('\StdClass', $result);
$this->assertInstanceOf('\StdClass', $stub->Magic);
$this->assertEquals('Magic', $stub->Magic->name);
}

/**
Expand Down
26 changes: 13 additions & 13 deletions tests/TestCase/Datasource/RulesCheckerTest.php
Expand Up @@ -44,12 +44,12 @@ function () {
);

$this->assertTrue($rules->check($entity, RulesChecker::CREATE));
$this->assertEmpty($entity->errors());
$this->assertEmpty($entity->getErrors());
$this->assertTrue($rules->check($entity, RulesChecker::UPDATE));
$this->assertEmpty($entity->errors());
$this->assertEmpty($entity->getErrors());

$this->assertFalse($rules->check($entity, RulesChecker::DELETE));
$this->assertEquals(['ruleName' => 'invalid'], $entity->errors('name'));
$this->assertEquals(['ruleName' => 'invalid'], $entity->getError('name'));
}

/**
Expand All @@ -73,12 +73,12 @@ function () {
);

$this->assertTrue($rules->check($entity, RulesChecker::CREATE));
$this->assertEmpty($entity->errors());
$this->assertEmpty($entity->getErrors());
$this->assertTrue($rules->check($entity, RulesChecker::DELETE));
$this->assertEmpty($entity->errors());
$this->assertEmpty($entity->getErrors());

$this->assertFalse($rules->check($entity, RulesChecker::UPDATE));
$this->assertEquals(['ruleName' => 'invalid'], $entity->errors('name'));
$this->assertEquals(['ruleName' => 'invalid'], $entity->getError('name'));
}

/**
Expand All @@ -102,12 +102,12 @@ function () {
);

$this->assertTrue($rules->check($entity, RulesChecker::UPDATE));
$this->assertEmpty($entity->errors());
$this->assertEmpty($entity->getErrors());
$this->assertTrue($rules->check($entity, RulesChecker::DELETE));
$this->assertEmpty($entity->errors());
$this->assertEmpty($entity->getErrors());

$this->assertFalse($rules->check($entity, RulesChecker::CREATE));
$this->assertEquals(['ruleName' => 'invalid'], $entity->errors('name'));
$this->assertEquals(['ruleName' => 'invalid'], $entity->getError('name'));
}

/**
Expand All @@ -131,7 +131,7 @@ function () {
);

$this->assertFalse($rules->check($entity, RulesChecker::CREATE));
$this->assertEquals(['ruleName' => 'invalid'], $entity->errors('name'));
$this->assertEquals(['ruleName' => 'invalid'], $entity->getError('name'));
}

/**
Expand All @@ -154,7 +154,7 @@ function () {
);

$this->assertFalse($rules->check($entity, RulesChecker::CREATE));
$this->assertEquals(['worst thing ever'], $entity->errors('name'));
$this->assertEquals(['worst thing ever'], $entity->getError('name'));
}

/**
Expand All @@ -177,7 +177,7 @@ function () {
);

$this->assertFalse($rules->check($entity, RulesChecker::CREATE));
$this->assertEquals(['this is bad'], $entity->errors('name'));
$this->assertEquals(['this is bad'], $entity->getError('name'));
}

/**
Expand All @@ -197,6 +197,6 @@ public function testAddWithoutFields()
});

$this->assertFalse($rules->check($entity, RulesChecker::CREATE));
$this->assertEmpty($entity->errors());
$this->assertEmpty($entity->getErrors());
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/ORM/Association/BelongsToManyTest.php
Expand Up @@ -854,7 +854,7 @@ public function testReplaceLinkFailingDomainRules()
];
$result = $assoc->replaceLinks($entity, $tags);
$this->assertFalse($result, 'replace should have failed.');
$this->assertNotEmpty($tags[0]->errors(), 'Bad entity should have errors.');
$this->assertNotEmpty($tags[0]->getErrors(), 'Bad entity should have errors.');

$entity = $articles->get(1, ['contain' => 'Tags']);
$this->assertCount($originalCount, $entity->tags, 'Should not have changed.');
Expand Down
14 changes: 7 additions & 7 deletions tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php
Expand Up @@ -1574,7 +1574,7 @@ public function testBuildMarshalMapNonArrayData()
$entity = $table->newEntity();
$result = $map['_translations']('garbage', $entity);
$this->assertNull($result, 'Non-array should not error out.');
$this->assertEmpty($entity->errors());
$this->assertEmpty($entity->getErrors());
$this->assertEmpty($entity->get('_translations'));
}

Expand Down Expand Up @@ -1602,7 +1602,7 @@ public function testBuildMarshalMapBuildEntities()
]
];
$result = $map['_translations']($data, $entity);
$this->assertEmpty($entity->errors(), 'No validation errors.');
$this->assertEmpty($entity->getErrors(), 'No validation errors.');
$this->assertCount(2, $result);
$this->assertArrayHasKey('en', $result);
$this->assertArrayHasKey('es', $result);
Expand Down Expand Up @@ -1639,13 +1639,13 @@ public function testBuildMarshalMapBuildEntitiesValidationErrors()
]
];
$result = $map['_translations']($data, $entity);
$this->assertNotEmpty($entity->errors(), 'Needs validation errors.');
$this->assertNotEmpty($entity->getErrors(), 'Needs validation errors.');
$expected = [
'title' => [
'_empty' => 'This field cannot be left empty'
]
];
$this->assertEquals($expected, $entity->errors('es'));
$this->assertEquals($expected, $entity->getError('es'));

$this->assertEquals('English Title', $result['en']->title);
$this->assertEquals('', $result['es']->title);
Expand Down Expand Up @@ -1681,7 +1681,7 @@ public function testBuildMarshalMapUpdateExistingEntities()
]
];
$result = $map['_translations']($data, $entity);
$this->assertEmpty($entity->errors(), 'No validation errors.');
$this->assertEmpty($entity->getErrors(), 'No validation errors.');
$this->assertSame($en, $result['en']);
$this->assertSame($es, $result['es']);
$this->assertSame($en, $entity->get('_translations')['en']);
Expand Down Expand Up @@ -1728,12 +1728,12 @@ public function testBuildMarshalMapUpdateEntitiesValidationErrors()
]
];
$result = $map['_translations']($data, $entity);
$this->assertNotEmpty($entity->errors(), 'Needs validation errors.');
$this->assertNotEmpty($entity->getErrors(), 'Needs validation errors.');
$expected = [
'title' => [
'_empty' => 'This field cannot be left empty'
]
];
$this->assertEquals($expected, $entity->errors('es'));
$this->assertEquals($expected, $entity->getError('es'));
}
}

0 comments on commit b89f571

Please sign in to comment.