Skip to content

Commit

Permalink
Fix deprecated method use in ORM tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 21, 2017
1 parent 9dca3d2 commit 3c0e8d4
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 73 deletions.
8 changes: 4 additions & 4 deletions tests/TestCase/ORM/AssociationCollectionTest.php
Expand Up @@ -155,7 +155,7 @@ public function testGetByProperty()
$table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['table'])
->getMock();
$table->schema([]);
$table->setSchema([]);
$belongsTo = new BelongsTo('Users', [
'sourceTable' => $table
]);
Expand Down Expand Up @@ -282,7 +282,7 @@ public function testSaveParents()
$table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['table'])
->getMock();
$table->schema([]);
$table->setSchema([]);
$mockOne = $this->getMockBuilder('Cake\ORM\Association\BelongsTo')
->setMethods(['saveAssociated'])
->setConstructorArgs(['Parent', [
Expand Down Expand Up @@ -332,7 +332,7 @@ public function testSaveParentsFiltered()
$table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['table'])
->getMock();
$table->schema([]);
$table->setSchema([]);
$mockOne = $this->getMockBuilder('Cake\ORM\Association\BelongsTo')
->setMethods(['saveAssociated'])
->setConstructorArgs(['Parents', [
Expand Down Expand Up @@ -382,7 +382,7 @@ public function testSaveChildrenFiltered()
$table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['table'])
->getMock();
$table->schema([]);
$table->setSchema([]);
$mockOne = $this->getMockBuilder('Cake\ORM\Association\HasMany')
->setMethods(['saveAssociated'])
->setConstructorArgs(['Comments', [
Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase/ORM/AssociationTest.php
Expand Up @@ -27,7 +27,7 @@ class TestTable extends Table

public function initialize(array $config = [])
{
$this->schema(['id' => ['type' => 'integer']]);
$this->setSchema(['id' => ['type' => 'integer']]);
}

public function findPublished($query)
Expand Down Expand Up @@ -302,7 +302,7 @@ public function testSetBindingKey()
*/
public function testBindingKeyDefault()
{
$this->source->primaryKey(['id', 'site_id']);
$this->source->setPrimaryKey(['id', 'site_id']);
$this->association
->expects($this->once())
->method('isOwningSide')
Expand All @@ -320,7 +320,7 @@ public function testBindingKeyDefault()
public function testBindingDefaultNoOwningSide()
{
$target = new Table;
$target->primaryKey(['foo', 'site_id']);
$target->setPrimaryKey(['foo', 'site_id']);
$this->association->setTarget($target);

$this->association
Expand Down Expand Up @@ -584,7 +584,7 @@ public function testPropertyNameClash()
{
$this->expectException(\PHPUnit\Framework\Error\Warning::class);
$this->expectExceptionMessageRegExp('/^Association property name "foo" clashes with field of same name of table "test"/');
$this->source->schema(['foo' => ['type' => 'string']]);
$this->source->setSchema(['foo' => ['type' => 'string']]);
$this->assertEquals('foo', $this->association->getProperty());
}

Expand All @@ -595,7 +595,7 @@ public function testPropertyNameClash()
*/
public function testPropertyNameExplicitySet()
{
$this->source->schema(['foo' => ['type' => 'string']]);
$this->source->setSchema(['foo' => ['type' => 'string']]);

$config = [
'className' => '\Cake\Test\TestCase\ORM\TestTable',
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/ORM/Behavior/BehaviorRegressionTest.php
Expand Up @@ -52,10 +52,10 @@ class BehaviorRegressionTest extends TestCase
public function testTreeAndTranslateIntegration()
{
$table = TableRegistry::get('NumberTrees');
$table->primaryKey(['id']);
$table->setPrimaryKey(['id']);
$table->addBehavior('Tree');
$table->addBehavior('Translate', ['fields' => ['name']]);
$table->entityClass(__NAMESPACE__ . '\\NumberTree');
$table->setEntityClass(__NAMESPACE__ . '\\NumberTree');

$all = $table->find('threaded')->find('translations');
$results = [];
Expand Down
14 changes: 7 additions & 7 deletions tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php
Expand Up @@ -98,7 +98,7 @@ public function testCustomTranslationTable()

$this->assertEquals('\TestApp\Model\Table\I18nTable', $i18n->getName());
$this->assertInstanceOf('TestApp\Model\Table\I18nTable', $i18n->getTarget());
$this->assertEquals('test_custom_i18n_datasource', $i18n->getTarget()->connection()->configName());
$this->assertEquals('test_custom_i18n_datasource', $i18n->getTarget()->getConnection()->configName());
$this->assertEquals('custom_i18n_table', $i18n->getTarget()->getTable());
}

Expand Down Expand Up @@ -1111,7 +1111,7 @@ public function testSavingWithNonDefaultLocale()
{
$table = TableRegistry::get('Articles');
$table->addBehavior('Translate', ['fields' => ['title', 'body']]);
$table->entityClass(__NAMESPACE__ . '\Article');
$table->setEntityClass(__NAMESPACE__ . '\Article');
I18n::setLocale('fra');
$translations = [
'fra' => ['title' => 'Un article'],
Expand Down Expand Up @@ -1188,7 +1188,7 @@ public function testAutoReferenceName()
public function testChangingReferenceName()
{
$table = TableRegistry::get('Articles');
$table->alias('FavoritePost');
$table->setAlias('FavoritePost');
$table->addBehavior(
'Translate',
['fields' => ['body'], 'referenceName' => 'Posts']
Expand Down Expand Up @@ -1289,7 +1289,7 @@ public function testSaveWithCleanFields()
{
$table = TableRegistry::get('Articles');
$table->addBehavior('Translate', ['fields' => ['title']]);
$table->entityClass(__NAMESPACE__ . '\Article');
$table->setEntityClass(__NAMESPACE__ . '\Article');
I18n::setLocale('fra');
$article = $table->get(1);
$article->set('body', 'New Body');
Expand All @@ -1311,7 +1311,7 @@ public function testSaveNewRecordWithTranslatesField()
'fields' => ['title'],
'validator' => (new \Cake\Validation\Validator)->add('title', 'notBlank', ['rule' => 'notBlank'])
]);
$table->entityClass(__NAMESPACE__ . '\Article');
$table->setEntityClass(__NAMESPACE__ . '\Article');

$data = [
'author_id' => 1,
Expand Down Expand Up @@ -1395,7 +1395,7 @@ public function testSaveExistingRecordOnlyTranslations()
{
$table = TableRegistry::get('Articles');
$table->addBehavior('Translate', ['fields' => ['title', 'body']]);
$table->entityClass(__NAMESPACE__ . '\Article');
$table->setEntityClass(__NAMESPACE__ . '\Article');

$data = [
'_translations' => [
Expand Down Expand Up @@ -1428,7 +1428,7 @@ public function testSaveExistingRecordWithTranslatesField()
{
$table = TableRegistry::get('Articles');
$table->addBehavior('Translate', ['fields' => ['title', 'body']]);
$table->entityClass(__NAMESPACE__ . '\Article');
$table->setEntityClass(__NAMESPACE__ . '\Article');

$data = [
'author_id' => 1,
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/ORM/Behavior/TreeBehaviorTest.php
Expand Up @@ -38,7 +38,7 @@ public function setUp()
{
parent::setUp();
$this->table = TableRegistry::get('NumberTrees');
$this->table->primaryKey(['id']);
$this->table->setPrimaryKey(['id']);
$this->table->addBehavior('Tree');
}

Expand Down Expand Up @@ -1378,7 +1378,7 @@ public function testFindPathWithAssociation()
{
$table = $this->table;
$other = TableRegistry::get('FriendlyTrees', [
'table' => $table->table()
'table' => $table->getTable()
]);
$table->hasOne('FriendlyTrees', [
'foreignKey' => 'id'
Expand Down Expand Up @@ -1487,11 +1487,11 @@ public function testSetLevelExistingNode()
public function assertMpttValues($expected, $table, $query = null)
{
$query = $query ?: $table->find();
$primaryKey = $table->primaryKey();
$primaryKey = $table->getPrimaryKey();
if (is_array($primaryKey)) {
$primaryKey = $primaryKey[0];
}
$displayField = $table->displayField();
$displayField = $table->getDisplayField();

$options = [
'valuePath' => function ($item, $key, $iterator) use ($primaryKey, $displayField) {
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/ORM/CompositeKeysTest.php
Expand Up @@ -498,7 +498,7 @@ public function testDeleteDependent()
public function testOneGenerateBelongsToManyEntitiesFromIds()
{
$articles = TableRegistry::get('SiteArticles');
$articles->entityClass(__NAMESPACE__ . '\OpenArticleEntity');
$articles->setEntityClass(__NAMESPACE__ . '\OpenArticleEntity');
$tags = TableRegistry::get('SiteTags');
$junction = TableRegistry::get('SiteArticlesTags');
$articles->belongsToMany('SiteTags', [
Expand Down Expand Up @@ -543,7 +543,7 @@ public function testFindListCompositeKeys()
'table' => 'site_authors',
'connection' => $this->connection,
]);
$table->displayField('name');
$table->setDisplayField('name');
$query = $table->find('list')
->enableHydration(false)
->order('id');
Expand All @@ -555,7 +555,7 @@ public function testFindListCompositeKeys()
];
$this->assertEquals($expected, $query->toArray());

$table->displayField(['name', 'site_id']);
$table->setDisplayField(['name', 'site_id']);
$query = $table->find('list')
->enableHydration(false)
->order('id');
Expand Down
54 changes: 27 additions & 27 deletions tests/TestCase/ORM/Locator/TableLocatorTest.php
Expand Up @@ -183,11 +183,11 @@ public function testGet()
'table' => 'my_articles',
]);
$this->assertInstanceOf('Cake\ORM\Table', $result);
$this->assertEquals('my_articles', $result->table());
$this->assertEquals('my_articles', $result->getTable());

$result2 = $this->_locator->get('Articles');
$this->assertSame($result, $result2);
$this->assertEquals('my_articles', $result->table());
$this->assertEquals('my_articles', $result->getTable());

$this->assertSame($this->_locator, $result->associations()->getTableLocator());
}
Expand All @@ -201,33 +201,33 @@ public function testGetFallbacks()
{
$result = $this->_locator->get('Droids');
$this->assertInstanceOf('Cake\ORM\Table', $result);
$this->assertEquals('droids', $result->table());
$this->assertEquals('Droids', $result->alias());
$this->assertEquals('droids', $result->getTable());
$this->assertEquals('Droids', $result->getAlias());

$result = $this->_locator->get('R2D2', ['className' => 'Droids']);
$this->assertInstanceOf('Cake\ORM\Table', $result);
$this->assertEquals('droids', $result->table(), 'The table should be derived from the className');
$this->assertEquals('R2D2', $result->alias());
$this->assertEquals('droids', $result->getTable(), 'The table should be derived from the className');
$this->assertEquals('R2D2', $result->getAlias());

$result = $this->_locator->get('C3P0', ['className' => 'Droids', 'table' => 'rebels']);
$this->assertInstanceOf('Cake\ORM\Table', $result);
$this->assertEquals('rebels', $result->table(), 'The table should be taken from options');
$this->assertEquals('C3P0', $result->alias());
$this->assertEquals('rebels', $result->getTable(), 'The table should be taken from options');
$this->assertEquals('C3P0', $result->getAlias());

$result = $this->_locator->get('Funky.Chipmunks');
$this->assertInstanceOf('Cake\ORM\Table', $result);
$this->assertEquals('chipmunks', $result->table(), 'The table should be derived from the alias');
$this->assertEquals('Chipmunks', $result->alias());
$this->assertEquals('chipmunks', $result->getTable(), 'The table should be derived from the alias');
$this->assertEquals('Chipmunks', $result->getAlias());

$result = $this->_locator->get('Awesome', ['className' => 'Funky.Monkies']);
$this->assertInstanceOf('Cake\ORM\Table', $result);
$this->assertEquals('monkies', $result->table(), 'The table should be derived from the classname');
$this->assertEquals('Awesome', $result->alias());
$this->assertEquals('monkies', $result->getTable(), 'The table should be derived from the classname');
$this->assertEquals('Awesome', $result->getAlias());

$result = $this->_locator->get('Stuff', ['className' => 'Cake\ORM\Table']);
$this->assertInstanceOf('Cake\ORM\Table', $result);
$this->assertEquals('stuff', $result->table(), 'The table should be derived from the alias');
$this->assertEquals('Stuff', $result->alias());
$this->assertEquals('stuff', $result->getTable(), 'The table should be derived from the alias');
$this->assertEquals('Stuff', $result->getAlias());
}

/**
Expand All @@ -241,7 +241,7 @@ public function testGetWithgetConfig()
'table' => 'my_articles',
]);
$result = $this->_locator->get('Articles');
$this->assertEquals('my_articles', $result->table(), 'Should use getConfig() data.');
$this->assertEquals('my_articles', $result->getTable(), 'Should use getConfig() data.');
}

/**
Expand All @@ -255,8 +255,8 @@ public function testGetWithConnectionName()
$result = $this->_locator->get('Articles', [
'connectionName' => 'testing'
]);
$this->assertEquals('articles', $result->table());
$this->assertEquals('test', $result->connection()->configName());
$this->assertEquals('articles', $result->getTable());
$this->assertEquals('test', $result->getConnection()->configName());
}

/**
Expand Down Expand Up @@ -434,23 +434,23 @@ public function testConfigAndBuild()

$table = $this->_locator->get('users', ['table' => 'users']);
$this->assertInstanceOf('Cake\ORM\Table', $table);
$this->assertEquals('users', $table->table());
$this->assertEquals('users', $table->alias());
$this->assertSame($connection, $table->connection());
$this->assertEquals(array_keys($schema), $table->schema()->columns());
$this->assertEquals($schema['id']['type'], $table->schema()->getColumnType('id'));
$this->assertEquals('users', $table->getTable());
$this->assertEquals('users', $table->getAlias());
$this->assertSame($connection, $table->getConnection());
$this->assertEquals(array_keys($schema), $table->getSchema()->columns());
$this->assertEquals($schema['id']['type'], $table->getSchema()->getColumnType('id'));

$this->_locator->clear();
$this->assertEmpty($this->_locator->getConfig());

$this->_locator->setConfig('users', $options);
$table = $this->_locator->get('users', ['className' => __NAMESPACE__ . '\MyUsersTable']);
$this->assertInstanceOf(__NAMESPACE__ . '\MyUsersTable', $table);
$this->assertEquals('users', $table->table());
$this->assertEquals('users', $table->alias());
$this->assertSame($connection, $table->connection());
$this->assertEquals(array_keys($schema), $table->schema()->columns());
$this->assertEquals($schema['id']['type'], $table->schema()->getColumnType('id'));
$this->assertEquals('users', $table->getTable());
$this->assertEquals('users', $table->getAlias());
$this->assertSame($connection, $table->getConnection());
$this->assertEquals(array_keys($schema), $table->getSchema()->columns());
$this->assertEquals($schema['id']['type'], $table->getSchema()->getColumnType('id'));
}

/**
Expand Down

0 comments on commit 3c0e8d4

Please sign in to comment.