Code Duplication    Length = 58-59 lines in 4 locations

src/OroCRM/Bundle/ContactBundle/Tests/Functional/DataFixtures/LoadContactEmailData.php 1 location

@@ 11-69 (lines=59) @@
8
9
use OroCRM\Bundle\ContactBundle\Entity\ContactEmail;
10
11
class LoadContactEmailData extends AbstractFixture implements DependentFixtureInterface
12
{
13
    const FIRST_ENTITY_NAME  = '[email protected]';
14
    const SECOND_ENTITY_NAME = '[email protected]';
15
    const THIRD_ENTITY_NAME  = '[email protected]';
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
            'email' => self::FIRST_ENTITY_NAME,
30
            'primary'  => true,
31
        ],
32
        [
33
            'email' => self::SECOND_ENTITY_NAME,
34
            'primary'  => false,
35
        ],
36
        [
37
            'email' => 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
49
        foreach ($this->contactEmailData as $contactEmailData) {
50
            $contactEmail = new ContactEmail();
51
            $contactEmail->setPrimary($contactEmailData['primary']);
52
            $contactEmail->setOwner($contact);
53
            $contactEmail->setEmail($contactEmailData['email']);
54
            $this->setReference('ContactEmail_Several_' . $contactEmailData['email'], $contactEmail);
55
            $manager->persist($contactEmail);
56
        }
57
58
        $contact2 = $this->getReference('Contact_' . LoadContactEntitiesData::SECOND_ENTITY_NAME);
59
        $contactEmail = new ContactEmail();
60
        $contactEmail->setPrimary($this->contactEmailData[0]['primary']);
61
        $contactEmail->setOwner($contact2);
62
        $contactEmail->setEmail($this->contactEmailData[0]['email']);
63
        $this->setReference('ContactEmail_Single_' . $this->contactEmailData[0]['email'], $contactEmail);
64
        $manager->persist($contactEmail);
65
66
67
        $manager->flush();
68
    }
69
}
70

src/OroCRM/Bundle/ContactBundle/Tests/Functional/DataFixtures/LoadContactPhoneData.php 1 location

@@ 11-68 (lines=58) @@
8
9
use OroCRM\Bundle\ContactBundle\Entity\ContactPhone;
10
11
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

src/OroCRM/Bundle/SalesBundle/Tests/Functional/DataFixtures/LoadB2bCustomerEmailData.php 1 location

@@ 12-70 (lines=59) @@
9
use OroCRM\Bundle\SalesBundle\Tests\Functional\DataFixtures\LoadB2bCustomerEntitiesData;
10
use OroCRM\Bundle\SalesBundle\Entity\B2bCustomerEmail;
11
12
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

src/OroCRM/Bundle/SalesBundle/Tests/Functional/DataFixtures/LoadB2bCustomerPhoneData.php 1 location

@@ 12-69 (lines=58) @@
9
use OroCRM\Bundle\SalesBundle\Tests\Functional\DataFixtures\LoadB2bCustomerEntitiesData;
10
use OroCRM\Bundle\SalesBundle\Entity\B2bCustomerPhone;
11
12
class LoadB2bCustomerPhoneData extends AbstractFixture implements DependentFixtureInterface
13
{
14
    const FIRST_ENTITY_NAME  = '1111111';
15
    const SECOND_ENTITY_NAME = '2222222';
16
    const THIRD_ENTITY_NAME  = '3333333';
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 $b2bCustomerPhoneData = [
29
        [
30
            'phone' => self::FIRST_ENTITY_NAME,
31
            'primary'  => true,
32
        ],
33
        [
34
            'phone' => self::SECOND_ENTITY_NAME,
35
            'primary'  => false,
36
        ],
37
        [
38
            'phone' => 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
        foreach ($this->b2bCustomerPhoneData as $b2bCustomerPhoneData) {
50
            $customerPhone = new B2bCustomerPhone();
51
            $customerPhone->setPrimary($b2bCustomerPhoneData['primary']);
52
            $customerPhone->setOwner($customer);
53
            $customerPhone->setPhone($b2bCustomerPhoneData['phone']);
54
55
            $this->setReference('B2bCustomerPhone_Several_' . $b2bCustomerPhoneData['phone'], $customerPhone);
56
            $manager->persist($customerPhone);
57
        }
58
59
        $customer2 = $this->getReference('B2bCustomer_' . LoadB2bCustomerEntitiesData::SECOND_ENTITY_NAME);
60
        $customerPhone = new B2bCustomerPhone();
61
        $customerPhone->setPrimary($this->b2bCustomerPhoneData[0]['primary']);
62
        $customerPhone->setOwner($customer2);
63
        $customerPhone->setPhone($this->b2bCustomerPhoneData[0]['phone']);
64
        $this->setReference('B2bCustomerPhone_Single_' . $this->b2bCustomerPhoneData[0]['phone'], $customerPhone);
65
        $manager->persist($customerPhone);
66
67
        $manager->flush();
68
    }
69
}
70