Skip to content

Commit

Permalink
remove getMock() deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
antograssiot committed Jun 7, 2016
1 parent 27dc37b commit 197d2d7
Show file tree
Hide file tree
Showing 13 changed files with 505 additions and 408 deletions.
105 changes: 57 additions & 48 deletions tests/TestCase/ORM/Association/BelongsToManyTest.php
Expand Up @@ -42,23 +42,21 @@ class BelongsToManyTest extends TestCase
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->tag = $this->getMock( $this->tag = $this->getMockBuilder('Cake\ORM\Table')
'Cake\ORM\Table', ->setMethods(['find', 'delete'])
['find', 'delete'], ->setConstructorArgs([['alias' => 'Tags', 'table' => 'tags']])
[['alias' => 'Tags', 'table' => 'tags']] ->getMock();
);
$this->tag->schema([ $this->tag->schema([
'id' => ['type' => 'integer'], 'id' => ['type' => 'integer'],
'name' => ['type' => 'string'], 'name' => ['type' => 'string'],
'_constraints' => [ '_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id']] 'primary' => ['type' => 'primary', 'columns' => ['id']]
] ]
]); ]);
$this->article = $this->getMock( $this->article = $this->getMockBuilder('Cake\ORM\Table')
'Cake\ORM\Table', ->setMethods(['find', 'delete'])
['find', 'delete'], ->setConstructorArgs([['alias' => 'Articles', 'table' => 'articles']])
[['alias' => 'Articles', 'table' => 'articles']] ->getMock();
);
$this->article->schema([ $this->article->schema([
'id' => ['type' => 'integer'], 'id' => ['type' => 'integer'],
'name' => ['type' => 'string'], 'name' => ['type' => 'string'],
Expand Down Expand Up @@ -258,7 +256,9 @@ public function testSaveStrategyInvalid()
*/ */
public function testCascadeDelete() public function testCascadeDelete()
{ {
$articleTag = $this->getMock('Cake\ORM\Table', ['deleteAll'], []); $articleTag = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['deleteAll'])
->getMock();
$config = [ $config = [
'sourceTable' => $this->article, 'sourceTable' => $this->article,
'targetTable' => $this->tag, 'targetTable' => $this->tag,
Expand Down Expand Up @@ -288,7 +288,9 @@ public function testCascadeDelete()
*/ */
public function testCascadeDeleteDependent() public function testCascadeDeleteDependent()
{ {
$articleTag = $this->getMock('Cake\ORM\Table', ['delete', 'deleteAll'], []); $articleTag = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['delete', 'deleteAll'])
->getMock();
$config = [ $config = [
'sourceTable' => $this->article, 'sourceTable' => $this->article,
'targetTable' => $this->tag, 'targetTable' => $this->tag,
Expand Down Expand Up @@ -327,7 +329,9 @@ public function testCascadeDeleteWithCallbacks()
$association->junction($articleTag); $association->junction($articleTag);
$this->article->association($articleTag->alias()); $this->article->association($articleTag->alias());


$counter = $this->getMock('StdClass', ['__invoke']); $counter = $this->getMockBuilder('StdClass')
->setMethods(['__invoke'])
->getMock();
$counter->expects($this->exactly(2))->method('__invoke'); $counter->expects($this->exactly(2))->method('__invoke');
$articleTag->eventManager()->on('Model.beforeDelete', $counter); $articleTag->eventManager()->on('Model.beforeDelete', $counter);


Expand Down Expand Up @@ -386,11 +390,11 @@ public function testLinkWithNotPersistedTarget()
public function testLinkSuccess() public function testLinkSuccess()
{ {
$connection = ConnectionManager::get('test'); $connection = ConnectionManager::get('test');
$joint = $this->getMock( $joint = $this->getMockBuilder('\Cake\ORM\Table')
'\Cake\ORM\Table', ->setMethods(['save'])
['save'], ->setConstructorArgs([['alias' => 'ArticlesTags', 'connection' => $connection]])
[['alias' => 'ArticlesTags', 'connection' => $connection]] ->getMock();
);
$config = [ $config = [
'sourceTable' => $this->article, 'sourceTable' => $this->article,
'targetTable' => $this->tag, 'targetTable' => $this->tag,
Expand Down Expand Up @@ -696,13 +700,14 @@ public function testSaveAssociatedNotEmptyNotIterable()
*/ */
public function testSaveAssociatedEmptySetSuccess($value) public function testSaveAssociatedEmptySetSuccess($value)
{ {
$table = $this->getMock('Cake\ORM\Table', ['table'], [[]]); $table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['table'])
->getMock();
$table->schema([]); $table->schema([]);
$assoc = $this->getMock( $assoc = $this->getMockBuilder('\Cake\ORM\Association\BelongsToMany')
'\Cake\ORM\Association\BelongsToMany', ->setMethods(['_saveTarget', 'replaceLinks'])
['_saveTarget', 'replaceLinks'], ->setConstructorArgs(['tags', ['sourceTable' => $table]])
['tags', ['sourceTable' => $table]] ->getMock();
);
$entity = new Entity([ $entity = new Entity([
'id' => 1, 'id' => 1,
'tags' => $value, 'tags' => $value,
Expand All @@ -724,13 +729,14 @@ public function testSaveAssociatedEmptySetSuccess($value)
*/ */
public function testSaveAssociatedEmptySetUpdateSuccess($value) public function testSaveAssociatedEmptySetUpdateSuccess($value)
{ {
$table = $this->getMock('Cake\ORM\Table', ['table'], [[]]); $table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['table'])
->getMock();
$table->schema([]); $table->schema([]);
$assoc = $this->getMock( $assoc = $this->getMockBuilder('\Cake\ORM\Association\BelongsToMany')
'\Cake\ORM\Association\BelongsToMany', ->setMethods(['_saveTarget', 'replaceLinks'])
['_saveTarget', 'replaceLinks'], ->setConstructorArgs(['tags', ['sourceTable' => $table]])
['tags', ['sourceTable' => $table]] ->getMock();
);
$entity = new Entity([ $entity = new Entity([
'id' => 1, 'id' => 1,
'tags' => $value, 'tags' => $value,
Expand All @@ -755,13 +761,14 @@ public function testSaveAssociatedEmptySetUpdateSuccess($value)
*/ */
public function testSaveAssociatedWithReplace() public function testSaveAssociatedWithReplace()
{ {
$table = $this->getMock('Cake\ORM\Table', ['table'], [[]]); $table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['table'])
->getMock();
$table->schema([]); $table->schema([]);
$assoc = $this->getMock( $assoc = $this->getMockBuilder('\Cake\ORM\Association\BelongsToMany')
'\Cake\ORM\Association\BelongsToMany', ->setMethods(['replaceLinks'])
['replaceLinks'], ->setConstructorArgs(['tags', ['sourceTable' => $table]])
['tags', ['sourceTable' => $table]] ->getMock();
);
$entity = new Entity([ $entity = new Entity([
'id' => 1, 'id' => 1,
'tags' => [ 'tags' => [
Expand All @@ -784,13 +791,14 @@ public function testSaveAssociatedWithReplace()
*/ */
public function testSaveAssociatedWithReplaceReturnFalse() public function testSaveAssociatedWithReplaceReturnFalse()
{ {
$table = $this->getMock('Cake\ORM\Table', ['table'], [[]]); $table = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['table'])
->getMock();
$table->schema([]); $table->schema([]);
$assoc = $this->getMock( $assoc = $this->getMockBuilder('\Cake\ORM\Association\BelongsToMany')
'\Cake\ORM\Association\BelongsToMany', ->setMethods(['replaceLinks'])
['replaceLinks'], ->setConstructorArgs(['tags', ['sourceTable' => $table]])
['tags', ['sourceTable' => $table]] ->getMock();
);
$entity = new Entity([ $entity = new Entity([
'id' => 1, 'id' => 1,
'tags' => [ 'tags' => [
Expand All @@ -814,11 +822,10 @@ public function testSaveAssociatedWithReplaceReturnFalse()
public function testSaveAssociatedOnlyEntitiesAppend() public function testSaveAssociatedOnlyEntitiesAppend()
{ {
$connection = ConnectionManager::get('test'); $connection = ConnectionManager::get('test');
$mock = $this->getMock( $mock = $this->getMockBuilder('Cake\ORM\Table')
'Cake\ORM\Table', ->setMethods(['saveAssociated', 'schema'])
['saveAssociated', 'schema'], ->setConstructorArgs([['table' => 'tags', 'connection' => $connection]])
[['table' => 'tags', 'connection' => $connection]] ->getMock();
);
$mock->primaryKey('id'); $mock->primaryKey('id');


$config = [ $config = [
Expand Down Expand Up @@ -908,7 +915,9 @@ public function testPropertyOption()
*/ */
public function testPropertyNoPlugin() public function testPropertyNoPlugin()
{ {
$mock = $this->getMock('Cake\ORM\Table', [], [], '', false); $mock = $this->getMockBuilder('Cake\ORM\Table')
->disableOriginalConstructor()
->getMock();
$config = [ $config = [
'sourceTable' => $this->article, 'sourceTable' => $this->article,
'targetTable' => $mock, 'targetTable' => $mock,
Expand Down
21 changes: 16 additions & 5 deletions tests/TestCase/ORM/Association/BelongsToTest.php
Expand Up @@ -265,7 +265,9 @@ public function testAttachToMultiPrimaryKeyMistmatch()
*/ */
public function testCascadeDelete() public function testCascadeDelete()
{ {
$mock = $this->getMock('Cake\ORM\Table', [], [], '', false); $mock = $this->getMockBuilder('Cake\ORM\Table')
->disableOriginalConstructor()
->getMock();
$config = [ $config = [
'sourceTable' => $this->client, 'sourceTable' => $this->client,
'targetTable' => $mock, 'targetTable' => $mock,
Expand All @@ -287,7 +289,10 @@ public function testCascadeDelete()
*/ */
public function testSaveAssociatedOnlyEntities() public function testSaveAssociatedOnlyEntities()
{ {
$mock = $this->getMock('Cake\ORM\Table', ['saveAssociated'], [], '', false); $mock = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['saveAssociated'])
->disableOriginalConstructor()
->getMock();
$config = [ $config = [
'sourceTable' => $this->client, 'sourceTable' => $this->client,
'targetTable' => $mock, 'targetTable' => $mock,
Expand Down Expand Up @@ -326,7 +331,9 @@ public function testPropertyOption()
*/ */
public function testPropertyNoPlugin() public function testPropertyNoPlugin()
{ {
$mock = $this->getMock('Cake\ORM\Table', [], [], '', false); $mock = $this->getMockBuilder('Cake\ORM\Table')
->disableOriginalConstructor()
->getMock();
$config = [ $config = [
'sourceTable' => $this->client, 'sourceTable' => $this->client,
'targetTable' => $mock, 'targetTable' => $mock,
Expand All @@ -348,7 +355,9 @@ public function testAttachToBeforeFind()
'sourceTable' => $this->client, 'sourceTable' => $this->client,
'targetTable' => $this->company 'targetTable' => $this->company
]; ];
$listener = $this->getMock('stdClass', ['__invoke']); $listener = $this->getMockBuilder('stdClass')
->setMethods(['__invoke'])
->getMock();
$this->company->eventManager()->attach($listener, 'Model.beforeFind'); $this->company->eventManager()->attach($listener, 'Model.beforeFind');
$association = new BelongsTo('Companies', $config); $association = new BelongsTo('Companies', $config);
$listener->expects($this->once())->method('__invoke') $listener->expects($this->once())->method('__invoke')
Expand All @@ -374,7 +383,9 @@ public function testAttachToBeforeFindExtraOptions()
'sourceTable' => $this->client, 'sourceTable' => $this->client,
'targetTable' => $this->company 'targetTable' => $this->company
]; ];
$listener = $this->getMock('stdClass', ['__invoke']); $listener = $this->getMockBuilder('stdClass')
->setMethods(['__invoke'])
->getMock();
$this->company->eventManager()->attach($listener, 'Model.beforeFind'); $this->company->eventManager()->attach($listener, 'Model.beforeFind');
$association = new BelongsTo('Companies', $config); $association = new BelongsTo('Companies', $config);
$options = new \ArrayObject(['something' => 'more']); $options = new \ArrayObject(['something' => 'more']);
Expand Down
23 changes: 15 additions & 8 deletions tests/TestCase/ORM/Association/HasManyTest.php
Expand Up @@ -57,11 +57,10 @@ public function setUp()
] ]
]); ]);
$connection = ConnectionManager::get('test'); $connection = ConnectionManager::get('test');
$this->article = $this->getMock( $this->article = $this->getMockBuilder('Cake\ORM\Table')
'Cake\ORM\Table', ->setMethods(['find', 'deleteAll', 'delete'])
['find', 'deleteAll', 'delete'], ->setConstructorArgs([['alias' => 'Articles', 'table' => 'articles', 'connection' => $connection]])
[['alias' => 'Articles', 'table' => 'articles', 'connection' => $connection]] ->getMock();
);
$this->article->schema([ $this->article->schema([
'id' => ['type' => 'integer'], 'id' => ['type' => 'integer'],
'title' => ['type' => 'string'], 'title' => ['type' => 'string'],
Expand Down Expand Up @@ -388,7 +387,10 @@ public function testEagerLoaderMultipleKeys()
$this->author->primaryKey(['id', 'site_id']); $this->author->primaryKey(['id', 'site_id']);
$association = new HasMany('Articles', $config); $association = new HasMany('Articles', $config);
$keys = [[1, 10], [2, 20], [3, 30], [4, 40]]; $keys = [[1, 10], [2, 20], [3, 30], [4, 40]];
$query = $this->getMock('Cake\ORM\Query', ['all', 'andWhere'], [null, null]); $query = $this->getMockBuilder('Cake\ORM\Query')
->setMethods(['all', 'andWhere'])
->setConstructorArgs([null, null])
->getMock();
$this->article->method('find') $this->article->method('find')
->with('all') ->with('all')
->will($this->returnValue($query)); ->will($this->returnValue($query));
Expand Down Expand Up @@ -486,7 +488,10 @@ public function testCascadeDeleteCallbacks()
*/ */
public function testSaveAssociatedOnlyEntities() public function testSaveAssociatedOnlyEntities()
{ {
$mock = $this->getMock('Cake\ORM\Table', ['saveAssociated'], [], '', false); $mock = $this->getMockBuilder('Cake\ORM\Table')
->setMethods(['saveAssociated'])
->disableOriginalConstructor()
->getMock();
$config = [ $config = [
'sourceTable' => $this->author, 'sourceTable' => $this->author,
'targetTable' => $mock, 'targetTable' => $mock,
Expand Down Expand Up @@ -527,7 +532,9 @@ public function testPropertyOption()
*/ */
public function testPropertyNoPlugin() public function testPropertyNoPlugin()
{ {
$mock = $this->getMock('Cake\ORM\Table', [], [], '', false); $mock = $this->getMockBuilder('Cake\ORM\Table')
->disableOriginalConstructor()
->getMock();
$config = [ $config = [
'sourceTable' => $this->author, 'sourceTable' => $this->author,
'targetTable' => $mock, 'targetTable' => $mock,
Expand Down

0 comments on commit 197d2d7

Please sign in to comment.