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

GuestCustomerStrategyTest::getCustomer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 1
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\MagentoBundle\Tests\Unit\ImportExport\Strategy;
4
5
use Doctrine\ORM\EntityManager;
6
7
use Oro\Bundle\IntegrationBundle\Entity\Channel;
8
use OroCRM\Bundle\MagentoBundle\Entity\Customer;
9
use OroCRM\Bundle\MagentoBundle\Entity\CustomerGroup;
10
use OroCRM\Bundle\MagentoBundle\Entity\Store;
11
use OroCRM\Bundle\MagentoBundle\Entity\Website;
12
use OroCRM\Bundle\MagentoBundle\ImportExport\Strategy\GuestCustomerStrategy;
13
14
class GuestCustomerStrategyTest extends AbstractStrategyTest
15
{
16
    /**
17
     * @return GuestCustomerStrategy
18
     */
19
    protected function getStrategy()
20
    {
21
        $strategy = new GuestCustomerStrategy(
22
            $this->eventDispatcher,
23
            $this->strategyHelper,
24
            $this->fieldHelper,
25
            $this->databaseHelper,
26
            $this->chainEntityClassNameProvider,
0 ignored issues
show
Unused Code introduced by
The call to GuestCustomerStrategy::__construct() has too many arguments starting with $this->chainEntityClassNameProvider.

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...
27
            $this->translator
28
        );
29
30
        $strategy->setOwnerHelper($this->defaultOwnerHelper);
31
        $strategy->setChannelHelper($this->channelHelper);
32
33
        $this->databaseHelper->expects($this->any())->method('getEntityReference')
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Oro\Bundle\Import...e\Field\DatabaseHelper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
            ->will($this->returnArgument(0));
35
36
        $strategy->setImportExportContext(
37
            $this->getMockBuilder('Oro\Bundle\ImportExportBundle\Context\ContextInterface')
38
            ->disableOriginalConstructor()
39
            ->getMock()
40
        );
41
        $strategy->setEntityName('OroCRM\Bundle\MagentoBundle\Entity\Customer');
42
43
        return $strategy;
44
    }
45
46
    public function testProcessEmptyEntity()
47
    {
48
        $customer = $this->getCustomer();
49
50
        $this->assertNotEmpty($this->getStrategy()->process($customer));
51
    }
52
53
    public function testProcessEntityWithStore()
54
    {
55
        $store = new Store();
56
        $store->setWebsite(new Website());
57
58
        $customer = $this->getCustomer();
59
        $customer->setStore($store);
60
61
        $entityManager = $this->getMockEntityManager();
62
        $this->strategyHelper->expects($this->once())->method('getEntityManager')
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Oro\Bundle\Import...t\ImportStrategyHelper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
            ->willReturn($entityManager);
64
65
        $this->assertNotEmpty($this->getStrategy()->process($customer));
66
    }
67
68
    /**
69
     * @return Customer
70
     */
71
    private function getCustomer()
72
    {
73
        $customer = new Customer();
74
        $customer->setChannel(new Channel());
75
76
        return $customer;
77
    }
78
79
    /**
80
     * @return \PHPUnit_Framework_MockObject_MockObject|EntityManager
81
     */
82
    private function getMockEntityManager()
83
    {
84
        $entityManager = $this->getMockBuilder('Doctrine\ORM\EntityManager')
85
            ->disableOriginalConstructor()->getMock();
86
87
        $repository     = $this->getMockBuilder('Doctrine\ORM\EntityRepository')
88
            ->disableOriginalConstructor()->getMock();
89
        $repository->expects(self::once())->method('findOneBy')->willReturn(new CustomerGroup());
90
91
        $entityManager->expects(self::once())->method('getRepository')->willReturn($repository);
92
93
        return $entityManager;
94
    }
95
}
96