Completed
Push — master ( c2375b...0b658a )
by
unknown
09:35
created

getNameDQLDataProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 20

Duplication

Lines 26
Ratio 100 %
Metric Value
dl 26
loc 26
rs 8.8571
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
29
        $this->dqlNameFormatterLink = $this
30
            ->getMockBuilder('Oro\Bundle\EntityConfigBundle\DependencyInjection\Utils\ServiceLink')
31
            ->disableOriginalConstructor()->getMock();
32
33
        $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...
34
    }
35
36
    /**
37
     * @dataProvider getNameDataProvider
38
     *
39
     * @param $format
40
     * @param $locale
41
     * @param $entity
42
     * @param $expected
43
     */
44
    public function testGetName($format, $locale, $entity, $expected)
45
    {
46
        $result = $this->provider->getName($format, $locale, $entity);
47
        $this->assertEquals($expected, $result);
48
    }
49
50
    /**
51
     * @dataProvider getNameDQLDataProvider
52
     *
53
     * @param $format
54
     * @param $locale
55
     * @param $className
56
     * @param $alias
57
     * @param $expected
58
     */
59
    public function testGetNameDQL($format, $locale, $className, $alias, $expected)
60
    {
61
        $result = $this->provider->getNameDQL($format, $locale, $className, $alias);
62
        $this->assertEquals($expected, $result);
63
    }
64
65
    /**
66
     * @return array
67
     */
68 View Code Duplication
    public function getNameDataProvider()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        return [
71
            'test unsupported class' => [
72
                'format' => '',
73
                'locale' => null,
74
                'entity' => new \stdClass(),
75
                'expected' => false
76
            ],
77
            'test unsupported format' => [
78
                'format' => '',
79
                'locale' => null,
80
                'entity' => $this->getEntity(),
81
                'expected' => false
82
            ],
83
            'correct data' => [
84
                'format' => SalesFunnelEntityNameProvider::FULL,
85
                'locale' => '',
86
                'entity' => $this->getEntity(),
87
                'expected' => 'Contact'
88
            ]
89
        ];
90
    }
91
92
    /**
93
     * @return array
94
     */
95 View Code Duplication
    public function getNameDQLDataProvider()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        return [
98
            'test unsupported class Name' => [
99
                'format' => '',
100
                'locale' => null,
101
                'className' => '',
102
                'alias' => '',
103
                'expected' => false
104
            ],
105
            'test unsupported format' => [
106
                'format' => '',
107
                'locale' => null,
108
                'className' => SalesFunnelEntityNameProvider::CLASS_NAME,
109
                'alias' => '',
110
                'expected' => false
111
            ],
112
            'correct data' => [
113
                'format' => EntityNameProviderInterface::FULL,
114
                'locale' => null,
115
                'className' => SalesFunnelEntityNameProvider::CLASS_NAME,
116
                'alias' => '',
117
                'expected' => 'CONCAT(\'Sales Funnel \', .id)'
118
            ]
119
        ];
120
    }
121
122
    /**
123
     * @return SalesFunnel
124
     */
125
    protected function getEntity()
126
    {
127
        $lead = new Lead();
128
        $lead->setName('Contact');
129
130
        $salesFunnel = new SalesFunnel();
131
        $salesFunnel->setLead($lead);
132
133
        return $salesFunnel;
134
    }
135
}
136