Browse Source

Fix more deprecated method usage.

A number of mocks needed to be adjusted as they were creating mocks of
the interface which does not yet have the undeprecated methods because
adding them would break compatibility, but not having them means mocks
are incomplete.
Mark Story 8 years ago
parent
commit
158ce98b3e

+ 2 - 2
src/Datasource/Paginator.php

@@ -166,7 +166,7 @@ class Paginator implements PaginatorInterface
             $object = $query->repository();
             $object = $query->repository();
         }
         }
 
 
-        $alias = $object->alias();
+        $alias = $object->getAlias();
         $defaults = $this->getDefaults($alias, $settings);
         $defaults = $this->getDefaults($alias, $settings);
         $options = $this->mergeOptions($params, $defaults);
         $options = $this->mergeOptions($params, $defaults);
         $options = $this->validateSort($object, $options);
         $options = $this->validateSort($object, $options);
@@ -389,7 +389,7 @@ class Paginator implements PaginatorInterface
      */
      */
     protected function _prefix(RepositoryInterface $object, $order, $whitelisted = false)
     protected function _prefix(RepositoryInterface $object, $order, $whitelisted = false)
     {
     {
-        $tableAlias = $object->alias();
+        $tableAlias = $object->getAlias();
         $tableOrder = [];
         $tableOrder = [];
         foreach ($order as $key => $value) {
         foreach ($order as $key => $value) {
             if (is_numeric($key)) {
             if (is_numeric($key)) {

+ 20 - 10
tests/TestCase/Datasource/PaginatorTest.php

@@ -56,9 +56,7 @@ class PaginatorTest extends TestCase
 
 
         $this->Paginator = new Paginator();
         $this->Paginator = new Paginator();
 
 
-        $this->Post = $this->getMockBuilder('Cake\Datasource\RepositoryInterface')
-            ->disableOriginalConstructor()
-            ->getMock();
+        $this->Post = $this->getMockRepository();
     }
     }
 
 
     /**
     /**
@@ -80,7 +78,7 @@ class PaginatorTest extends TestCase
     public function testPageParamCasting()
     public function testPageParamCasting()
     {
     {
         $this->Post->expects($this->any())
         $this->Post->expects($this->any())
-            ->method('alias')
+            ->method('getAlias')
             ->will($this->returnValue('Posts'));
             ->will($this->returnValue('Posts'));
 
 
         $query = $this->_getMockFindQuery();
         $query = $this->_getMockFindQuery();
@@ -615,9 +613,9 @@ class PaginatorTest extends TestCase
      */
      */
     public function testValidateSortInvalidDirection()
     public function testValidateSortInvalidDirection()
     {
     {
-        $model = $this->getMockBuilder('Cake\Datasource\RepositoryInterface')->getMock();
+        $model = $this->getMockRepository();
         $model->expects($this->any())
         $model->expects($this->any())
-            ->method('alias')
+            ->method('getAlias')
             ->will($this->returnValue('model'));
             ->will($this->returnValue('model'));
         $model->expects($this->any())
         $model->expects($this->any())
             ->method('hasField')
             ->method('hasField')
@@ -749,9 +747,9 @@ class PaginatorTest extends TestCase
      */
      */
     public function testValidateSortWhitelistNotInSchema()
     public function testValidateSortWhitelistNotInSchema()
     {
     {
-        $model = $this->getMockBuilder('Cake\Datasource\RepositoryInterface')->getMock();
+        $model = $this->getMockRepository();
         $model->expects($this->any())
         $model->expects($this->any())
-            ->method('alias')
+            ->method('getAlias')
             ->will($this->returnValue('model'));
             ->will($this->returnValue('model'));
         $model->expects($this->once())->method('hasField')
         $model->expects($this->once())->method('hasField')
             ->will($this->returnValue(false));
             ->will($this->returnValue(false));
@@ -796,11 +794,23 @@ class PaginatorTest extends TestCase
         $this->assertEquals($expected, $result['order']);
         $this->assertEquals($expected, $result['order']);
     }
     }
 
 
+    protected function getMockRepository()
+    {
+        $model = $this->getMockBuilder('Cake\Datasource\RepositoryInterface')
+            ->setMethods([
+                'getAlias', 'hasField', 'alias', 'find', 'get', 'query', 'updateAll', 'deleteAll',
+                'exists', 'save', 'delete', 'newEntity', 'newEntities', 'patchEntity', 'patchEntities'
+            ])
+            ->getMock();
+
+        return $model;
+    }
+
     protected function mockAliasHasFieldModel()
     protected function mockAliasHasFieldModel()
     {
     {
-        $model = $this->getMockBuilder('Cake\Datasource\RepositoryInterface')->getMock();
+        $model = $this->getMockRepository();
         $model->expects($this->any())
         $model->expects($this->any())
-            ->method('alias')
+            ->method('getAlias')
             ->will($this->returnValue('model'));
             ->will($this->returnValue('model'));
         $model->expects($this->any())
         $model->expects($this->any())
             ->method('hasField')
             ->method('hasField')

+ 10 - 10
tests/TestCase/View/Form/EntityContextTest.php

@@ -675,7 +675,7 @@ class EntityContextTest extends TestCase
         ]);
         ]);
 
 
         TableRegistry::get('Users')->belongsToMany('Groups');
         TableRegistry::get('Users')->belongsToMany('Groups');
-        TableRegistry::get('Groups')->primaryKey('thing');
+        TableRegistry::get('Groups')->setPrimaryKey('thing');
 
 
         $result = $context->val('user.groups._ids');
         $result = $context->val('user.groups._ids');
         $this->assertEquals([1, 4], $result);
         $this->assertEquals([1, 4], $result);
@@ -689,8 +689,8 @@ class EntityContextTest extends TestCase
     public function testValSchemaDefault()
     public function testValSchemaDefault()
     {
     {
         $table = TableRegistry::get('Articles');
         $table = TableRegistry::get('Articles');
-        $column = $table->schema()->getColumn('title');
-        $table->schema()->addColumn('title', ['default' => 'default title'] + $column);
+        $column = $table->getSchema()->getColumn('title');
+        $table->getSchema()->addColumn('title', ['default' => 'default title'] + $column);
         $row = $table->newEntity();
         $row = $table->newEntity();
 
 
         $context = new EntityContext($this->request, [
         $context = new EntityContext($this->request, [
@@ -715,7 +715,7 @@ class EntityContextTest extends TestCase
             'table' => 'Articles',
             'table' => 'Articles',
         ]);
         ]);
         $articles = TableRegistry::get('Articles');
         $articles = TableRegistry::get('Articles');
-        $articles->schema()->addColumn('comments_on', [
+        $articles->getSchema()->addColumn('comments_on', [
             'type' => 'boolean'
             'type' => 'boolean'
         ]);
         ]);
 
 
@@ -795,7 +795,7 @@ class EntityContextTest extends TestCase
         $this->_setupTables();
         $this->_setupTables();
 
 
         $comments = TableRegistry::get('Comments');
         $comments = TableRegistry::get('Comments');
-        $comments->schema()->addColumn('starred', 'boolean');
+        $comments->getSchema()->addColumn('starred', 'boolean');
         $comments->getValidator()->add('starred', 'valid', ['rule' => 'boolean']);
         $comments->getValidator()->add('starred', 'valid', ['rule' => 'boolean']);
 
 
         $row = new Article([
         $row = new Article([
@@ -1257,26 +1257,26 @@ class EntityContextTest extends TestCase
         $articles->belongsTo('Users');
         $articles->belongsTo('Users');
         $articles->belongsToMany('Tags');
         $articles->belongsToMany('Tags');
         $articles->hasMany('Comments');
         $articles->hasMany('Comments');
-        $articles->entityClass(__NAMESPACE__ . '\Article');
+        $articles->setEntityClass(__NAMESPACE__ . '\Article');
 
 
         $articlesTags = TableRegistry::get('ArticlesTags');
         $articlesTags = TableRegistry::get('ArticlesTags');
         $comments = TableRegistry::get('Comments');
         $comments = TableRegistry::get('Comments');
         $users = TableRegistry::get('Users');
         $users = TableRegistry::get('Users');
         $users->hasMany('Articles');
         $users->hasMany('Articles');
 
 
-        $articles->schema([
+        $articles->setSchema([
             'id' => ['type' => 'integer', 'length' => 11, 'null' => false],
             'id' => ['type' => 'integer', 'length' => 11, 'null' => false],
             'title' => ['type' => 'string', 'length' => 255],
             'title' => ['type' => 'string', 'length' => 255],
             'user_id' => ['type' => 'integer', 'length' => 11, 'null' => false],
             'user_id' => ['type' => 'integer', 'length' => 11, 'null' => false],
             'body' => ['type' => 'crazy_text', 'baseType' => 'text'],
             'body' => ['type' => 'crazy_text', 'baseType' => 'text'],
             '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
             '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
         ]);
         ]);
-        $articlesTags->schema([
+        $articlesTags->setSchema([
             'article_id' => ['type' => 'integer', 'length' => 11, 'null' => false],
             'article_id' => ['type' => 'integer', 'length' => 11, 'null' => false],
             'tag_id' => ['type' => 'integer', 'length' => 11, 'null' => false],
             'tag_id' => ['type' => 'integer', 'length' => 11, 'null' => false],
             '_constraints' => ['unique_tag' => ['type' => 'primary', 'columns' => ['article_id', 'tag_id']]]
             '_constraints' => ['unique_tag' => ['type' => 'primary', 'columns' => ['article_id', 'tag_id']]]
         ]);
         ]);
-        $users->schema([
+        $users->setSchema([
             'id' => ['type' => 'integer', 'length' => 11],
             'id' => ['type' => 'integer', 'length' => 11],
             'username' => ['type' => 'string', 'length' => 255],
             'username' => ['type' => 'string', 'length' => 255],
             'bio' => ['type' => 'text'],
             'bio' => ['type' => 'text'],
@@ -1322,7 +1322,7 @@ class EntityContextTest extends TestCase
             'table' => 'Articles',
             'table' => 'Articles',
         ]);
         ]);
         $articles = TableRegistry::get('Articles');
         $articles = TableRegistry::get('Articles');
-        $this->assertEquals($articles->schema()->columns(), $context->fieldNames());
+        $this->assertEquals($articles->getSchema()->columns(), $context->fieldNames());
     }
     }
 
 
     /**
     /**

+ 9 - 9
tests/TestCase/View/Helper/FormHelperTest.php

@@ -65,7 +65,7 @@ class ContactsTable extends Table
      */
      */
     public function initialize(array $config)
     public function initialize(array $config)
     {
     {
-        $this->schema($this->_schema);
+        $this->setSchema($this->_schema);
     }
     }
 }
 }
 
 
@@ -101,7 +101,7 @@ class ValidateUsersTable extends Table
      */
      */
     public function initialize(array $config)
     public function initialize(array $config)
     {
     {
-        $this->schema($this->_schema);
+        $this->setSchema($this->_schema);
     }
     }
 }
 }
 
 
@@ -1368,7 +1368,7 @@ class FormHelperTest extends TestCase
         $table = TableRegistry::get('Contacts', [
         $table = TableRegistry::get('Contacts', [
             'className' => __NAMESPACE__ . '\ContactsTable'
             'className' => __NAMESPACE__ . '\ContactsTable'
         ]);
         ]);
-        $table->schema(['foo' => [
+        $table->setSchema(['foo' => [
             'type' => 'binary',
             'type' => 'binary',
             'null' => false,
             'null' => false,
             'default' => null,
             'default' => null,
@@ -3302,7 +3302,7 @@ class FormHelperTest extends TestCase
     public function testControlCheckbox()
     public function testControlCheckbox()
     {
     {
         $articles = TableRegistry::get('Articles');
         $articles = TableRegistry::get('Articles');
-        $articles->schema()->addColumn('active', ['type' => 'boolean', 'default' => null]);
+        $articles->getSchema()->addColumn('active', ['type' => 'boolean', 'default' => null]);
         $article = $articles->newEntity();
         $article = $articles->newEntity();
 
 
         $this->Form->create($article);
         $this->Form->create($article);
@@ -4381,8 +4381,8 @@ class FormHelperTest extends TestCase
         $this->assertHtml($expected, $result);
         $this->assertHtml($expected, $result);
 
 
         $Articles = TableRegistry::get('Articles');
         $Articles = TableRegistry::get('Articles');
-        $title = $Articles->schema()->getColumn('title');
-        $Articles->schema()->addColumn(
+        $title = $Articles->getSchema()->getColumn('title');
+        $Articles->getSchema()->addColumn(
             'title',
             'title',
             ['default' => 'default title'] + $title
             ['default' => 'default title'] + $title
         );
         );
@@ -4716,8 +4716,8 @@ class FormHelperTest extends TestCase
     public function testRadioDefaultValue()
     public function testRadioDefaultValue()
     {
     {
         $Articles = TableRegistry::get('Articles');
         $Articles = TableRegistry::get('Articles');
-        $title = $Articles->schema()->getColumn('title');
-        $Articles->schema()->addColumn(
+        $title = $Articles->getSchema()->getColumn('title');
+        $Articles->getSchema()->addColumn(
             'title',
             'title',
             ['default' => '1'] + $title
             ['default' => '1'] + $title
         );
         );
@@ -5862,7 +5862,7 @@ class FormHelperTest extends TestCase
         $this->assertHtml($expected, $result);
         $this->assertHtml($expected, $result);
 
 
         $Articles = TableRegistry::get('Articles');
         $Articles = TableRegistry::get('Articles');
-        $Articles->schema()->addColumn(
+        $Articles->getSchema()->addColumn(
             'published',
             'published',
             ['type' => 'boolean', 'null' => false, 'default' => true]
             ['type' => 'boolean', 'null' => false, 'default' => true]
         );
         );

+ 2 - 2
tests/test_app/TestApp/Model/Table/PaginatorPostsTable.php

@@ -29,7 +29,7 @@ class PaginatorPostsTable extends Table
      */
      */
     public function initialize(array $config)
     public function initialize(array $config)
     {
     {
-        $this->table('posts');
+        $this->setTable('posts');
         $this->belongsTo('PaginatorAuthor', [
         $this->belongsTo('PaginatorAuthor', [
             'foreignKey' => 'author_id'
             'foreignKey' => 'author_id'
         ]);
         ]);
@@ -40,7 +40,7 @@ class PaginatorPostsTable extends Table
      */
      */
     public function findPopular(Query $query, array $options)
     public function findPopular(Query $query, array $options)
     {
     {
-        $field = $this->alias() . '.' . $this->primaryKey();
+        $field = $this->getAlias() . '.' . $this->getPrimaryKey();
         $query->where([$field . ' >' => '1']);
         $query->where([$field . ' >' => '1']);
 
 
         return $query;
         return $query;