1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\ChannelBundle\Tests\Unit\Provider; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\SecurityBundle\ORM\Walker\AclHelper; |
6
|
|
|
|
7
|
|
|
use OroCRM\Bundle\ChannelBundle\Entity\Channel; |
8
|
|
|
use OroCRM\Bundle\ChannelBundle\Entity\Repository\ChannelRepository; |
9
|
|
|
use OroCRM\Bundle\ChannelBundle\Provider\ChannelsByEntitiesProvider; |
10
|
|
|
|
11
|
|
|
class ChannelsByEntitiesProviderTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var ChannelsByEntitiesProvider |
15
|
|
|
*/ |
16
|
|
|
protected $provider; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var ChannelRepository|\PHPUnit_Framework_MockObject_MockObject |
20
|
|
|
*/ |
21
|
|
|
protected $repo; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var AclHelper|\PHPUnit_Framework_MockObject_MockObject |
25
|
|
|
*/ |
26
|
|
|
protected $aclHelper; |
27
|
|
|
|
28
|
|
|
protected function setUp() |
29
|
|
|
{ |
30
|
|
|
$doctrineHelper = $this |
31
|
|
|
->getMockBuilder('Oro\Bundle\EntityBundle\ORM\DoctrineHelper') |
32
|
|
|
->disableOriginalConstructor() |
33
|
|
|
->getMock(); |
34
|
|
|
|
35
|
|
|
$this->repo = $this |
36
|
|
|
->getMockBuilder('OroCRM\Bundle\ChannelBundle\Entity\Repository\ChannelRepository') |
37
|
|
|
->disableOriginalConstructor() |
38
|
|
|
->getMock(); |
39
|
|
|
|
40
|
|
|
$doctrineHelper |
41
|
|
|
->expects($this->once()) |
42
|
|
|
->method('getEntityRepositoryForClass') |
43
|
|
|
->with('OroCRMChannelBundle:Channel') |
44
|
|
|
->willReturn($this->repo); |
45
|
|
|
|
46
|
|
|
$this->aclHelper = $this->getMockBuilder('Oro\Bundle\SecurityBundle\ORM\Walker\AclHelper') |
47
|
|
|
->disableOriginalConstructor() |
48
|
|
|
->getMock(); |
49
|
|
|
$this->aclHelper->expects($this->any()) |
50
|
|
|
->method('apply') |
51
|
|
|
->will($this->returnArgument(0)); |
52
|
|
|
|
53
|
|
|
$this->provider = new ChannelsByEntitiesProvider($doctrineHelper, $this->aclHelper); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testGetChannelsByEntities() |
57
|
|
|
{ |
58
|
|
|
$channelsForParams1 = [new Channel(), new Channel()]; |
59
|
|
|
$channelsForParams2 = [new Channel(), new Channel()]; |
60
|
|
|
$channelsForParams3 = [new Channel(), new Channel()]; |
61
|
|
|
$data = [ |
62
|
|
|
'entity set#1 and status = true: do not using cache' => [ |
63
|
|
|
$channelsForParams1, |
64
|
|
|
['Entity1', 'Entity2'], |
65
|
|
|
true |
66
|
|
|
], |
67
|
|
|
'entity set#2: do not using cache' => [ |
68
|
|
|
$channelsForParams2, |
69
|
|
|
['Entity1'], |
70
|
|
|
true |
71
|
|
|
], |
72
|
|
|
'entity set#1 and status = false: do not using cache' => [ |
73
|
|
|
$channelsForParams3, |
74
|
|
|
['Entity1', 'Entity2'], |
75
|
|
|
false |
76
|
|
|
], |
77
|
|
|
'entity set#1 and status = true: using cache' => [ |
78
|
|
|
$channelsForParams1, |
79
|
|
|
['Entity1', 'Entity2'], |
80
|
|
|
true |
81
|
|
|
], |
82
|
|
|
'entity set#1 with other order and status = true: using cache' => [ |
83
|
|
|
$channelsForParams1, |
84
|
|
|
['Entity2', 'Entity1'], |
85
|
|
|
true |
86
|
|
|
], |
87
|
|
|
]; |
88
|
|
|
$this->repo |
|
|
|
|
89
|
|
|
->expects($this->any()) |
90
|
|
|
->method('getChannelsByEntities') |
91
|
|
|
->with() |
92
|
|
|
->willReturnMap([ |
93
|
|
|
[['Entity1', 'Entity2'], true, $this->aclHelper, $channelsForParams1], |
94
|
|
|
[['Entity1'], true, $this->aclHelper, $channelsForParams2], |
95
|
|
|
[['Entity1', 'Entity2'], false, $this->aclHelper, $channelsForParams3] |
96
|
|
|
|
97
|
|
|
]); |
98
|
|
|
foreach ($data as $item) { |
99
|
|
|
$result = $item[0]; |
100
|
|
|
$entities = $item[1]; |
101
|
|
|
$status = $item[2]; |
102
|
|
|
$this->assertSame($result, $this->provider->getChannelsByEntities($entities, $status)); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: