Completed
Push — master ( cd8605...3b7290 )
by
unknown
09:46
created

ContactNameFormatterTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 12
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\ContactBundle\Tests\Unit\Formatter;
4
5
use Oro\Bundle\LocaleBundle\Formatter\NameFormatter;
6
7
use OroCRM\Bundle\ContactBundle\Entity\Contact;
8
use OroCRM\Bundle\ContactBundle\Entity\ContactEmail;
9
use OroCRM\Bundle\ContactBundle\Entity\ContactPhone;
10
use OroCRM\Bundle\ContactBundle\Formatter\ContactNameFormatter;
11
12
class ContactNameFormatterTest extends \PHPUnit_Framework_TestCase
13
{
14
    /** @var NameFormatter */
15
    protected $nameFormatter;
16
17 View Code Duplication
    public function setUp()
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...
18
    {
19
        $this->nameFormatter = $this->getMockBuilder('Oro\Bundle\LocaleBundle\Formatter\NameFormatter')
20
            ->disableOriginalConstructor()
21
            ->getMock();
22
23
        $this->nameFormatter->expects($this->any())
24
            ->method('format')
25
            ->will($this->returnCallback(function (Contact $contact) {
26
                return trim(implode(' ', [$contact->getFirstName(), $contact->getLastName()]));
27
            }));
28
    }
29
30
    /**
31
     * @dataProvider formatDataProvider
32
     */
33
    public function testFormat(Contact $contact, $expectedResult)
34
    {
35
        $contactNameFormatter = new ContactNameFormatter($this->nameFormatter);
36
        $this->assertEquals($expectedResult, $contactNameFormatter->format($contact));
37
    }
38
39
    public function formatDataProvider()
40
    {
41
        return [
42
            'contact with all contact info' => [
43
                (new Contact())
44
                    ->setFirstName('first')
45
                    ->setLastName('last')
46
                    ->addEmail((new ContactEmail('[email protected]'))->setPrimary(true))
0 ignored issues
show
Compatibility introduced by
(new \OroCRM\Bundle\Cont...om'))->setPrimary(true) of type object<Oro\Bundle\Addres...e\Entity\AbstractEmail> is not a sub-type of object<OroCRM\Bundle\Con...le\Entity\ContactEmail>. It seems like you assume a child class of the class Oro\Bundle\AddressBundle\Entity\AbstractEmail to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
47
                    ->addPhone((new ContactPhone('542435'))->setPrimary(true)),
0 ignored issues
show
Compatibility introduced by
(new \OroCRM\Bundle\Cont...35'))->setPrimary(true) of type object<Oro\Bundle\Addres...e\Entity\AbstractPhone> is not a sub-type of object<OroCRM\Bundle\Con...le\Entity\ContactPhone>. It seems like you assume a child class of the class Oro\Bundle\AddressBundle\Entity\AbstractPhone to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
48
                'first last',
49
            ],
50
            'contact with empty name' => [
51
                (new Contact())
52
                    ->addEmail((new ContactEmail('[email protected]'))->setPrimary(true))
0 ignored issues
show
Compatibility introduced by
(new \OroCRM\Bundle\Cont...om'))->setPrimary(true) of type object<Oro\Bundle\Addres...e\Entity\AbstractEmail> is not a sub-type of object<OroCRM\Bundle\Con...le\Entity\ContactEmail>. It seems like you assume a child class of the class Oro\Bundle\AddressBundle\Entity\AbstractEmail to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
53
                    ->addPhone((new ContactPhone('542435'))->setPrimary(true)),
0 ignored issues
show
Compatibility introduced by
(new \OroCRM\Bundle\Cont...35'))->setPrimary(true) of type object<Oro\Bundle\Addres...e\Entity\AbstractPhone> is not a sub-type of object<OroCRM\Bundle\Con...le\Entity\ContactPhone>. It seems like you assume a child class of the class Oro\Bundle\AddressBundle\Entity\AbstractPhone to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
54
                '542435',
55
            ],
56
            'contact with only phone' => [
57
                (new Contact())
58
                    ->addPhone((new ContactPhone('542435'))->setPrimary(true)),
0 ignored issues
show
Compatibility introduced by
(new \OroCRM\Bundle\Cont...35'))->setPrimary(true) of type object<Oro\Bundle\Addres...e\Entity\AbstractPhone> is not a sub-type of object<OroCRM\Bundle\Con...le\Entity\ContactPhone>. It seems like you assume a child class of the class Oro\Bundle\AddressBundle\Entity\AbstractPhone to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
59
                '542435',
60
            ],
61
            'contact with only email' => [
62
                (new Contact())
63
                    ->addEmail((new ContactEmail('[email protected]'))->setPrimary(true)),
0 ignored issues
show
Compatibility introduced by
(new \OroCRM\Bundle\Cont...om'))->setPrimary(true) of type object<Oro\Bundle\Addres...e\Entity\AbstractEmail> is not a sub-type of object<OroCRM\Bundle\Con...le\Entity\ContactEmail>. It seems like you assume a child class of the class Oro\Bundle\AddressBundle\Entity\AbstractEmail to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
64
                '[email protected]',
65
            ],
66
        ];
67
    }
68
}
69