Completed
Push — 1.10 ( 95facb...eb5cb8 )
by
unknown
22:14
created

RestOpportunityTest::getStatusByLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace OroCRM\Bundle\SalesBundle\Tests\Functional\Controller\API;
4
5
use Oro\Bundle\EntityExtendBundle\Model\EnumValue;
6
use Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper;
7
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase;
8
9
/**
10
 * @outputBuffering enabled
11
 * @dbIsolation
12
 */
13
class RestOpportunityTest extends WebTestCase
14
{
15
    protected function setUp()
16
    {
17
        $this->initClient(
18
            [],
19
            $this->generateWsseAuthHeader()
20
        );
21
22
        $this->loadFixtures(['OroCRM\Bundle\SalesBundle\Tests\Functional\Fixture\LoadSalesBundleFixtures']);
23
    }
24
25
    /**
26
     * @return array
27
     */
28
    public function testPostOpportunity()
29
    {
30
        $request = [
31
            "opportunity" => [
32
                'name'        => 'opportunity_name_' . mt_rand(1, 500),
33
                'owner'       => '1',
34
                'customer'    => $this->getReference('default_b2bcustomer')->getId(),
35
                'contact'     => $this->getReference('default_contact')->getId(),
36
                'dataChannel' => $this->getReference('default_channel')->getId(),
37
                'status'      => 'in_progress'
38
            ]
39
        ];
40
41
        $this->client->request(
42
            'POST',
43
            $this->getUrl('oro_api_post_opportunity'),
44
            $request
45
        );
46
47
        $result = $this->getJsonResponseContent($this->client->getResponse(), 201);
0 ignored issues
show
Documentation introduced by
$this->client->getResponse() is of type object|null, but the function expects a object<Symfony\Component\HttpFoundation\Response>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
49
        $request['id'] = $result['id'];
50
51
        return $request;
52
    }
53
54
    /**
55
     * @param $request
56
     *
57
     * @depends testPostOpportunity
58
     * @return  mixed
59
     */
60
    public function testGetOpportunity($request)
61
    {
62
        $this->client->request(
63
            'GET',
64
            $this->getUrl('oro_api_get_opportunity', ['id' => $request['id']])
65
        );
66
67
        $result = $this->getJsonResponseContent($this->client->getResponse(), 200);
0 ignored issues
show
Documentation introduced by
$this->client->getResponse() is of type object|null, but the function expects a object<Symfony\Component\HttpFoundation\Response>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
69
        $this->assertEquals($request['id'], $result['id']);
70
        $this->assertEquals($request['opportunity']['name'], $result['name']);
71
        // Because api return name of status, that can be different, assert id
72
        $this->assertEquals('in_progress', $this->getStatusByLabel($result['status'])->getId());
73
        // TODO: incomplete CRM-816
74
        //$this->assertEquals($request['opportunity']['owner'], $result['owner']['id']);
75
        return $request;
76
    }
77
78
    /**
79
     * @param $request
80
     *
81
     * @depends testGetOpportunity
82
     * @return  mixed
83
     */
84
    public function testPutOpportunity($request)
85
    {
86
        $request['opportunity']['name'] .= '_updated';
87
88
        $this->client->request(
89
            'PUT',
90
            $this->getUrl('oro_api_put_opportunity', ['id' => $request['id']]),
91
            $request
92
        );
93
94
        $result = $this->client->getResponse();
95
        $this->assertEmptyResponseStatusCodeEquals($result, 204);
96
97
        $this->client->request(
98
            'GET',
99
            $this->getUrl('oro_api_get_opportunity', ['id' => $request['id']])
100
        );
101
102
        $result = $this->getJsonResponseContent($this->client->getResponse(), 200);
0 ignored issues
show
Documentation introduced by
$this->client->getResponse() is of type object|null, but the function expects a object<Symfony\Component\HttpFoundation\Response>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
103
104
        $this->assertEquals($request['id'], $result['id']);
105
        $this->assertEquals($request['opportunity']['name'], $result['name']);
106
        // Because api return name of status, that can be different, assert id
107
        $this->assertEquals('in_progress', $this->getStatusByLabel($result['status'])->getId());
108
109
        return $request;
110
    }
111
112
    /**
113
     * @depends testPutOpportunity
114
     */
115
    public function testGetOpportunities($request)
116
    {
117
        $baseUrl = $this->getUrl('oro_api_get_opportunities');
118
        $this->client->request('GET', $baseUrl);
119
120
        $result = $this->getJsonResponseContent($this->client->getResponse(), 200);
0 ignored issues
show
Documentation introduced by
$this->client->getResponse() is of type object|null, but the function expects a object<Symfony\Component\HttpFoundation\Response>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
121
122
        $this->assertNotEmpty($result);
123
124
        $result = end($result);
125
        $this->assertEquals($request['id'], $result['id']);
126
        $this->assertEquals($request['opportunity']['name'], $result['name']);
127
        // Because api return name of status, that can be different, assert id
128
        $this->assertEquals('in_progress', $this->getStatusByLabel($result['status'])->getId());
129
130
        $this->client->request('GET', $baseUrl . '?contactId=' . $request['opportunity']['contact']);
131
        $this->assertCount(1, $this->getJsonResponseContent($this->client->getResponse(), 200));
0 ignored issues
show
Documentation introduced by
$this->client->getResponse() is of type object|null, but the function expects a object<Symfony\Component\HttpFoundation\Response>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
132
133
        $this->client->request('GET', $baseUrl . '?contactId<>' . $request['opportunity']['contact']);
134
        $this->assertEmpty($this->getJsonResponseContent($this->client->getResponse(), 200));
0 ignored issues
show
Documentation introduced by
$this->client->getResponse() is of type object|null, but the function expects a object<Symfony\Component\HttpFoundation\Response>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
135
    }
136
137
    /**
138
     * @depends testPutOpportunity
139
     */
140
    public function testDeleteOpportunity($request)
141
    {
142
        $this->client->request(
143
            'DELETE',
144
            $this->getUrl('oro_api_delete_opportunity', ['id' => $request['id']])
145
        );
146
        $result = $this->client->getResponse();
147
        $this->assertEmptyResponseStatusCodeEquals($result, 204);
148
149
        $this->client->request(
150
            'GET',
151
            $this->getUrl('oro_api_get_opportunity', ['id' => $request['id']])
152
        );
153
154
        $result = $this->client->getResponse();
155
        $this->assertJsonResponseStatusCodeEquals($result, 404);
156
    }
157
158
    /**
159
     * @param $result
160
     * @return EnumValue
161
     */
162
    protected function getStatusByLabel($statusLabel)
163
    {
164
        return $this->getContainer()
165
            ->get('doctrine')
166
            ->getManager()
167
            ->getRepository(ExtendHelper::buildEnumValueClassName('opportunity_status'))
168
            ->findOneByName($statusLabel);
169
    }
170
}
171