Completed
Push — 1.8 ( 8d6730...a2d9e7 )
by
unknown
42:28
created

getNameDQLDataProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 26
rs 8.8571
c 1
b 0
f 1
cc 1
eloc 20
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\SalesBundle\Tests\Unit\Provider;
4
5
use Oro\Bundle\EntityBundle\Provider\EntityNameProviderInterface;
6
use Oro\Bundle\EntityConfigBundle\DependencyInjection\Utils\ServiceLink;
7
8
use OroCRM\Bundle\SalesBundle\Entity\Lead;
9
use OroCRM\Bundle\SalesBundle\Entity\SalesFunnel;
10
use OroCRM\Bundle\SalesBundle\Provider\SalesFunnelEntityNameProvider;
11
12
class SalesFunnelEntityNameProviderTest extends \PHPUnit_Framework_TestCase
13
{
14
    /** @var SalesFunnelEntityNameProvider */
15
    protected $provider;
16
17
    /** @var ServiceLink */
18
    protected $nameFormatterLink;
19
20
    /** @var ServiceLink */
21
    protected $dqlNameFormatterLink;
22
23
    protected function setUp()
24
    {
25
        $this->nameFormatterLink = $this
26
            ->getMockBuilder('Oro\Bundle\EntityConfigBundle\DependencyInjection\Utils\ServiceLink')
27
            ->disableOriginalConstructor()->getMock();
28
        $this->dqlNameFormatterLink = $this
29
            ->getMockBuilder('Oro\Bundle\EntityConfigBundle\DependencyInjection\Utils\ServiceLink')
30
            ->disableOriginalConstructor()->getMock();
31
32
        $this->provider = new SalesFunnelEntityNameProvider($this->nameFormatterLink, $this->dqlNameFormatterLink);
0 ignored issues
show
Unused Code introduced by
The call to SalesFunnelEntityNameProvider::__construct() has too many arguments starting with $this->nameFormatterLink.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
33
    }
34
35
    /**
36
     * @dataProvider getNameDataProvider
37
     *
38
     * @param $format
39
     * @param $locale
40
     * @param $entity
41
     * @param $expected
42
     */
43
    public function testGetName($format, $locale, $entity, $expected)
44
    {
45
        $result = $this->provider->getName($format, $locale, $entity);
46
        $this->assertEquals($expected, $result);
47
    }
48
49
    /**
50
     * @dataProvider getNameDQLDataProvider
51
     *
52
     * @param $format
53
     * @param $locale
54
     * @param $className
55
     * @param $alias
56
     * @param $expected
57
     */
58
    public function testGetNameDQL($format, $locale, $className, $alias, $expected)
59
    {
60
        $result = $this->provider->getNameDQL($format, $locale, $className, $alias);
61
        $this->assertEquals($expected, $result);
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    public function getNameDataProvider()
68
    {
69
        return [
70
            'test unsupported class' => [
71
                'format' => '',
72
                'locale' => null,
73
                'entity' => new \stdClass(),
74
                'expected' => false
75
            ],
76
            'test unsupported format' => [
77
                'format' => '',
78
                'locale' => null,
79
                'entity' => $this->getEntity(),
80
                'expected' => false
81
            ],
82
            'correct data' => [
83
                'format' => SalesFunnelEntityNameProvider::FULL,
84
                'locale' => '',
85
                'entity' => $this->getEntity(),
86
                'expected' => 'Contact'
87
            ]
88
        ];
89
    }
90
91
    /**
92
     * @return array
93
     */
94
    public function getNameDQLDataProvider()
95
    {
96
        return [
97
            'test unsupported class Name' => [
98
                'format' => '',
99
                'locale' => null,
100
                'className' => '',
101
                'alias' => '',
102
                'expected' => false
103
            ],
104
            'test unsupported format' => [
105
                'format' => '',
106
                'locale' => null,
107
                'className' => SalesFunnelEntityNameProvider::CLASS_NAME,
108
                'alias' => '',
109
                'expected' => false
110
            ],
111
            'correct data' => [
112
                'format' => EntityNameProviderInterface::FULL,
113
                'locale' => null,
114
                'className' => SalesFunnelEntityNameProvider::CLASS_NAME,
115
                'alias' => '',
116
                'expected' => 'CONCAT(\'Sales Funnel \', .id)'
117
            ]
118
        ];
119
    }
120
121
    /**
122
     * @return SalesFunnel
123
     */
124
    protected function getEntity()
125
    {
126
        $lead = new Lead();
127
        $lead->setName('Contact');
128
129
        $salesFunnel = new SalesFunnel();
130
        $salesFunnel->setLead($lead);
131
132
        return $salesFunnel;
133
    }
134
}
135