Completed
Push — master ( a18731...e2e070 )
by
unknown
99:54 queued 47:45
created

ChannelsByEntitiesProviderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 95
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 27 1
A testGetChannelsByEntities() 0 49 2
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
0 ignored issues
show
Documentation Bug introduced by
The method expects does not exist on object<OroCRM\Bundle\Cha...tory\ChannelRepository>? Since you implemented __call, maybe consider adding a @method annotation.

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:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
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