From 990eb1cda3edc1595e630b398702bb0a62070ccc Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 21 Nov 2017 07:58:38 -0500 Subject: [PATCH] Fix remaining deprecations for table methods. --- tests/TestCase/Auth/FormAuthenticateTest.php | 2 +- .../Component/PaginatorComponentTest.php | 59 +++++++++++-------- tests/TestCase/Database/Schema/TableTest.php | 8 +-- .../Network/Session/DatabaseSessionTest.php | 6 +- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/tests/TestCase/Auth/FormAuthenticateTest.php b/tests/TestCase/Auth/FormAuthenticateTest.php index 89b9e651437..d4dbc38c760 100644 --- a/tests/TestCase/Auth/FormAuthenticateTest.php +++ b/tests/TestCase/Auth/FormAuthenticateTest.php @@ -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 = [ diff --git a/tests/TestCase/Controller/Component/PaginatorComponentTest.php b/tests/TestCase/Controller/Component/PaginatorComponentTest.php index 2bcdf49dc42..cdac8c6cbe1 100644 --- a/tests/TestCase/Controller/Component/PaginatorComponentTest.php +++ b/tests/TestCase/Controller/Component/PaginatorComponentTest.php @@ -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(); } /** @@ -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(); @@ -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') @@ -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)); @@ -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') @@ -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)); @@ -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)); @@ -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') @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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; + } + } diff --git a/tests/TestCase/Database/Schema/TableTest.php b/tests/TestCase/Database/Schema/TableTest.php index d70e2d0c37f..01f4cd67c52 100644 --- a/tests/TestCase/Database/Schema/TableTest.php +++ b/tests/TestCase/Database/Schema/TableTest.php @@ -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'], @@ -589,7 +589,7 @@ public function testConstraintForeignKey() $this->assertEquals($expected, $compositeConstraint); $expectedSubstring = 'CONSTRAINT FOREIGN KEY \(\) REFERENCES \(\)'; - $this->assertQuotedQuery($expectedSubstring, $table->schema()->createSql(ConnectionManager::get('test'))[0]); + $this->assertQuotedQuery($expectedSubstring, $table->getSchema()->createSql(ConnectionManager::get('test'))[0]); } /** @@ -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' => [ @@ -620,7 +620,7 @@ public function testConstraintForeignKeyTwoColumns() $expectedSubstring = 'CONSTRAINT FOREIGN KEY \(, \)' . ' REFERENCES \(, \)'; - $this->assertQuotedQuery($expectedSubstring, $table->schema()->createSql(ConnectionManager::get('test'))[0]); + $this->assertQuotedQuery($expectedSubstring, $table->getSchema()->createSql(ConnectionManager::get('test'))[0]); } /** diff --git a/tests/TestCase/Network/Session/DatabaseSessionTest.php b/tests/TestCase/Network/Session/DatabaseSessionTest.php index d4c44f9f029..ab339d94c90 100644 --- a/tests/TestCase/Network/Session/DatabaseSessionTest.php +++ b/tests/TestCase/Network/Session/DatabaseSessionTest.php @@ -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()); } /**