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, |
|
|
|
|
27
|
|
|
$this->translator |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$strategy->setOwnerHelper($this->defaultOwnerHelper); |
31
|
|
|
$strategy->setChannelHelper($this->channelHelper); |
32
|
|
|
|
33
|
|
|
$this->databaseHelper->expects($this->any())->method('getEntityReference') |
|
|
|
|
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') |
|
|
|
|
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
|
|
|
|
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.