Issues (15)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Tests/OrderServiceTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
 * This file is part of the MailChimpEcommerceBundle package.
4
 *
5
 * Copyright (c) 2017 kevin92dev.es
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * Feel free to edit as you please, and have fun.
11
 *
12
 * @author Kevin Murillo <[email protected]>
13
 */
14
15
namespace Kevin92dev\MailChimpEcommerceBundle\Tests;
16
17
use Kevin92dev\MailChimpEcommerceBundle\RequestTypes;
18
use Kevin92dev\MailChimpEcommerceBundle\Services\OrderService;
19
use PHPUnit_Framework_TestCase;
20
21
class OrderServiceTest extends PHPUnit_Framework_TestCase
22
{
23
    private $mailChimpStub;
24
    private $mcOrder;
25
    private $mcOrderLine;
26
    private $mcProduct;
27
    private $mcProductVariant;
28
    private $mcCustomer;
29
    private $mcAddress;
30
31
    public function setUp()
32
    {
33
        parent::setUp(); // TODO: Change the autogenerated stub
34
35
        $this->mailChimpStub = $this
36
            ->getMockBuilder('\Kevin92dev\MailChimpEcommerceBundle\Services\MailChimp')
37
            ->disableOriginalConstructor()
38
            ->getMock();
39
        $this->mcOrder = $this
40
            ->getMockBuilder('\Kevin92dev\MailChimpEcommerceBundle\Entities\Order')
41
            ->getMock();
42
        $this->mcOrderLine = $this
43
            ->getMockBuilder('\Kevin92dev\MailChimpEcommerceBundle\Entities\OrderLine')
44
            ->getMock();
45
        $this->mcProduct = $this
46
            ->getMockBuilder('\Kevin92dev\MailChimpEcommerceBundle\Entities\Product')
47
            ->getMock();
48
        $this->mcProductVariant = $this
49
            ->getMockBuilder('\Kevin92dev\MailChimpEcommerceBundle\Entities\ProductVariant')
50
            ->getMock();
51
        $this->mcCustomer = $this
52
            ->getMockBuilder('\Kevin92dev\MailChimpEcommerceBundle\Entities\Customer')
53
            ->getMock();
54
        $this->mcAddress = $this
55
            ->getMockBuilder('\Kevin92dev\MailChimpEcommerceBundle\Entities\Address')
56
            ->getMock();
57
    }
58
59
    public function testSendOrderToMailChimpSuccess()
60
    {
61
        $method = RequestTypes::$POST;
62
        $resource = '/orders';
63
        $body = [
64
            'landing_site' => "landing_site",
65
            'financial_status' => "processing",
66
            'fulfillment_status' => "",
67
            'currency_code' => "EUR",
68
            'order_total' => 21,
69
            'tax_total' => 4.48,
70
            'shipping_total' => 0,
71
            'tracking_code' => "prec",
72
            'processed_at_foreign' => "",
73
            'cancelled_at_foreign' => "",
74
            'updated_at_foreign' => "",
75
            'id' => "1234",
76
            'campaign_id' => "",
77
            'customer' => [
78
                'id' => "50",
79
                'email_address' => "[email protected]",
80
                'opt_in_status' => true,
81
                'company' => "",
82
                'first_name' => "Kevin",
83
                'last_name' => "Murillo",
84
                'orders_count' => 5,
85
                'total_spent' => 50.75,
86
                'address' => [
87
                    'address1' => "Av. Test nÂș 92",
88
                    'address2' => "",
89
                    'city' => "Barcelona",
90
                    'province' => "Barcelona",
91
                    'province_code' => "BCN",
92
                    'postal_code' => "08080",
93
                    'country' => "Spain",
94
                    'country_code' => "ESP",
95
                ]
96
            ],
97
            'shipping_address' => [
98
                'name' => "shipping_address address for [email protected]",
99
                'address1' => "Av. Test nÂș 92",
100
                'address2' => "",
101
                'city' => "Barcelona",
102
                'province' => "Barcelona",
103
                'province_code' => "BCN",
104
                'postal_code' => "08080",
105
                'country' => "Spain",
106
                'country_code' => "ESP",
107
            ],
108
            'billing_address' => [
109
                'name' => "billing_address address for [email protected]",
110
                'address1' => "Av. Test nÂș 92",
111
                'address2' => "",
112
                'city' => "Barcelona",
113
                'province' => "Barcelona",
114
                'province_code' => "BCN",
115
                'postal_code' => "08080",
116
                'country' => "Spain",
117
                'country_code' => "ESP",
118
            ]
119
        ];
120
121
        // Create mocks
122
        $this->setCustomerMock();
123
        $this->setAddressMock();
124
        $this->setOrderMock($this->mcCustomer, $this->mcAddress);
125
126
        // Check that doRequest call have the right params
127
        $this->mailChimpStub
128
            ->expects($this->once())
129
            ->method('doRequest')
130
            ->with(
131
                $method,
132
                $body,
133
                $resource
134
            );
135
136
        // Call method to test
137
        $orderService = new OrderService($this->mailChimpStub);
138
        $orderService->create($this->mcOrder);
139
    }
140
141
    private function setOrderMock($customerMock, $addressMock)
142
    {
143
        $this->setOrderLineMock();
144
145
        $array = [
146
            'getId' => 1234,
147
            'getCampaignId' => '',
148
            'getLandingSite' => 'landing_site',
149
            'getFinancialStatus' => 'processing',
150
            'getFulfillmentStatus' => '',
151
            'getCurrencyCode' => 'EUR',
152
            'getOrderTotal' => 21,
153
            'getTaxTotal' => '4.48',
154
            'getShippingTotal' => '0',
155
            'getTrackingCode' => 'prec',
156
            'getProcessedAtForeign' => '',
157
            'getCancelledAtForeign' => '',
158
            'getUpdatedAtForeign' => '',
159
            'getCustomer' => $customerMock,
160
            'getShippingAddress' => $addressMock,
161
            'getBillingAddress' => $addressMock,
162
            'getOrderLines' => $this->mcOrderLine,
163
        ];
164
165
        foreach ($array as $method => $value) {
166
            $this->mcOrder
167
                ->expects($this->any())
168
                ->method($method)
169
                ->will($this->returnValue($value));
170
        }
171
    }
172
173
    private function setOrderLineMock()
174
    {
175
        $this->setProductMock();
176
        $this->setProductVariantMock();
177
178
        $array = [
179
            'getId' => 1234,
180
            'getProduct' => $this->mcProduct,
181
            'getProductVariant' => $this->mcProductVariant,
182
            'getQuantity' => 2,
183
            'getPrice' => 10.50,
184
        ];
185
186
        foreach ($array as $method => $value) {
187
            $this->mcOrderLine
188
                ->expects($this->any())
189
                ->method($method)
190
                ->will($this->returnValue($value));
191
        }
192
    }
193
194 View Code Duplication
    private function setProductMock()
0 ignored issues
show
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...
195
    {
196
        $array = [
197
            'getId' => 567
198
        ];
199
200
        foreach ($array as $method => $value) {
201
            $this->mcProduct
202
                ->expects($this->any())
203
                ->method($method)
204
                ->will($this->returnValue($value));
205
        }
206
    }
207
208 View Code Duplication
    private function setProductVariantMock()
0 ignored issues
show
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...
209
    {
210
        $array = [
211
            'getId' => 567,
212
        ];
213
214
        foreach ($array as $method => $value) {
215
            $this->mcProductVariant
216
                ->expects($this->any())
217
                ->method($method)
218
                ->will($this->returnValue($value));
219
        }
220
    }
221
222
    private function setCustomerMock()
223
    {
224
        $array = [
225
            'getId' => 50,
226
            'getEmail' => '[email protected]',
227
            'isOptInStatus' => true,
228
            'getCompany' => '',
229
            'getFirstname' => 'Kevin',
230
            'getLastname' => 'Murillo',
231
            'getOrdersCount' => 5,
232
            'getTotalSpent' => 50.75,
233
            'getAddress' => $this->mcAddress,
234
        ];
235
236
        foreach ($array as $method => $value) {
237
            $this->mcCustomer
238
                ->expects($this->any())
239
                ->method($method)
240
                ->will($this->returnValue($value));
241
        }
242
    }
243
244
    private function setAddressMock()
245
    {
246
        $array = [
247
            'getAddress1' => 'Av. Test nÂș 92',
248
            'getAddress2' => '',
249
            'getCity' => 'Barcelona',
250
            'getProvince' => 'Barcelona',
251
            'getProvinceCode' => 'BCN',
252
            'getPostalCode' => '08080',
253
            'getCountry' => 'Spain',
254
            'getCountryCode' => 'ESP',
255
        ];
256
257
        foreach ($array as $method => $value) {
258
            $this->mcAddress
259
                ->expects($this->any())
260
                ->method($method)
261
                ->will($this->returnValue($value));
262
        }
263
    }
264
}
265