Completed
Push — master ( 3560db...6e658b )
by
unknown
08:14
created

RestContactEmailApiTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 89
Duplicated Lines 82.02 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 8
Bugs 2 Features 5
Metric Value
wmc 7
c 8
b 2
f 5
lcom 2
cbo 2
dl 73
loc 89
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testCreateContactEmail() 15 15 1
A testCreateSecondPrimaryEmail() 12 12 1
A testEmptyContactId() 10 10 1
A testEmptyEmail() 11 11 1
A testDeleteEmailForbidden() 14 14 1
A testDeleteEmailSuccess() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace OroCRM\Bundle\ContactBundle\Tests\Functional\API;
4
5
use FOS\RestBundle\Util\Codes;
6
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase;
7
use OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactEmailData;
8
use OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactEntitiesData;
9
10
/**
11
 * @outputBuffering enabled
12
 * @dbIsolation
13
 */
14
class RestContactEmailApiTest extends WebTestCase
15
{
16
    protected function setUp()
17
    {
18
        $this->initClient([], $this->generateWsseAuthHeader());
19
        $this->loadFixtures([
20
            'OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactEmailData'
21
        ]);
22
    }
23
24 View Code Duplication
    public function testCreateContactEmail()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
25
    {
26
        $contact = $this->getReference('Contact_' . LoadContactEntitiesData::THIRD_ENTITY_NAME);
27
        $content = json_encode([
28
            'contactId' => $contact->getId(),
29
            'email' =>'[email protected]',
30
            'primary' => true
31
        ]);
32
33
        $this->client->request('POST', $this->getUrl('oro_api_post_contact_email'), [], [], [], $content);
34
        $contact = $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_CREATED);
35
36
        $this->assertArrayHasKey('id', $contact);
37
        $this->assertNotEmpty($contact['id']);
38
    }
39
40 View Code Duplication
    public function testCreateSecondPrimaryEmail()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
41
    {
42
        $contact = $this->getReference('Contact_Brenda');
43
        $content = json_encode([
44
            'contactId' => $contact->getId(),
45
            'email' =>'[email protected]',
46
            'primary' => true
47
        ]);
48
49
        $this->client->request('POST', $this->getUrl('oro_api_post_contact_email'), [], [], [], $content);
50
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_BAD_REQUEST);
51
    }
52
53 View Code Duplication
    public function testEmptyContactId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
54
    {
55
        $content = json_encode([
56
            'email' =>'[email protected]',
57
            'primary' => true
58
        ]);
59
60
        $this->client->request('POST', $this->getUrl('oro_api_post_contact_email'), [], [], [], $content);
61
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_BAD_REQUEST);
62
    }
63
64 View Code Duplication
    public function testEmptyEmail()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
65
    {
66
        $contact = $this->getReference('Contact_Brenda');
67
        $content = json_encode([
68
            'contactId' => $contact->getId(),
69
            'primary' => true
70
        ]);
71
72
        $this->client->request('POST', $this->getUrl('oro_api_post_contact_email'), [], [], [], $content);
73
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_BAD_REQUEST);
74
    }
75
76 View Code Duplication
    public function testDeleteEmailForbidden()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
77
    {
78
        $contactEmail = $this->getReference('ContactEmail_Several_'. LoadContactEmailData::FIRST_ENTITY_NAME);
79
        $routeParams = [
80
            'id' => $contactEmail->getId()
81
        ];
82
        $this->client->request('DELETE', $this->getUrl('oro_api_delete_contact_email', $routeParams));
83
84
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_INTERNAL_SERVER_ERROR);
85
        $this->assertEquals(
86
            '{"code":500,"message":"oro.contact.email.error.delete.more_one"}',
87
            $this->client->getResponse()->getContent()
88
        );
89
    }
90
91 View Code Duplication
    public function testDeleteEmailSuccess()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
92
    {
93
        $contactEmail = $this->getReference('ContactEmail_Single_'. LoadContactEmailData::FIRST_ENTITY_NAME);
94
        $routeParams = [
95
            'id' => $contactEmail->getId()
96
        ];
97
        $this->client->request('DELETE', $this->getUrl('oro_api_delete_contact_email', $routeParams));
98
99
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_OK);
100
        $this->assertEquals('{"id":""}', $this->client->getResponse()->getContent());
101
    }
102
}
103