1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\ContactBundle\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\ContactBundle\Entity\ContactPhone; |
10
|
|
|
|
11
|
|
View Code Duplication |
class LoadContactPhoneData extends AbstractFixture implements DependentFixtureInterface |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
const FIRST_ENTITY_NAME = '1111111'; |
14
|
|
|
const SECOND_ENTITY_NAME = '2222222'; |
15
|
|
|
const THIRD_ENTITY_NAME = '3333333'; |
16
|
|
|
|
17
|
|
|
public function getDependencies() |
18
|
|
|
{ |
19
|
|
|
return [ |
20
|
|
|
'OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactEntitiesData' |
21
|
|
|
]; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $contactEmailData = [ |
28
|
|
|
[ |
29
|
|
|
'phone' => self::FIRST_ENTITY_NAME, |
30
|
|
|
'primary' => true, |
31
|
|
|
], |
32
|
|
|
[ |
33
|
|
|
'phone' => self::SECOND_ENTITY_NAME, |
34
|
|
|
'primary' => false, |
35
|
|
|
], |
36
|
|
|
[ |
37
|
|
|
'phone' => self::THIRD_ENTITY_NAME, |
38
|
|
|
'primary' => false, |
39
|
|
|
] |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function load(ObjectManager $manager) |
46
|
|
|
{ |
47
|
|
|
$contact = $this->getReference('Contact_' . LoadContactEntitiesData::FIRST_ENTITY_NAME); |
48
|
|
|
foreach ($this->contactEmailData as $contactEmailData) { |
49
|
|
|
$contactPhone = new ContactPhone(); |
50
|
|
|
$contactPhone->setPrimary($contactEmailData['primary']); |
51
|
|
|
$contactPhone->setOwner($contact); |
52
|
|
|
$contactPhone->setPhone($contactEmailData['phone']); |
53
|
|
|
|
54
|
|
|
$this->setReference('ContactPhone_Several_' . $contactEmailData['phone'], $contactPhone); |
55
|
|
|
$manager->persist($contactPhone); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$contact2 = $this->getReference('Contact_' . LoadContactEntitiesData::SECOND_ENTITY_NAME); |
59
|
|
|
$contactPhone = new ContactPhone(); |
60
|
|
|
$contactPhone->setPrimary($this->contactEmailData[0]['primary']); |
61
|
|
|
$contactPhone->setOwner($contact2); |
62
|
|
|
$contactPhone->setPhone($this->contactEmailData[0]['phone']); |
63
|
|
|
$this->setReference('ContactPhone_Single_' . $this->contactEmailData[0]['phone'], $contactPhone); |
64
|
|
|
$manager->persist($contactPhone); |
65
|
|
|
|
66
|
|
|
$manager->flush(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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.