Test Failed
Push — 135-map-multiple-wordpress-obj... ( 3634c2...bb35fb )
by Jonathan
12:00
created

SforcePartnerClientTest   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 486
Duplicated Lines 17.08 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
dl 83
loc 486
rs 6
c 0
b 0
f 0
wmc 55
lcom 1
cbo 9

25 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteAll() 0 25 5
A setUp() 0 39 4
A testLogin() 0 10 2
A testServerTimestamp() 10 10 2
A testUserInfo() 11 11 2
A testDescribeSObject() 11 11 2
A testDescribeSObjects() 0 13 2
A testDescribeGlobal() 10 10 2
A testDescribeLayout() 10 10 2
A testDescribeTabs() 10 10 2
A testCreate() 0 3 1
A testRetrieve() 0 18 2
A testUpdate() 0 20 2
A testGetUpdated() 0 15 2
A testDelete() 0 12 2
A testGetDeleted() 0 17 3
A testQuery() 0 12 2
A testUpsert() 0 30 2
A testAssignmentRuleHeaderId() 21 21 2
A testAssignmentRuleHeaderFlag() 0 23 2
A testMruHeader() 0 20 2
A testSearch() 0 10 2
A testSendSingleEmail() 0 23 2
A testSendMassEmail() 0 17 2
A testEmptyRecycleBin() 0 25 2

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like SforcePartnerClientTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use SforcePartnerClientTest, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style introduced by
File has mixed line endings; this may cause incorrect results
Loading history...
Coding Style introduced by
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
2
require_once ('PHPUnit/Framework/TestCase.php');
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
3
require_once ('../soapclient/SforcePartnerClient.php');
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
4
require_once ('../soapclient/SforceHeaderOptions.php');
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
5
6
/*
7
 * Copyright (c) 2007, salesforce.com, inc.
8
 * All rights reserved.
9
 *
10
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided
11
 * that the following conditions are met:
12
 *
13
 *    Redistributions of source code must retain the above copyright notice, this list of conditions and the
14
 *    following disclaimer.
15
 *
16
 *    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
17
 *    the following disclaimer in the documentation and/or other materials provided with the distribution.
18
 *
19
 *    Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or
20
 *    promote products derived from this software without specific prior written permission.
21
 *
22
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
 * POSSIBILITY OF SUCH DAMAGE.
30
 */
31
32
/**
33
 * This file contains one class.
34
 * @package SalesforceTest
35
 */
36
/**
37
 * SforcePartnerClientTest class.
38
 *
39
 * @package SalesforceTest
40
 */
41
class SforcePartnerClientTest extends PHPUnit_Framework_TestCase {
42
  private $wsdl = '../soapclient/partner.wsdl.xml';
43
  private $username = '[email protected]';
44
  private $password = 'changeme';
45
  protected $mySforceConnection = null;
46
  protected $mylogin = null;
47
  protected $theId = null;
48
49
  public function deleteAll($queryResult) {
0 ignored issues
show
Coding Style introduced by
The function name deleteAll is in camel caps, but expected delete_all instead as per the coding standard.
Loading history...
50
    $records = $queryResult->records;
51
    $ids = array ();
0 ignored issues
show
Unused Code introduced by
$ids is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
52
    $buckets = array_chunk($records, 200);
53
    foreach ($buckets as $bucket) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
54
      $ids = array ();
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
55
      foreach ($bucket as $record) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
56
        $sObject = new SObject($record);
57
        //var_dump($sObject);
58
        $ids[] = $sObject->Id;
59
      }
60
      try {
61
        global $mySforceConnection;
62
        $this->mySforceConnection->delete($ids);
63
      } catch (Exception $e) {
64
        print_r($e->faultstring);
0 ignored issues
show
introduced by
The use of function print_r() is discouraged
Loading history...
65
      }
66
    }
67
68
    $queryLocator = $queryResult->queryLocator;
69
    if (isset($queryLocator)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
70
      $result = $this->mySforceConnection->queryMore($queryLocator);
71
      $this->deleteAll($result);
72
    }
73
  }
74
75
  protected function setUp() {
0 ignored issues
show
Coding Style introduced by
The function name setUp is in camel caps, but expected set_up instead as per the coding standard.
Loading history...
76
    echo "Begin Test Setup\r\n";
77
    try {
78
      // Create the fixtures.
79
      $this->mySforceConnection = new SforcePartnerClient();
80
      $this->mySforceConnection->createConnection($this->wsdl);
81
      $this->mylogin = $this->mySforceConnection->login($this->username, $this->password);
82
83
      // CLEAN
84
      $queryOptions = new QueryOptions(300);
85
      $createQuery = 'SELECT Id from Contact where FirstName = \'DELETE_ME\'';
86
      $leadQuery = 'SELECT Id from Lead where FirstName = \'DELETE_ME\'';
87
      $createQueryResult = $this->mySforceConnection->query($createQuery, $queryOptions);
0 ignored issues
show
Unused Code introduced by
The call to SforcePartnerClient::query() has too many arguments starting with $queryOptions.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
88
      $leadQueryResult = $this->mySforceConnection->query($leadQuery, $queryOptions);
0 ignored issues
show
Unused Code introduced by
The call to SforcePartnerClient::query() has too many arguments starting with $queryOptions.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
89
      if ($createQueryResult->size > 0) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
90
        echo 'Deleting '.$createQueryResult->size." contacts.\r\n";
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$createQueryResult'
Loading history...
91
        $this->deleteAll($createQueryResult);
92
      }
93
      if ($leadQueryResult->size > 0) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
94
        $this->deleteAll($leadQueryResult);
95
      }
96
      $createFields = array (
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
97
        'FirstName' => 'DELETE_ME',
98
        'LastName' => 'DELETE_ME',
99
        'MailingCity' => 'San Diego',
100
        'MailingState' => 'CA'
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
101
        );
102
        $sObject1 = new SObject();
103
        $sObject1->fields = $createFields;
104
        $sObject1->type = 'Contact';
105
        $createResponse = $this->mySforceConnection->create(array($sObject1));
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
106
        $this->assertNotNull($createResponse);
107
        $this->assertTrue($createResponse->success);
108
    } catch (SoapFault $fault) {
109
      $this->fail($fault->faultstring);
110
    }
111
    $this->theId = $createResponse->id;
112
    echo "Test setup complete.\r\n";
113
  }
114
115
  public function testLogin() {
0 ignored issues
show
Coding Style introduced by
The function name testLogin is in camel caps, but expected test_login instead as per the coding standard.
Loading history...
116
    echo "testLogin\r\n";
117
    try {
118
      $mylogin = $this->mylogin;
119
      $this->assertNotNull($mylogin);
120
      $this->assertNotNull($mylogin->userInfo);
121
    } catch (SoapFault $fault) {
122
      $this->fail($fault->faultstring);
123
    }
124
  }
125
126 View Code Duplication
  public function testServerTimestamp() {
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...
Coding Style introduced by
The function name testServerTimestamp is in camel caps, but expected test_server_timestamp instead as per the coding standard.
Loading history...
127
    echo "testServerTimestamp\r\n";
128
    try {
129
      $timeStamp = $this->mySforceConnection->getServerTimestamp();
130
      $this->assertNotNull($timeStamp);
131
      $this->assertNotNull($timeStamp->timestamp);
132
    } catch (SoapFault $fault) {
133
      $this->fail($fault->faultstring);
134
    }
135
  }
136
137 View Code Duplication
  public function testUserInfo() {
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...
Coding Style introduced by
The function name testUserInfo is in camel caps, but expected test_user_info instead as per the coding standard.
Loading history...
138
    echo "testUserInfo\r\n";
139
    try {
140
      $userInfo = $this->mySforceConnection->getUserInfo();
141
      $this->assertNotNull($userInfo);
142
      $this->assertNotNull($userInfo->userId);
143
      $this->assertNotNull($userInfo->userFullName);
144
    } catch (SoapFault $fault) {
145
      $this->fail($fault->faultstring);
146
    }
147
  }
148
149 View Code Duplication
  public function testDescribeSObject() {
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...
Coding Style introduced by
The function name testDescribeSObject is in camel caps, but expected test_describe_s_object instead as per the coding standard.
Loading history...
150
    echo "testDescribeSObject\r\n";
151
    try {
152
      $response = $this->mySforceConnection->describeSObject('Contact');
153
      $this->assertNotNull($response);
154
      $this->assertEquals('Contact', $response->name);
155
    } catch (SoapFault $fault) {
156
      echo $fault;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$fault'
Loading history...
157
      $this->fail($fault->faultstring);
158
    }
159
  }
160
161
  public function testDescribeSObjects() {
0 ignored issues
show
Coding Style introduced by
The function name testDescribeSObjects is in camel caps, but expected test_describe_s_objects instead as per the coding standard.
Loading history...
162
    echo "testDescribeSObjects\r\n";
163
    try {
164
      $response = $this->mySforceConnection->describeSObjects(array (
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
165
        'Account',
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 10 spaces, but found 8.
Loading history...
166
        'Contact'
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 10 spaces, but found 8.
Loading history...
introduced by
Comma required after last value in array declaration
Loading history...
167
        ));
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 6 spaces, but found 8.
Loading history...
168
        $this->assertNotNull($response);
169
        $this->assertEquals(2, sizeof($response));
170
    } catch (SoapFault $fault) {
171
      $this->fail($fault->faultstring);
172
    }
173
  }
174
175 View Code Duplication
  public function testDescribeGlobal() {
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...
Coding Style introduced by
The function name testDescribeGlobal is in camel caps, but expected test_describe_global instead as per the coding standard.
Loading history...
176
    echo "testDescribeGlobal\r\n";
177
    try {
178
      $response = $this->mySforceConnection->describeGlobal();
179
      $this->assertNotNull($response);
180
      $this->assertNotNull($response->types);
181
    } catch (SoapFault $fault) {
182
      $this->fail($fault->faultstring);
183
    }
184
  }
185
186 View Code Duplication
  public function testDescribeLayout() {
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...
Coding Style introduced by
The function name testDescribeLayout is in camel caps, but expected test_describe_layout instead as per the coding standard.
Loading history...
187
    echo "testDescribeLayout\r\n";
188
    try {
189
      $response = $this->mySforceConnection->describeLayout('Contact');
190
      $this->assertNotNull($response);
191
      $this->assertNotNull($response->recordTypeMappings);
192
    } catch (SoapFault $fault) {
193
      $this->fail($fault->faultstring);
194
    }
195
  }
196
197 View Code Duplication
  public function testDescribeTabs() {
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...
Coding Style introduced by
The function name testDescribeTabs is in camel caps, but expected test_describe_tabs instead as per the coding standard.
Loading history...
198
    echo "testDescribeTabs\r\n";
199
    try {
200
      $response = $this->mySforceConnection->describeTabs();
201
      $this->assertNotNull($response);
202
      $this->assertTrue(sizeof($response) > 0);
203
    } catch (SoapFault $fault) {
204
      $this->fail($fault->faultstring);
205
    }
206
  }
207
208
  public function testCreate() {
0 ignored issues
show
Coding Style introduced by
The function name testCreate is in camel caps, but expected test_create instead as per the coding standard.
Loading history...
209
    // now done in setUp so that theId can be accessed by other tests.
210
  }
211
212
  public function testRetrieve() {
0 ignored issues
show
Coding Style introduced by
The function name testRetrieve is in camel caps, but expected test_retrieve instead as per the coding standard.
Loading history...
213
    echo "testRetrieve\r\n";
214
    try {
215
      $ids = array ($this->theId);
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
216
      $this->assertEquals(1, count($ids));
217
218
      $retrieveFields = 'LastName';
219
      $retrieveResponse = $this->mySforceConnection->retrieve($retrieveFields, 'Contact', $ids);
220
      $sObject = new SObject($retrieveResponse);
221
      $this->assertEquals($this->theId, $sObject->Id);
222
      // Fields on SObjects are SimpleXMLElements.
223
      //$this->assertEquals('DELETE_ME', $sObject->fields->LastName);
224
      //$this->assertEquals('San Diego', $sObject->MailingCity);
225
      //$this->assertEquals('CA', $sObject->MailingState);
226
    } catch (SoapFault $fault) {
227
      $this->fail($fault->faultstring);
228
    }
229
  }
230
231
  public function testUpdate() {
0 ignored issues
show
Coding Style introduced by
The function name testUpdate is in camel caps, but expected test_update instead as per the coding standard.
Loading history...
232
    echo "testUpdate\r\n";
233
    try {
234
      $id = $this->theId;
235
      $this->assertNotNull($id);
236
      $updateFields = array (
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
237
        'Id' => $id,
238
        'MailingCity' => 'New York',
239
        'MailingState' => 'NY'
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
240
        );
241
        $sObject1 = new SObject();
242
        $sObject1->fields = $updateFields;
243
        $sObject1->type = 'Contact';
244
        $updateResponse = $this->mySforceConnection->update(array ($sObject1));
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
245
        $this->assertNotNull($updateResponse);
246
        $this->assertTrue($updateResponse->success);
247
    } catch (SoapFault $fault) {
248
      $this->fail($fault->faultstring);
249
    }
250
  }
251
252
  public function testGetUpdated() {
0 ignored issues
show
Coding Style introduced by
The function name testGetUpdated is in camel caps, but expected test_get_updated instead as per the coding standard.
Loading history...
253
    echo "testGetUpdated\r\n";
254
    try {
255
      $type = 'Contact';
256
      $currentTime = mktime();
257
      // assume that create or update occured within the last 5 mins.
258
      $startTime = $currentTime-(60*5);
0 ignored issues
show
introduced by
Expected 1 space before "-"; 0 found
Loading history...
introduced by
Expected 1 space before "*"; 0 found
Loading history...
introduced by
Expected 1 space after "*"; 0 found
Loading history...
259
      $endTime = $currentTime;
260
      $response = $this->mySforceConnection->getUpdated($type, $startTime, $endTime);
0 ignored issues
show
Documentation introduced by
$startTime is of type integer, but the function expects a object<date>.

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...
Documentation introduced by
$endTime is of type integer, but the function expects a object<date>.

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...
261
      $this->assertNotNull($response);
262
263
    } catch (SoapFault $fault) {
264
      $this->fail($fault->faultstring);
265
    }
266
  }
267
268
  public function testDelete() {
0 ignored issues
show
Coding Style introduced by
The function name testDelete is in camel caps, but expected test_delete instead as per the coding standard.
Loading history...
269
    echo "testDelete\r\n";
270
    try {
271
      $ids = array ($this->theId);
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
272
      $this->assertEquals(1, count($ids));
273
      $response = $this->mySforceConnection->delete($ids);
274
      $this->assertNotNull($response);
275
      $this->assertTrue($response->success);
276
    } catch (SoapFault $fault) {
277
      $this->fail($fault->faultstring);
278
    }
279
  }
280
281
  public function testGetDeleted() {
0 ignored issues
show
Coding Style introduced by
The function name testGetDeleted is in camel caps, but expected test_get_deleted instead as per the coding standard.
Loading history...
282
    echo "testGetDeleted\r\n";
283
    try {
284
      $type = 'Contact';
285
      $currentTime = mktime();
286
      // assume that delete occured within the last 5 mins.
287
      $startTime = $currentTime-(60*10);
0 ignored issues
show
introduced by
Expected 1 space before "-"; 0 found
Loading history...
introduced by
Expected 1 space before "*"; 0 found
Loading history...
introduced by
Expected 1 space after "*"; 0 found
Loading history...
288
      $endTime = $currentTime;
289
      $response = $this->mySforceConnection->getDeleted($type, $startTime, $endTime);
0 ignored issues
show
Documentation introduced by
$startTime is of type integer, but the function expects a object<date>.

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...
Documentation introduced by
$endTime is of type integer, but the function expects a object<date>.

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...
290
      if (isset($response)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
291
        $this->assertNotNull(count($response->deletedRecords));
292
        echo'deleted records = '.count($response->deletedRecords)."\r\n";
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'count'
Loading history...
293
      }
294
    } catch (SoapFault $fault) {
295
      $this->fail($fault->faultstring);
296
    }
297
  }
298
299
  public function testQuery() {
0 ignored issues
show
Coding Style introduced by
The function name testQuery is in camel caps, but expected test_query instead as per the coding standard.
Loading history...
300
    echo "testQuery\r\n";
301
    $query = 'SELECT Id,Name,BillingCity,BillingState,Phone,Fax from Account';
302
    $queryOptions = new QueryOptions(200);
303
    try {
304
      $response = $this->mySforceConnection->query($query, $queryOptions);
0 ignored issues
show
Unused Code introduced by
The call to SforcePartnerClient::query() has too many arguments starting with $queryOptions.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
305
      $this->assertNotNull($response);
306
      $this->assertTrue(sizeof($response) > 0);
307
    } catch (SoapFault $fault) {
308
      $this->fail($fault->faultstring);
309
    }
310
  }
311
  /*
312
   public function testQueryMore() {
313
   echo "testQueryMore\r\n";
314
   $createFields = array (
315
   'FirstName' => 'DELETE_ME',
316
   'LastName' => 'DELETE_ME',
317
   'MailingCity' => 'San Diego',
318
   'MailingState' => 'CA'
319
   );
320
321
   $sObject1 = new SObject();
322
   $sObject1->fields = $createFields;
323
   $sObject1->type = 'Contact';
324
325
   $createNum = 500;
326
   try {
327
   for ($counter = 0; $counter < $createNum; $counter++) {
328
   $createResponse = $this->mySforceConnection->create(array ($sObject1));
329
   $this->assertTrue($createResponse->success);
330
   }
331
332
   $query = 'SELECT Id from Contact where FirstName = \'DELETE_ME\'';
333
   $queryOptions = new QueryOptions(300);
334
335
   $queryResponse = $this->mySforceConnection->query($query, $queryOptions);
336
   $this->assertEquals($createNum+1, $queryResponse->size);
337
   if ($queryResponse->size) {
338
   $this->deleteAll($queryResponse);
339
   }
340
   $queryResponse = $this->mySforceConnection->query($query, $queryOptions);
341
   $this->assertEquals(0, $queryResponse->size);
342
   } catch (SoapFault $fault) {
343
   $this->fail($fault->faultstring);
344
   }
345
   }
346
   */
347
348
  public function testUpsert() {
0 ignored issues
show
Coding Style introduced by
The function name testUpsert is in camel caps, but expected test_upsert instead as per the coding standard.
Loading history...
349
    // Make the language field an external id field on the contact
350
    // table before proceeding.
351
    echo "testUpsert\r\n";
352
    $createFields = array (
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
353
      'FirstName' => 'DELETE_ME',
354
      'LastName' => 'DELETE_ME',
355
      'MailingCity' => 'TEST_UPSERT',
356
      'MailingState' => 'CA',
357
      'Languages__c' => 'TEST_UPSERT_ID'
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
358
      );
359
      $external_id = 'Languages__c';
360
      try {
361
        $sObject1 = new SObject();
362
        $sObject1->fields = $createFields;
363
        $sObject1->type = 'Contact';
364
        $upsertResponse = $this->mySforceConnection->upsert($external_id, array($sObject1));
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
365
        $this->assertNotNull($upsertResponse);
366
        $this->assertTrue($upsertResponse->success);
367
        $id = $upsertResponse->id;
368
        $ids = array ($id);
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
369
        $retrieveFields = 'Id, FirstName, LastName, MailingCity, MailingState';
370
        $retrieveResponse = $this->mySforceConnection->retrieve($retrieveFields, 'Contact', $ids);
371
        $this->assertNotNull($retrieveResponse);
372
        $sObject = new SObject($retrieveResponse);
373
        $this->assertEquals($id, $sObject->Id);
374
      } catch (SoapFault $fault) {
375
        $this->fail($fault->faultstring);
376
      }
377
  }
378
379 View Code Duplication
  public function testAssignmentRuleHeaderId() {
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...
Coding Style introduced by
The function name testAssignmentRuleHeaderId is in camel caps, but expected test_assignment_rule_header_id instead as per the coding standard.
Loading history...
380
    echo "testAssignmentRuleHeaderId\r\n";
381
    $header = new AssignmentRuleHeader('01Q300000005lDgEAI', NULL);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
382
    $createFields = array (
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
383
      'FirstName' => 'DELETE_ME',
384
      'LastName' => 'DELETE_ME',
385
      'Email' => '[email protected]',
386
      'Company' => 'DELETE_ME Company',
387
      'LeadSource' => 'PHPUnit2',
388
      'City' => 'San Diego',
389
      'State' => 'CA'
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
390
      );
391
      $sObject1 = new SObject();
392
      $sObject1->fields = $createFields;
393
      $sObject1->type = 'Lead';
394
      try {
395
        $createResponse = $this->mySforceConnection->create(array ($sObject1), $header, NULL);
0 ignored issues
show
Unused Code introduced by
The call to SforcePartnerClient::create() has too many arguments starting with $header.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
$createResponse is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
396
      } catch (SoapFault $fault) {
397
        $this->fail($fault->faultstring);
398
      }
399
  }
400
401
  public function testAssignmentRuleHeaderFlag() {
0 ignored issues
show
Coding Style introduced by
The function name testAssignmentRuleHeaderFlag is in camel caps, but expected test_assignment_rule_header_flag instead as per the coding standard.
Loading history...
402
    echo "testAssignmentRuleHeaderFlag\r\n";
403
    $header = new AssignmentRuleHeader(NULL, TRUE);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected true, but found TRUE.
Loading history...
404
    $createFields = array (
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
405
      'FirstName' => 'DELETE_ME',
406
      'LastName' => 'DELETE_ME',
407
      'Email' => '[email protected]',
408
      'Company' => 'DELETE_ME Company',
409
      'LeadSource' => 'PHPUnit2',
410
      'City' => 'San Diego',
411
      'State' => 'CA'
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
412
      );
413
      $sObject1 = new SObject();
414
      $sObject1->fields = $createFields;
415
      $sObject1->type = 'Lead';
416
      try {
417
        $createResponse = $this->mySforceConnection->create(array ($sObject1), $header, NULL);
0 ignored issues
show
Unused Code introduced by
The call to SforcePartnerClient::create() has too many arguments starting with $header.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
418
        $this->assertNotNull($createResponse);
419
        $this->assertTrue($createResponse->success);
420
      } catch (SoapFault $fault) {
421
        $this->fail($fault->faultstring);
422
      }
423
  }
424
425
  public function testMruHeader() {
0 ignored issues
show
Coding Style introduced by
The function name testMruHeader is in camel caps, but expected test_mru_header instead as per the coding standard.
Loading history...
426
    echo "testMruHeader\r\n";
427
    $header = new MruHeader(TRUE);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected true, but found TRUE.
Loading history...
428
    $createFields = array (
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
429
      'FirstName' => 'DELETE_ME',
430
      'LastName' => 'DELETE_ME',
431
      'MailingCity' => 'San Diego',
432
      'MailingState' => 'CA'
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
433
      );
434
      $sObject1 = new SObject();
435
      $sObject1->fields = $createFields;
436
      $sObject1->type = 'Contact';
437
      try {
438
        $createResponse = $this->mySforceConnection->create(array ($sObject1), NULL, $header);
0 ignored issues
show
Unused Code introduced by
The call to SforcePartnerClient::create() has too many arguments starting with NULL.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
439
        $this->assertNotNull($createResponse);
440
        $this->assertTrue($createResponse->success);
441
      } catch (SoapFault $fault) {
442
        $this->fail($fault->faultstring);
443
      }
444
  }
445
446
  public function testSearch() {
0 ignored issues
show
Coding Style introduced by
The function name testSearch is in camel caps, but expected test_search instead as per the coding standard.
Loading history...
447
    echo "testSearch\r\n";
448
    try {
449
      $searchResponse
450
      = $this->mySforceConnection->search('FIND {DELETE_ME} returning contact(id, phone, firstname, lastname)');
451
      $this->assertNotNull($searchResponse);
452
    } catch (SoapFault $fault) {
453
      $this->fail($fault->faultstring);
454
    }
455
  }
0 ignored issues
show
Coding Style introduced by
The function name testSendSingleEmail is in camel caps, but expected test_send_single_email instead as per the coding standard.
Loading history...
Coding Style Comprehensibility introduced by
The string literal [email protected] does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal Hello there does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal First Single Email does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal Second Single Email does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
Coding Style introduced by
The function name testSendMassEmail is in camel caps, but expected test_send_mass_email instead as per the coding standard.
Loading history...
Coding Style Comprehensibility introduced by
The string literal Nicks Mass Email Message does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal 00X50000000wX9q does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal 0035000000PiCMd does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style introduced by
The function name testEmptyRecycleBin is in camel caps, but expected test_empty_recycle_bin instead as per the coding standard.
Loading history...
456
457
  public function testSendSingleEmail() {
458
    echo "testSendSingleEmail\r\n";
459
    try {
460
      $singleEmail1 = new SingleEmailMessage();
461
      $singleEmail1->toAddresses = "[email protected]";
462
      $singleEmail1->plainTextBody = "Hello there";
463
      $singleEmail1->subject = "First Single Email";
464
      $singleEmail1->saveAsActivity = true;
465
      $singleEmail1->emailPriority = EMAIL_PRIORITY_LOW;
466
467
      $singleEmail2 = new SingleEmailMessage();
468
      $singleEmail2->toAddresses = "[email protected]";
469
      $singleEmail2->plainTextBody = "Hello there";
470
      $singleEmail2->subject = "Second Single Email";
471
      $singleEmail2->saveAsActivity = true;
472
      $singleEmail2->emailPriority = EMAIL_PRIORITY_LOW;
473
474
      $emailResponse = $this->mySforceConnection->sendSingleEmail(array ($singleEmail1, $singleEmail2));
475
      $this->assertNotNull($emailResponse);
476
    } catch (SoapFault $fault) {
477
      $this->fail($fault->faultstring);
478
    }
479
  }
480
481
  public function testSendMassEmail() {
482
    echo "testSendMassEmail\r\n";
483
    try {
484
      $massEmail = new MassEmailMessage();
485
      $massEmail->subject = "Nicks Mass Email Message";
486
      $massEmail->saveAsActivity = true;
487
      $massEmail->emailPriority = EMAIL_PRIORITY_LOW;
488
      $massEmail->templateId = "00X50000000wX9q";
489
      $massEmail->targetObjectIds = array ("0035000000PiCMd");
490
491
      $emailResponse = $this->mySforceConnection->sendMassEmail(array($massEmail));
492
493
      $this->assertNotNull($emailResponse);
494
    } catch (SoapFault $fault) {
495
      $this->fail($fault->faultstring);
496
    }
497
  }
498
499
  public function testEmptyRecycleBin() {
500
    echo "testEmptyRecycleBin\r\n";
501
    try {
502
      $fields = array (
503
      'Type' => 'Electrical'
504
      );
505
506
      $sObject = new SObject();
507
      $sObject->fields = $fields;
508
      $sObject->type = 'Case';
509
510
      //echo "Creating Case:\n";
511
      $response = $this->mySforceConnection->create(array ($sObject));
512
      $this->assertNotNull($response);
513
      $id = $response->id;
514
      //echo "Deleted Case:\n";
515
      $response = $this->mySforceConnection->delete(array($id));
516
      $this->assertNotNull($response);
517
      //echo "Empty Recycle Bin:\n";
518
      $response = $this->mySforceConnection->emptyRecycleBin(array($id));
519
      $this->assertNotNull($response);
520
    } catch (SoapFault $fault) {
521
      $this->fail($fault->faultstring);
522
    }
523
  }
524
525
526
}
527
?>