Skip to content

Commit

Permalink
Fix remaining deprecations for table methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 21, 2017
1 parent 158ce98 commit 990eb1c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 32 deletions.
2 changes: 1 addition & 1 deletion tests/TestCase/Auth/FormAuthenticateTest.php
Expand Up @@ -226,7 +226,7 @@ public function testAuthenticateSuccess()
public function testAuthenticateIncludesVirtualFields()
{
$users = TableRegistry::get('Users');
$users->entityClass('TestApp\Model\Entity\VirtualUser');
$users->setEntityClass('TestApp\Model\Entity\VirtualUser');

$request = new ServerRequest('posts/index');
$request->data = [
Expand Down
59 changes: 35 additions & 24 deletions tests/TestCase/Controller/Component/PaginatorComponentTest.php
Expand Up @@ -86,9 +86,7 @@ public function setUp()
$this->registry = new ComponentRegistry($controller);
$this->Paginator = new PaginatorComponent($this->registry, []);

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

/**
Expand Down Expand Up @@ -145,7 +143,7 @@ public function testInvalidPaginatorOption()
public function testPageParamCasting()
{
$this->Post->expects($this->any())
->method('alias')
->method('getAlias')
->will($this->returnValue('Posts'));

$query = $this->_getMockFindQuery();
Expand Down Expand Up @@ -665,9 +663,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 @@ -791,9 +789,9 @@ public function testOutOfVeryBigPageNumberGetsClamped()
*/
public function testValidateSortWhitelistFailure()
{
$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')->will($this->returnValue(true));

Expand All @@ -814,9 +812,9 @@ public function testValidateSortWhitelistFailure()
*/
public function testValidateSortWhitelistTrusted()
{
$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')
Expand Down Expand Up @@ -844,9 +842,9 @@ public function testValidateSortWhitelistTrusted()
*/
public function testValidateSortWhitelistEmpty()
{
$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')
->will($this->returnValue(true));
Expand All @@ -872,9 +870,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 All @@ -901,9 +899,9 @@ public function testValidateSortWhitelistNotInSchema()
*/
public function testValidateSortWhitelistMultiple()
{
$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')
Expand Down Expand Up @@ -932,9 +930,9 @@ public function testValidateSortWhitelistMultiple()
*/
public function testValidateSortMultiple()
{
$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')->will($this->returnValue(true));

Expand All @@ -961,9 +959,9 @@ public function testValidateSortMultiple()
*/
public function testValidateSortWithString()
{
$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')->will($this->returnValue(true));

Expand All @@ -983,9 +981,9 @@ public function testValidateSortWithString()
*/
public function testValidateSortNoSort()
{
$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')
->will($this->returnValue(true));
Expand All @@ -1005,9 +1003,9 @@ public function testValidateSortNoSort()
*/
public function testValidateSortInvalidAlias()
{
$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')->will($this->returnValue(true));

Expand Down Expand Up @@ -1381,4 +1379,17 @@ protected function _getMockFindQuery($table = null)

return $query;
}

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;
}

}
8 changes: 4 additions & 4 deletions tests/TestCase/Database/Schema/TableTest.php
Expand Up @@ -576,7 +576,7 @@ public function testAddConstraintForeignKey()
public function testConstraintForeignKey()
{
$table = TableRegistry::get('ArticlesTags');
$compositeConstraint = $table->schema()->getConstraint('tag_id_fk');
$compositeConstraint = $table->getSchema()->getConstraint('tag_id_fk');
$expected = [
'type' => 'foreign',
'columns' => ['tag_id'],
Expand All @@ -589,7 +589,7 @@ public function testConstraintForeignKey()
$this->assertEquals($expected, $compositeConstraint);

$expectedSubstring = 'CONSTRAINT <tag_id_fk> FOREIGN KEY \(<tag_id>\) REFERENCES <tags> \(<id>\)';
$this->assertQuotedQuery($expectedSubstring, $table->schema()->createSql(ConnectionManager::get('test'))[0]);
$this->assertQuotedQuery($expectedSubstring, $table->getSchema()->createSql(ConnectionManager::get('test'))[0]);
}

/**
Expand All @@ -600,7 +600,7 @@ public function testConstraintForeignKey()
public function testConstraintForeignKeyTwoColumns()
{
$table = TableRegistry::get('Orders');
$compositeConstraint = $table->schema()->getConstraint('product_category_fk');
$compositeConstraint = $table->getSchema()->getConstraint('product_category_fk');
$expected = [
'type' => 'foreign',
'columns' => [
Expand All @@ -620,7 +620,7 @@ public function testConstraintForeignKeyTwoColumns()
$expectedSubstring = 'CONSTRAINT <product_category_fk> FOREIGN KEY \(<product_category>, <product_id>\)' .
' REFERENCES <products> \(<category>, <id>\)';

$this->assertQuotedQuery($expectedSubstring, $table->schema()->createSql(ConnectionManager::get('test'))[0]);
$this->assertQuotedQuery($expectedSubstring, $table->getSchema()->createSql(ConnectionManager::get('test'))[0]);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Network/Session/DatabaseSessionTest.php
Expand Up @@ -71,9 +71,9 @@ public function testConstructionSettings()

$session = TableRegistry::get('Sessions');
$this->assertInstanceOf('Cake\ORM\Table', $session);
$this->assertEquals('Sessions', $session->alias());
$this->assertEquals(ConnectionManager::get('test'), $session->connection());
$this->assertEquals('sessions', $session->table());
$this->assertEquals('Sessions', $session->getAlias());
$this->assertEquals(ConnectionManager::get('test'), $session->getConnection());
$this->assertEquals('sessions', $session->getTable());
}

/**
Expand Down

0 comments on commit 990eb1c

Please sign in to comment.