1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\SalesBundle\Tests\Functional\DataFixtures; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture; |
6
|
|
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface; |
7
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
8
|
|
|
|
9
|
|
|
use OroCRM\Bundle\SalesBundle\Tests\Functional\DataFixtures\LoadB2bCustomerEntitiesData; |
10
|
|
|
use OroCRM\Bundle\SalesBundle\Entity\B2bCustomerEmail; |
11
|
|
|
|
12
|
|
View Code Duplication |
class LoadB2bCustomerEmailData extends AbstractFixture implements DependentFixtureInterface |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
const FIRST_ENTITY_NAME = '[email protected]'; |
15
|
|
|
const SECOND_ENTITY_NAME = '[email protected]'; |
16
|
|
|
const THIRD_ENTITY_NAME = '[email protected]'; |
17
|
|
|
|
18
|
|
|
public function getDependencies() |
19
|
|
|
{ |
20
|
|
|
return [ |
21
|
|
|
'OroCRM\Bundle\SalesBundle\Tests\Functional\DataFixtures\LoadB2bCustomerEntitiesData' |
22
|
|
|
]; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $b2bCustomerEmailData = [ |
29
|
|
|
[ |
30
|
|
|
'email' => self::FIRST_ENTITY_NAME, |
31
|
|
|
'primary' => true, |
32
|
|
|
], |
33
|
|
|
[ |
34
|
|
|
'email' => self::SECOND_ENTITY_NAME, |
35
|
|
|
'primary' => false, |
36
|
|
|
], |
37
|
|
|
[ |
38
|
|
|
'email' => self::THIRD_ENTITY_NAME, |
39
|
|
|
'primary' => false, |
40
|
|
|
] |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
public function load(ObjectManager $manager) |
47
|
|
|
{ |
48
|
|
|
$customer = $this->getReference('B2bCustomer_' . LoadB2bCustomerEntitiesData::FIRST_ENTITY_NAME); |
49
|
|
|
|
50
|
|
|
foreach ($this->b2bCustomerEmailData as $b2bCustomerEmailData) { |
51
|
|
|
$customerEmail = new B2bCustomerEmail(); |
52
|
|
|
$customerEmail->setPrimary($b2bCustomerEmailData['primary']); |
53
|
|
|
$customerEmail->setOwner($customer); |
54
|
|
|
$customerEmail->setEmail($b2bCustomerEmailData['email']); |
55
|
|
|
$this->setReference('B2bCustomerEmail_Several_' . $b2bCustomerEmailData['email'], $customerEmail); |
56
|
|
|
$manager->persist($customerEmail); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$customer2 = $this->getReference('B2bCustomer_' . LoadB2bCustomerEntitiesData::SECOND_ENTITY_NAME); |
60
|
|
|
$customerEmail = new B2bCustomerEmail(); |
61
|
|
|
$customerEmail->setPrimary($this->b2bCustomerEmailData[0]['primary']); |
62
|
|
|
$customerEmail->setOwner($customer2); |
63
|
|
|
$customerEmail->setEmail($this->b2bCustomerEmailData[0]['email']); |
64
|
|
|
$this->setReference('B2bCustomerEmail_Single_' . $this->b2bCustomerEmailData[0]['email'], $customerEmail); |
65
|
|
|
$manager->persist($customerEmail); |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
$manager->flush(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
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.