From 3c0e8d4a5c6a84ea679f3cc3562d025145abca82 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 21 Nov 2017 00:44:32 -0500 Subject: [PATCH] Fix deprecated method use in ORM tests. --- .../ORM/AssociationCollectionTest.php | 8 +-- tests/TestCase/ORM/AssociationTest.php | 10 ++-- .../ORM/Behavior/BehaviorRegressionTest.php | 4 +- .../ORM/Behavior/TranslateBehaviorTest.php | 14 ++--- .../ORM/Behavior/TreeBehaviorTest.php | 8 +-- tests/TestCase/ORM/CompositeKeysTest.php | 6 +-- .../TestCase/ORM/Locator/TableLocatorTest.php | 54 +++++++++---------- tests/TestCase/ORM/MarshallerTest.php | 34 ++++++------ tests/TestCase/ORM/QueryRegressionTest.php | 2 +- tests/TestCase/ORM/ResultSetTest.php | 4 +- tests/TestCase/ORM/TableRegressionTest.php | 2 +- 11 files changed, 73 insertions(+), 73 deletions(-) diff --git a/tests/TestCase/ORM/AssociationCollectionTest.php b/tests/TestCase/ORM/AssociationCollectionTest.php index 251415055a7..1d65eb64f1f 100644 --- a/tests/TestCase/ORM/AssociationCollectionTest.php +++ b/tests/TestCase/ORM/AssociationCollectionTest.php @@ -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 ]); @@ -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', [ @@ -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', [ @@ -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', [ diff --git a/tests/TestCase/ORM/AssociationTest.php b/tests/TestCase/ORM/AssociationTest.php index 39db252663d..03b0610f913 100644 --- a/tests/TestCase/ORM/AssociationTest.php +++ b/tests/TestCase/ORM/AssociationTest.php @@ -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) @@ -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') @@ -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 @@ -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()); } @@ -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', diff --git a/tests/TestCase/ORM/Behavior/BehaviorRegressionTest.php b/tests/TestCase/ORM/Behavior/BehaviorRegressionTest.php index 8ec512f5447..edffc3707ad 100644 --- a/tests/TestCase/ORM/Behavior/BehaviorRegressionTest.php +++ b/tests/TestCase/ORM/Behavior/BehaviorRegressionTest.php @@ -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 = []; diff --git a/tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php b/tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php index 809b0cd0de8..aae0b56d25f 100644 --- a/tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php +++ b/tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php @@ -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()); } @@ -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'], @@ -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'] @@ -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'); @@ -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, @@ -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' => [ @@ -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, diff --git a/tests/TestCase/ORM/Behavior/TreeBehaviorTest.php b/tests/TestCase/ORM/Behavior/TreeBehaviorTest.php index a19883a9ca5..0a4b4aeab25 100644 --- a/tests/TestCase/ORM/Behavior/TreeBehaviorTest.php +++ b/tests/TestCase/ORM/Behavior/TreeBehaviorTest.php @@ -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'); } @@ -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' @@ -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) { diff --git a/tests/TestCase/ORM/CompositeKeysTest.php b/tests/TestCase/ORM/CompositeKeysTest.php index 29b4c7028c0..0d25beb5275 100644 --- a/tests/TestCase/ORM/CompositeKeysTest.php +++ b/tests/TestCase/ORM/CompositeKeysTest.php @@ -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', [ @@ -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'); @@ -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'); diff --git a/tests/TestCase/ORM/Locator/TableLocatorTest.php b/tests/TestCase/ORM/Locator/TableLocatorTest.php index be9f201636a..fa78a87c53f 100644 --- a/tests/TestCase/ORM/Locator/TableLocatorTest.php +++ b/tests/TestCase/ORM/Locator/TableLocatorTest.php @@ -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()); } @@ -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()); } /** @@ -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.'); } /** @@ -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()); } /** @@ -434,11 +434,11 @@ 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()); @@ -446,11 +446,11 @@ public function testConfigAndBuild() $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')); } /** diff --git a/tests/TestCase/ORM/MarshallerTest.php b/tests/TestCase/ORM/MarshallerTest.php index 445541ad913..3699309c48d 100644 --- a/tests/TestCase/ORM/MarshallerTest.php +++ b/tests/TestCase/ORM/MarshallerTest.php @@ -71,8 +71,8 @@ class GreedyCommentsTable extends Table */ public function initialize(array $config) { - $this->table('comments'); - $this->alias('Comments'); + $this->setTable('comments'); + $this->setAlias('Comments'); } /** @@ -156,11 +156,11 @@ public function setUp() $this->comments->belongsTo('Articles'); $this->comments->belongsTo('Users'); - $this->articles->entityClass(__NAMESPACE__ . '\OpenEntity'); - $this->comments->entityClass(__NAMESPACE__ . '\OpenEntity'); - $this->users->entityClass(__NAMESPACE__ . '\OpenEntity'); - $this->tags->entityClass(__NAMESPACE__ . '\OpenEntity'); - $this->articleTags->entityClass(__NAMESPACE__ . '\OpenEntity'); + $this->articles->setEntityClass(__NAMESPACE__ . '\OpenEntity'); + $this->comments->setEntityClass(__NAMESPACE__ . '\OpenEntity'); + $this->users->setEntityClass(__NAMESPACE__ . '\OpenEntity'); + $this->tags->setEntityClass(__NAMESPACE__ . '\OpenEntity'); + $this->articleTags->setEntityClass(__NAMESPACE__ . '\OpenEntity'); } /** @@ -283,7 +283,7 @@ public function testOneOnlyCastMatchingData() 'author_id' => 'derp', 'created' => 'fale' ]; - $this->articles->entityClass(__NAMESPACE__ . '\OpenEntity'); + $this->articles->setEntityClass(__NAMESPACE__ . '\OpenEntity'); $marshall = new Marshaller($this->articles); $result = $marshall->one($data, []); @@ -305,7 +305,7 @@ public function testOneAccessibleProperties() 'author_id' => 1, 'not_in_schema' => true ]; - $this->articles->entityClass(__NAMESPACE__ . '\ProtectedArticle'); + $this->articles->setEntityClass(__NAMESPACE__ . '\ProtectedArticle'); $marshall = new Marshaller($this->articles); $result = $marshall->one($data, []); @@ -327,7 +327,7 @@ public function testOneAccessibleFieldsOption() 'author_id' => 1, 'not_in_schema' => true ]; - $this->articles->entityClass(__NAMESPACE__ . '\ProtectedArticle'); + $this->articles->setEntityClass(__NAMESPACE__ . '\ProtectedArticle'); $marshall = new Marshaller($this->articles); @@ -423,8 +423,8 @@ public function testOneAccessibleFieldsOptionForAssociations() 'username' => 'mark', ] ]; - $this->articles->entityClass(__NAMESPACE__ . '\ProtectedArticle'); - $this->users->entityClass(__NAMESPACE__ . '\ProtectedArticle'); + $this->articles->setEntityClass(__NAMESPACE__ . '\ProtectedArticle'); + $this->users->setEntityClass(__NAMESPACE__ . '\ProtectedArticle'); $marshall = new Marshaller($this->articles); @@ -829,7 +829,7 @@ public function testOneBelongsToManyWithNestedAssociations() */ public function testBelongsToManyAddingNewExisting() { - $this->tags->entityClass(__NAMESPACE__ . '\Tag'); + $this->tags->setEntityClass(__NAMESPACE__ . '\Tag'); $data = [ 'title' => 'My title', 'body' => 'My content', @@ -3360,8 +3360,8 @@ public function testEnsurePrimaryKeyBeingReadFromTableForHandlingEmptyStringPrim ]; $articles = TableRegistry::get('Articles'); - $articles->schema()->dropConstraint('primary'); - $articles->primaryKey('id'); + $articles->getSchema()->dropConstraint('primary'); + $articles->setPrimaryKey('id'); $marshall = new Marshaller($articles); $result = $marshall->one($data); @@ -3390,8 +3390,8 @@ public function testEnsurePrimaryKeyBeingReadFromTableWhenLoadingBelongsToManyRe ]; $tags = TableRegistry::get('Tags'); - $tags->schema()->dropConstraint('primary'); - $tags->primaryKey('id'); + $tags->getSchema()->dropConstraint('primary'); + $tags->setPrimaryKey('id'); $marshall = new Marshaller($this->articles); $result = $marshall->one($data, ['associated' => ['Tags']]); diff --git a/tests/TestCase/ORM/QueryRegressionTest.php b/tests/TestCase/ORM/QueryRegressionTest.php index 8970dbfb22f..476ca1a81e5 100644 --- a/tests/TestCase/ORM/QueryRegressionTest.php +++ b/tests/TestCase/ORM/QueryRegressionTest.php @@ -667,7 +667,7 @@ public function testDeepHasManyEitherStrategy() $tags = TableRegistry::get('Tags'); $this->skipIf( - $tags->connection()->getDriver() instanceof \Cake\Database\Driver\Sqlserver, + $tags->getConnection()->getDriver() instanceof \Cake\Database\Driver\Sqlserver, 'SQL server is temporarily weird in this test, will investigate later' ); $tags = TableRegistry::get('Tags'); diff --git a/tests/TestCase/ORM/ResultSetTest.php b/tests/TestCase/ORM/ResultSetTest.php index 0cda1cbe074..5401beca3fa 100644 --- a/tests/TestCase/ORM/ResultSetTest.php +++ b/tests/TestCase/ORM/ResultSetTest.php @@ -141,7 +141,7 @@ public function testIteratorAfterSerializationHydrated() foreach ($results as $i => $row) { $expected = new Entity($this->fixtureData[$i]); $expected->isNew(false); - $expected->source($this->table->alias()); + $expected->source($this->table->getAlias()); $expected->clean(); $this->assertEquals($expected, $row, "Row $i does not match"); } @@ -235,7 +235,7 @@ public function testGroupBy() $options = [ 'markNew' => false, 'markClean' => true, - 'source' => $this->table->alias() + 'source' => $this->table->getAlias() ]; $expected = [ 1 => [ diff --git a/tests/TestCase/ORM/TableRegressionTest.php b/tests/TestCase/ORM/TableRegressionTest.php index bb3bde8dd29..27bbd7c0343 100644 --- a/tests/TestCase/ORM/TableRegressionTest.php +++ b/tests/TestCase/ORM/TableRegressionTest.php @@ -58,7 +58,7 @@ public function testAfterSaveRollbackTransaction() $table->getEventManager()->on( 'Model.afterSave', function () use ($table) { - $table->connection()->rollback(); + $table->getConnection()->rollback(); } ); $entity = $table->newEntity(['name' => 'Jon']);