Completed
Push — master ( 3b7290...73d268 )
by
unknown
11:56
created

ChannelsByEntitiesProviderTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 20
rs 9.4285
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\ChannelBundle\Tests\Unit\Provider;
4
5
use OroCRM\Bundle\ChannelBundle\Entity\Channel;
6
use OroCRM\Bundle\ChannelBundle\Entity\Repository\ChannelRepository;
7
use OroCRM\Bundle\ChannelBundle\Provider\ChannelsByEntitiesProvider;
8
9
class ChannelsByEntitiesProviderTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @var ChannelsByEntitiesProvider
13
     */
14
    protected $provider;
15
16
    /**
17
     * @var ChannelRepository|\PHPUnit_Framework_MockObject_MockObject
18
     */
19
    protected $repo;
20
21
    protected function setUp()
22
    {
23
        $doctrineHelper = $this
24
            ->getMockBuilder('Oro\Bundle\EntityBundle\ORM\DoctrineHelper')
25
            ->disableOriginalConstructor()
26
            ->getMock();
27
28
        $this->repo = $this
29
            ->getMockBuilder('OroCRM\Bundle\ChannelBundle\Entity\Repository\ChannelRepository')
30
            ->disableOriginalConstructor()
31
            ->getMock();
32
33
        $doctrineHelper
34
            ->expects($this->once())
35
            ->method('getEntityRepositoryForClass')
36
            ->with('OroCRMChannelBundle:Channel')
37
            ->willReturn($this->repo);
38
39
        $this->provider = new ChannelsByEntitiesProvider($doctrineHelper);
40
    }
41
42
    public function testGetChannelsByEntities()
43
    {
44
        $channelsForParams1 = [new Channel(), new Channel()];
45
        $channelsForParams2 = [new Channel(), new Channel()];
46
        $channelsForParams3 = [new Channel(), new Channel()];
47
        $data = [
48
            'entity set#1 and status = true: do not using cache'           => [
49
                $channelsForParams1,
50
                ['Entity1', 'Entity2'],
51
                true
52
            ],
53
            'entity set#2: do not using cache'                             => [
54
                $channelsForParams2,
55
                ['Entity1'],
56
                true
57
            ],
58
            'entity set#1 and status = false: do not using cache'          => [
59
                $channelsForParams3,
60
                ['Entity1', 'Entity2'],
61
                false
62
            ],
63
            'entity set#1 and status = true: using cache'                  => [
64
                $channelsForParams1,
65
                ['Entity1', 'Entity2'],
66
                true
67
            ],
68
            'entity set#1 with other order and status = true: using cache' => [
69
                $channelsForParams1,
70
                ['Entity2', 'Entity1'],
71
                true
72
            ],
73
        ];
74
        $this->repo
75
            ->expects($this->any())
76
            ->method('getChannelsByEntities')
77
            ->with()
78
            ->willReturnMap([
79
                [['Entity1', 'Entity2'], true, $channelsForParams1],
80
                [['Entity1'], true, $channelsForParams2],
81
                [['Entity1', 'Entity2'], false, $channelsForParams3]
82
83
            ]);
84
        foreach ($data as $item) {
85
            $result     = $item[0];
86
            $entities   = $item[1];
87
            $status     = $item[2];
88
            $this->assertSame($result, $this->provider->getChannelsByEntities($entities, $status));
89
        }
90
    }
91
}
92