From 2b47b1f55b6776a819a353711f97b60a8675f753 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 2 Aug 2019 11:42:14 +0530 Subject: [PATCH] Update use of deprecated MockBuilder::setMethods(). As a result TestCase::getMockModel() no longer accepts null or non existent methods for it's $methods argument. --- src/TestSuite/TestCase.php | 6 +++--- tests/TestCase/TestSuite/TestCaseTest.php | 21 ++++----------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/TestSuite/TestCase.php b/src/TestSuite/TestCase.php index 6c0d43b2d1e..e59ebb7499f 100644 --- a/src/TestSuite/TestCase.php +++ b/src/TestSuite/TestCase.php @@ -753,12 +753,12 @@ protected function skipUnless($condition, $message = '') * Mock a model, maintain fixtures and table association * * @param string $alias The model to get a mock for. - * @param array|null $methods The list of methods to mock + * @param array $methods The list of methods to mock * @param array $options The config data for the mock's constructor. * @throws \Cake\ORM\Exception\MissingTableClassException * @return \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject */ - public function getMockForModel(string $alias, ?array $methods = [], array $options = []) + public function getMockForModel(string $alias, array $methods = [], array $options = []) { $className = $this->_getTableClassName($alias, $options); $connectionName = $className::defaultConnectionName(); @@ -772,7 +772,7 @@ public function getMockForModel(string $alias, ?array $methods = [], array $opti /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $mock */ $mock = $this->getMockBuilder($className) - ->setMethods($methods) + ->onlyMethods($methods) ->setConstructorArgs([$options]) ->getMock(); diff --git a/tests/TestCase/TestSuite/TestCaseTest.php b/tests/TestCase/TestSuite/TestCaseTest.php index fb23349d296..301cb119ccb 100644 --- a/tests/TestCase/TestSuite/TestCaseTest.php +++ b/tests/TestCase/TestSuite/TestCaseTest.php @@ -359,12 +359,10 @@ public function testGetMockForModel() ->will($this->returnValue('mocked')); $this->assertSame('mocked', $Posts->save($entity)); $this->assertSame('Cake\ORM\Entity', $Posts->getEntityClass()); - - $Posts = $this->getMockForModel('Posts', ['doSomething']); $this->assertInstanceOf('Cake\Database\Connection', $Posts->getConnection()); $this->assertSame('test', $Posts->getConnection()->configName()); - $Tags = $this->getMockForModel('Tags', ['doSomething']); + $Tags = $this->getMockForModel('Tags', ['save']); $this->assertSame('TestApp\Model\Entity\Tag', $Tags->getEntityClass()); } @@ -411,7 +409,7 @@ public function testGetMockForModelWithPlugin() $this->assertTrue($TestPluginComment->save($entity)); $this->assertFalse($TestPluginComment->save($entity)); - $TestPluginAuthors = $this->getMockForModel('TestPlugin.Authors', ['doSomething']); + $TestPluginAuthors = $this->getMockForModel('TestPlugin.Authors', ['save']); $this->assertInstanceOf('TestPlugin\Model\Table\AuthorsTable', $TestPluginAuthors); $this->assertSame('TestPlugin\Model\Entity\Author', $TestPluginAuthors->getEntityClass()); $this->clearPlugins(); @@ -453,17 +451,6 @@ public function testGetMockForModelTable() $result = $this->getTableLocator()->get('Comments'); $this->assertInstanceOf(Table::class, $result); $this->assertEmpty([], $allMethodsStubs->getAlias()); - - $allMethodsMocks = $this->getMockForModel( - 'Table', - null, - ['alias' => 'Comments', 'className' => Table::class] - ); - $result = $this->getTableLocator()->get('Comments'); - $this->assertInstanceOf(Table::class, $result); - $this->assertSame('Comments', $allMethodsMocks->getAlias()); - - $this->assertNotEquals($allMethodsStubs, $allMethodsMocks); } /** @@ -475,10 +462,10 @@ public function testGetMockForModelSetTable() { static::setAppNamespace(); - $I18n = $this->getMockForModel('I18n', ['doSomething']); + $I18n = $this->getMockForModel('I18n', ['save']); $this->assertSame('custom_i18n_table', $I18n->getTable()); - $Tags = $this->getMockForModel('Tags', ['doSomething']); + $Tags = $this->getMockForModel('Tags', ['save']); $this->assertSame('tags', $Tags->getTable()); } }