1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\ActivityListBundle\Tests\Unit\Model\Strategy; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\ActivityListBundle\Entity\Manager\ActivityListManager; |
6
|
|
|
use Oro\Bundle\ActivityListBundle\Model\MergeModes; |
7
|
|
|
use Oro\Bundle\ActivityListBundle\Model\Strategy\ReplaceStrategy; |
8
|
|
|
use Oro\Bundle\ActivityListBundle\Model\Strategy\UniteStrategy; |
9
|
|
|
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper; |
10
|
|
|
use Oro\Bundle\EntityMergeBundle\Data\EntityData; |
11
|
|
|
use Oro\Bundle\EntityMergeBundle\Data\FieldData; |
12
|
|
|
use Oro\Bundle\EntityMergeBundle\Metadata\EntityMetadata; |
13
|
|
|
use Oro\Bundle\EntityMergeBundle\Metadata\FieldMetadata; |
14
|
|
|
use Oro\Bundle\UserBundle\Entity\User; |
15
|
|
|
use Symfony\Component\Security\Core\Util\ClassUtils; |
16
|
|
|
|
17
|
|
|
class UniteStrategyTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var ReplaceStrategy $strategy |
21
|
|
|
*/ |
22
|
|
|
protected $strategy; |
23
|
|
|
|
24
|
|
|
/** @var ActivityListManager|\PHPUnit_Framework_MockObject_MockObject */ |
25
|
|
|
protected $activityListManager; |
26
|
|
|
|
27
|
|
|
/** @var DoctrineHelper|\PHPUnit_Framework_MockObject_MockObject */ |
28
|
|
|
protected $doctrineHelper; |
29
|
|
|
|
30
|
|
View Code Duplication |
protected function setUp() |
31
|
|
|
{ |
32
|
|
|
$activityListManager = 'Oro\Bundle\ActivityListBundle\Entity\Manager\ActivityListManager'; |
33
|
|
|
$this->activityListManager = $this->getMockBuilder($activityListManager) |
34
|
|
|
->disableOriginalConstructor() |
35
|
|
|
->getMock(); |
36
|
|
|
|
37
|
|
|
$this->doctrineHelper = $this->getMockBuilder('Oro\Bundle\EntityBundle\ORM\DoctrineHelper') |
38
|
|
|
->disableOriginalConstructor() |
39
|
|
|
->getMock(); |
40
|
|
|
|
41
|
|
|
$this->strategy = new UniteStrategy($this->activityListManager, $this->doctrineHelper); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function testNotSupports() |
45
|
|
|
{ |
46
|
|
|
$fieldData = new FieldData(new EntityData(new EntityMetadata(), []), new FieldMetadata()); |
47
|
|
|
$fieldData->setMode(MergeModes::ACTIVITY_REPLACE); |
48
|
|
|
|
49
|
|
|
$this->assertFalse($this->strategy->supports($fieldData)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
View Code Duplication |
public function testSupports() |
53
|
|
|
{ |
54
|
|
|
$fieldData = new FieldData(new EntityData(new EntityMetadata(), []), new FieldMetadata()); |
55
|
|
|
$fieldData->setMode(MergeModes::ACTIVITY_UNITE); |
56
|
|
|
|
57
|
|
|
$this->assertTrue($this->strategy->supports($fieldData)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
public function testMerge() |
61
|
|
|
{ |
62
|
|
|
$account1 = new User(); |
63
|
|
|
$account2 = new User(); |
64
|
|
|
$this->setId($account1, 1); |
65
|
|
|
$this->setId($account2, 2); |
66
|
|
|
$entityMetadata = new EntityMetadata(['type' => ClassUtils::getRealClass($account1)]); |
67
|
|
|
$entityData = new EntityData($entityMetadata, [$account1, $account2]); |
68
|
|
|
$entityData->setMasterEntity($account1); |
69
|
|
|
$fieldData = new FieldData($entityData, new FieldMetadata()); |
70
|
|
|
$fieldData->setMode(MergeModes::ACTIVITY_UNITE); |
71
|
|
|
|
72
|
|
|
$queryBuilder = $this->getMockBuilder('Doctrine\ORM\QueryBuilder') |
73
|
|
|
->disableOriginalConstructor() |
74
|
|
|
->setMethods(['getQuery', 'getResult']) |
75
|
|
|
->getMock(); |
76
|
|
|
$queryBuilder->expects($this->any()) |
77
|
|
|
->method('getQuery') |
78
|
|
|
->will($this->returnSelf()); |
79
|
|
|
$queryBuilder->expects($this->any()) |
80
|
|
|
->method('getResult') |
81
|
|
|
->will($this->returnValue([ |
82
|
|
|
['id' => 1, 'relatedActivityId' => 11], |
83
|
|
|
['id' => 3, 'relatedActivityId' => 2] |
84
|
|
|
])); |
85
|
|
|
|
86
|
|
|
$repository = $this->getMockBuilder('Oro\Bundle\ActivityListBundle\Entity\Repository\ActivityListRepository') |
87
|
|
|
->disableOriginalConstructor() |
88
|
|
|
->getMock(); |
89
|
|
|
$repository->expects($this->any()) |
90
|
|
|
->method('getActivityListQueryBuilderByActivityClass') |
91
|
|
|
->willReturn($queryBuilder); |
92
|
|
|
$repository->expects($this->any()) |
93
|
|
|
->method('findBy') |
94
|
|
|
->willReturn($this->returnValue([])); |
95
|
|
|
|
96
|
|
|
$this->doctrineHelper |
97
|
|
|
->expects($this->any()) |
98
|
|
|
->method('getEntityRepository') |
99
|
|
|
->willReturn($repository); |
100
|
|
|
|
101
|
|
|
$this->activityListManager |
102
|
|
|
->expects($this->exactly(2)) |
103
|
|
|
->method('replaceActivityTargetWithPlainQuery'); |
104
|
|
|
|
105
|
|
|
$this->strategy->merge($fieldData); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testGetName() |
109
|
|
|
{ |
110
|
|
|
$this->assertEquals('activity_unite', $this->strategy->getName()); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param $object |
115
|
|
|
* @param $value |
116
|
|
|
*/ |
117
|
|
View Code Duplication |
protected function setId($object, $value) |
118
|
|
|
{ |
119
|
|
|
$class = new \ReflectionClass($object); |
120
|
|
|
$property = $class->getProperty('id'); |
121
|
|
|
$property->setAccessible(true); |
122
|
|
|
|
123
|
|
|
$property->setValue($object, $value); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..