Skip to content

Commit

Permalink
Fix more deprecated method usage.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
markstory committed Nov 21, 2017
1 parent 3c0e8d4 commit 158ce98
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/Datasource/Paginator.php
Expand Up @@ -166,7 +166,7 @@ public function paginate($object, array $params = [], array $settings = [])
$object = $query->repository();
}

$alias = $object->alias();
$alias = $object->getAlias();
$defaults = $this->getDefaults($alias, $settings);
$options = $this->mergeOptions($params, $defaults);
$options = $this->validateSort($object, $options);
Expand Down Expand Up @@ -389,7 +389,7 @@ public function validateSort(RepositoryInterface $object, array $options)
*/
protected function _prefix(RepositoryInterface $object, $order, $whitelisted = false)
{
$tableAlias = $object->alias();
$tableAlias = $object->getAlias();
$tableOrder = [];
foreach ($order as $key => $value) {
if (is_numeric($key)) {
Expand Down
30 changes: 20 additions & 10 deletions tests/TestCase/Datasource/PaginatorTest.php
Expand Up @@ -56,9 +56,7 @@ public function setUp()

$this->Paginator = new Paginator();

$this->Post = $this->getMockBuilder('Cake\Datasource\RepositoryInterface')
->disableOriginalConstructor()
->getMock();
$this->Post = $this->getMockRepository();
}

/**
Expand All @@ -80,7 +78,7 @@ public function tearDown()
public function testPageParamCasting()
{
$this->Post->expects($this->any())
->method('alias')
->method('getAlias')
->will($this->returnValue('Posts'));

$query = $this->_getMockFindQuery();
Expand Down Expand Up @@ -615,9 +613,9 @@ public function testValidateSortInvalid()
*/
public function testValidateSortInvalidDirection()
{
$model = $this->getMockBuilder('Cake\Datasource\RepositoryInterface')->getMock();
$model = $this->getMockRepository();
$model->expects($this->any())
->method('alias')
->method('getAlias')
->will($this->returnValue('model'));
$model->expects($this->any())
->method('hasField')
Expand Down Expand Up @@ -749,9 +747,9 @@ public function testValidateSortWhitelistEmpty()
*/
public function testValidateSortWhitelistNotInSchema()
{
$model = $this->getMockBuilder('Cake\Datasource\RepositoryInterface')->getMock();
$model = $this->getMockRepository();
$model->expects($this->any())
->method('alias')
->method('getAlias')
->will($this->returnValue('model'));
$model->expects($this->once())->method('hasField')
->will($this->returnValue(false));
Expand Down Expand Up @@ -796,11 +794,23 @@ public function testValidateSortWhitelistMultiple()
$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()
{
$model = $this->getMockBuilder('Cake\Datasource\RepositoryInterface')->getMock();
$model = $this->getMockRepository();
$model->expects($this->any())
->method('alias')
->method('getAlias')
->will($this->returnValue('model'));
$model->expects($this->any())
->method('hasField')
Expand Down
20 changes: 10 additions & 10 deletions tests/TestCase/View/Form/EntityContextTest.php
Expand Up @@ -675,7 +675,7 @@ public function testValAssociatedCustomIds()
]);

TableRegistry::get('Users')->belongsToMany('Groups');
TableRegistry::get('Groups')->primaryKey('thing');
TableRegistry::get('Groups')->setPrimaryKey('thing');

$result = $context->val('user.groups._ids');
$this->assertEquals([1, 4], $result);
Expand All @@ -689,8 +689,8 @@ public function testValAssociatedCustomIds()
public function testValSchemaDefault()
{
$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();

$context = new EntityContext($this->request, [
Expand All @@ -715,7 +715,7 @@ public function testIsRequiredBooleanField()
'table' => 'Articles',
]);
$articles = TableRegistry::get('Articles');
$articles->schema()->addColumn('comments_on', [
$articles->getSchema()->addColumn('comments_on', [
'type' => 'boolean'
]);

Expand Down Expand Up @@ -795,7 +795,7 @@ public function testIsRequiredAssociatedHasManyBoolean()
$this->_setupTables();

$comments = TableRegistry::get('Comments');
$comments->schema()->addColumn('starred', 'boolean');
$comments->getSchema()->addColumn('starred', 'boolean');
$comments->getValidator()->add('starred', 'valid', ['rule' => 'boolean']);

$row = new Article([
Expand Down Expand Up @@ -1257,26 +1257,26 @@ protected function _setupTables()
$articles->belongsTo('Users');
$articles->belongsToMany('Tags');
$articles->hasMany('Comments');
$articles->entityClass(__NAMESPACE__ . '\Article');
$articles->setEntityClass(__NAMESPACE__ . '\Article');

$articlesTags = TableRegistry::get('ArticlesTags');
$comments = TableRegistry::get('Comments');
$users = TableRegistry::get('Users');
$users->hasMany('Articles');

$articles->schema([
$articles->setSchema([
'id' => ['type' => 'integer', 'length' => 11, 'null' => false],
'title' => ['type' => 'string', 'length' => 255],
'user_id' => ['type' => 'integer', 'length' => 11, 'null' => false],
'body' => ['type' => 'crazy_text', 'baseType' => 'text'],
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
]);
$articlesTags->schema([
$articlesTags->setSchema([
'article_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']]]
]);
$users->schema([
$users->setSchema([
'id' => ['type' => 'integer', 'length' => 11],
'username' => ['type' => 'string', 'length' => 255],
'bio' => ['type' => 'text'],
Expand Down Expand Up @@ -1322,7 +1322,7 @@ public function testFieldNames()
'table' => 'Articles',
]);
$articles = TableRegistry::get('Articles');
$this->assertEquals($articles->schema()->columns(), $context->fieldNames());
$this->assertEquals($articles->getSchema()->columns(), $context->fieldNames());
}

/**
Expand Down
18 changes: 9 additions & 9 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -65,7 +65,7 @@ class ContactsTable extends Table
*/
public function initialize(array $config)
{
$this->schema($this->_schema);
$this->setSchema($this->_schema);
}
}

Expand Down Expand Up @@ -101,7 +101,7 @@ class ValidateUsersTable extends Table
*/
public function initialize(array $config)
{
$this->schema($this->_schema);
$this->setSchema($this->_schema);
}
}

Expand Down Expand Up @@ -1368,7 +1368,7 @@ public function testFileUploadFieldTypeGenerationForBinaries()
$table = TableRegistry::get('Contacts', [
'className' => __NAMESPACE__ . '\ContactsTable'
]);
$table->schema(['foo' => [
$table->setSchema(['foo' => [
'type' => 'binary',
'null' => false,
'default' => null,
Expand Down Expand Up @@ -3302,7 +3302,7 @@ public function testControlZero()
public function testControlCheckbox()
{
$articles = TableRegistry::get('Articles');
$articles->schema()->addColumn('active', ['type' => 'boolean', 'default' => null]);
$articles->getSchema()->addColumn('active', ['type' => 'boolean', 'default' => null]);
$article = $articles->newEntity();

$this->Form->create($article);
Expand Down Expand Up @@ -4381,8 +4381,8 @@ public function testTextDefaultValue()
$this->assertHtml($expected, $result);

$Articles = TableRegistry::get('Articles');
$title = $Articles->schema()->getColumn('title');
$Articles->schema()->addColumn(
$title = $Articles->getSchema()->getColumn('title');
$Articles->getSchema()->addColumn(
'title',
['default' => 'default title'] + $title
);
Expand Down Expand Up @@ -4716,8 +4716,8 @@ public function testRadioComplexDisabled()
public function testRadioDefaultValue()
{
$Articles = TableRegistry::get('Articles');
$title = $Articles->schema()->getColumn('title');
$Articles->schema()->addColumn(
$title = $Articles->getSchema()->getColumn('title');
$Articles->getSchema()->addColumn(
'title',
['default' => '1'] + $title
);
Expand Down Expand Up @@ -5862,7 +5862,7 @@ public function testCheckboxDefaultValue()
$this->assertHtml($expected, $result);

$Articles = TableRegistry::get('Articles');
$Articles->schema()->addColumn(
$Articles->getSchema()->addColumn(
'published',
['type' => 'boolean', 'null' => false, 'default' => true]
);
Expand Down
4 changes: 2 additions & 2 deletions tests/test_app/TestApp/Model/Table/PaginatorPostsTable.php
Expand Up @@ -29,7 +29,7 @@ class PaginatorPostsTable extends Table
*/
public function initialize(array $config)
{
$this->table('posts');
$this->setTable('posts');
$this->belongsTo('PaginatorAuthor', [
'foreignKey' => 'author_id'
]);
Expand All @@ -40,7 +40,7 @@ public function initialize(array $config)
*/
public function findPopular(Query $query, array $options)
{
$field = $this->alias() . '.' . $this->primaryKey();
$field = $this->getAlias() . '.' . $this->getPrimaryKey();
$query->where([$field . ' >' => '1']);

return $query;
Expand Down

0 comments on commit 158ce98

Please sign in to comment.