Skip to content

Commit 56e8393

Browse files
author
Alex Boyce
authored
Merge pull request #53 from advisors-excel-llc/develop
Develop
2 parents 6f29f5b + a1b65e3 commit 56e8393

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+653
-264
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ $client = new Client(
2828
"https://login.salesforce.com",
2929
"SF_USER",
3030
"SF_PASS"
31-
)
31+
),
32+
"46.0", // optional version number, defaults to 44.0
33+
"MyAppName" // optional client app name, used when filtering out Change Data Events in the Streaming API
3234
);
3335
```
3436

37+
> For more information about using client app names with Change Data Capture, see
38+
> [https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_event_fields_header.htm](https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_event_fields_header.htm)
39+
3540
If you have an authorization code returned to your redirectUrl and wish to use it, you can do so like this:
3641

3742
```php
@@ -157,14 +162,22 @@ while (!$result->isDone()) {
157162
}
158163

159164
// Query deleted and merged records, too
160-
$result = $sObjectClient->queryAll("SELECT Id, Name FROM Account");
165+
$result = $sObjectClient->queryAll(
166+
"SELECT Id, Name FROM Account",
167+
1000 // optional batch size, defaults to 2000, which is the max, min is 200
168+
);
161169

162170
// Search for something
163171
$result = $sObjectClient->search("FIND {Some Query} IN ALL FIELDS");
164172

165173
var_dump($result->getSearchRecords()); // CompositeSObject[]
166174
```
167175

176+
> For more information on Batch Sizes and the Sforce-Query-Options header, see
177+
> [https://developer.salesforce.com/docs/atlas.en-us.220.0.api_rest.meta/api_rest/headers_queryoptions.htm](https://developer.salesforce.com/docs/atlas.en-us.220.0.api_rest.meta/api_rest/headers_queryoptions.htm).
178+
>
179+
> *It should be noted that batch size may not be respected in Salesforce if it is not optimal for performance*
180+
168181
## Instantiate the Streaming Client
169182
[Reference](https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/intro_stream.htm)
170183

@@ -182,7 +195,8 @@ $client = new BayeuxClient(
182195
"https://login.salesforce.com",
183196
"SF_USER",
184197
"SF_PASS"
185-
)
198+
),
199+
"46.0" // optional version number, defaults to 44.0
186200
);
187201

188202
```

Tests/Bayeux/BayeuxClientTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ protected function setUp()
3838
getenv("SF_LOGIN_URL"),
3939
getenv("SF_USER"),
4040
getenv("SF_PASS")
41-
)
41+
),
42+
null,
43+
"45.0"
4244
);
4345
}
4446

Tests/Bulk/BulkClientTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ protected function setUp()/* The :void return type declaration that should be he
4747
getenv("SF_LOGIN_URL"),
4848
getenv("SF_USER"),
4949
getenv("SF_PASS")
50-
)
50+
),
51+
"45.0"
5152
);
5253

5354
$builder = SerializerBuilder::create();
@@ -131,14 +132,14 @@ public function testCSV()
131132

132133
$this->assertNotNull($result);
133134

134-
$objects = $result->getContents();
135-
136-
$this->assertNotEmpty($objects);
137-
$this->assertNotNull($objects[0]['Id']);
138-
$this->assertNotNull($objects[0]['Name']);
139-
140135
$closeJob = $this->client->closeJob($job);
141136
$this->assertEquals($job->getId(), $closeJob->getId());
142137
$this->assertEquals(JobInfo::STATE_CLOSED, $closeJob->getState());
138+
139+
$object = $result->getContents(true)->current();
140+
141+
$this->assertNotEmpty($object);
142+
$this->assertNotNull($object["Id"]);
143+
$this->assertNotNull($object["Name"]);
143144
}
144145
}

Tests/Psr7/CsvStreamTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,28 @@ public function testRead()
3838
$row
3939
);
4040
}
41+
42+
public function testGetContents()
43+
{
44+
$testLine = '"Name","Alt Name","Description","Alt Desc"'.PHP_EOL.
45+
'"Item 1","Item 2","This is a longer'.PHP_EOL.'multiline field","Last Field"'.PHP_EOL;
46+
$stream = stream_for($testLine);
47+
$csv = new CsvStream($stream);
48+
49+
foreach ($csv->getContents(true) as $row) {
50+
if (false === $row) {
51+
break;
52+
}
53+
}
54+
55+
$this->assertEquals(
56+
[
57+
"Name" => 'Item 1',
58+
"Alt Name" => 'Item 2',
59+
"Description" => 'This is a longer'.PHP_EOL.'multiline field',
60+
"Alt Desc" => 'Last Field',
61+
],
62+
$row
63+
);
64+
}
4165
}

Tests/Rest/ClientTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ protected function setUp()/* The :void return type declaration that should be he
2727
getenv("SF_LOGIN_URL"),
2828
getenv("SF_USER"),
2929
getenv("SF_PASS")
30-
)
30+
),
31+
"45.0",
32+
"testing_sdk"
3133
);
3234
}
3335

Tests/Rest/Composite/CompositeClientTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
use AE\SalesforceRestSdk\Model\Rest\Composite\CompositeSObject;
1515
use AE\SalesforceRestSdk\Model\SObject;
1616
use AE\SalesforceRestSdk\Rest\Client;
17-
use AE\SalesforceRestSdk\Rest\Composite\Builder\BatchRequestBuilder;
18-
use AE\SalesforceRestSdk\Rest\Composite\Builder\CompositeRequestBuilder;
1917
use AE\SalesforceRestSdk\Rest\Composite\CompositeClient;
2018
use AE\SalesforceRestSdk\Model\Rest\Composite\CollectionRequest;
2119
use PHPUnit\Framework\TestCase;
@@ -41,7 +39,9 @@ protected function setUp()
4139
getenv("SF_LOGIN_URL"),
4240
getenv("SF_USER"),
4341
getenv("SF_PASS")
44-
)
42+
),
43+
"45.0",
44+
2000
4545
);
4646

4747
$this->client = $this->restClient->getCompositeClient();
@@ -167,7 +167,7 @@ public function testDelete(array $ids)
167167
public function testCompositeRequest()
168168
{
169169
$now = new \DateTime();
170-
$builder = new CompositeRequestBuilder();
170+
$builder = $this->client->compositeRequestBuilder();
171171

172172
$builder
173173
->info("BasicInfo", "Account")
@@ -281,7 +281,7 @@ public function testCompositeRequest()
281281
// It's not like this couldn't be rolled into the previous test, but that thing was getting huge
282282
public function testCompositeCollectionRequest()
283283
{
284-
$builder = new CompositeRequestBuilder();
284+
$builder = $this->client->compositeRequestBuilder();
285285

286286
$builder
287287
->createSObjectCollection(
@@ -340,7 +340,7 @@ public function testCompositeCollectionRequest()
340340

341341
$response = $this->client->sendCompositeRequest($builder->build());
342342

343-
$this->assertCount(7, $response->getCompositeResponse());
343+
$this->assertCount(6, $response->getCompositeResponse());
344344

345345
$create = $response->findResultByReferenceId("create");
346346
$this->assertNotNull($create);
@@ -432,7 +432,7 @@ public function testTree()
432432

433433
public function testBatchSObject()
434434
{
435-
$builder = new BatchRequestBuilder();
435+
$builder = $this->client->batchRequestBuilder();
436436

437437
$builder
438438
->limits()
@@ -486,7 +486,7 @@ public function testBatchSObject()
486486
*/
487487
public function testBatchSObject2(string $id)
488488
{
489-
$builder = new BatchRequestBuilder();
489+
$builder = $this->client->batchRequestBuilder();
490490
$now = new \DateTime();
491491

492492
$builder
@@ -540,33 +540,33 @@ public function testBulkRead()
540540
{
541541
// Get 1000 Accounts
542542
$ids = [];
543-
$query = $this->restClient->getSObjectClient()->query("SELECT Id FROM Account LIMIT 1000");
543+
$query = $this->restClient->getSObjectClient()->query("SELECT Id FROM Account LIMIT 500");
544544
do {
545545
foreach ($query->getRecords() as $record) {
546546
$ids[] = $record->Id;
547547
}
548548
} while (!($query = $this->restClient->getSObjectClient()->query($query))->isDone());
549549

550-
$this->assertCount(1000, $ids);
550+
$this->assertCount(500, $ids);
551551

552552
$result = $this->client->read('Account', $ids, ['Id', 'Name']);
553-
$this->assertCount(1000, $result);
553+
$this->assertCount(500, $result);
554554
}
555555

556556
public function testBulkReadComposite()
557557
{
558558
// Get 1000 Accounts
559559
$ids = [];
560-
$query = $this->restClient->getSObjectClient()->query("SELECT Id FROM Account LIMIT 1000");
560+
$query = $this->restClient->getSObjectClient()->query("SELECT Id FROM Account LIMIT 500");
561561
do {
562562
foreach ($query->getRecords() as $record) {
563563
$ids[] = $record->Id;
564564
}
565565
} while (!($query = $this->restClient->getSObjectClient()->query($query))->isDone());
566566

567-
$this->assertCount(1000, $ids);
567+
$this->assertCount(500, $ids);
568568

569-
$builder = new CompositeRequestBuilder();
569+
$builder = $this->client->compositeRequestBuilder();
570570
for ($i = 0; $i < 5; $i++) {
571571
$builder->getSObjectCollection('test_bulk_'.$i, 'Account', $ids, ['Id', 'Name']);
572572
}
@@ -576,12 +576,12 @@ public function testBulkReadComposite()
576576
$this->assertEquals(200, $subResult->getHttpStatusCode());
577577
/** @var CompositeSObject[] $body */
578578
$body = $subResult->getBody();
579-
$this->assertCount(1000, $body);
579+
$this->assertCount(500, $body);
580580

581581
$subResult = $result->findResultByReferenceId('test_bulk_4');
582582
$this->assertEquals(200, $subResult->getHttpStatusCode());
583583
/** @var CompositeSObject[] $body */
584584
$body = $subResult->getBody();
585-
$this->assertCount(1000, $body);
585+
$this->assertCount(500, $body);
586586
}
587587
}

Tests/Rest/GenericEventClientTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ protected function setUp()/* The :void return type declaration that should be he
3737
getenv("SF_LOGIN_URL"),
3838
getenv("SF_USER"),
3939
getenv("SF_PASS")
40-
)
40+
),
41+
"45.0"
4142
);
4243
$this->sObjectClient = $restClient->getSObjectClient();
4344

Tests/Rest/SObject/SObjectClientTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ protected function setUp()/* The :void return type declaration that should be he
3030
getenv("SF_LOGIN_URL"),
3131
getenv("SF_USER"),
3232
getenv("SF_PASS")
33-
)
33+
),
34+
"45.0",
35+
"testing_sdk"
3436
);
3537

3638
$this->client = $client->getSObjectClient();
@@ -77,7 +79,6 @@ public function testCreate()
7779

7880
$this->assertTrue($saved);
7981
$this->assertNotNull($account->Id);
80-
$this->assertEquals("Account", $account->Type);
8182

8283
return $account;
8384
}
@@ -172,7 +173,6 @@ public function testUpdate(SObject $SObject): SObject
172173
try {
173174
$this->client->persist("Account", $SObject);
174175
$this->assertNotNull($SObject->Id);
175-
$this->assertEquals("Account", $SObject->Type);
176176
} catch (\RuntimeException $e) {
177177
$this->assertTrue(false, $e->getMessage());
178178
}

src/Bayeux/BayeuxClient.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class BayeuxClient
6161

6262
public const VERSION = '1.0';
6363
public const MINIMUM_VERSION = '1.0';
64-
public const SALESFORCE_VERSION = '44.0';
6564

6665
/**
6766
* @var Client
@@ -119,17 +118,19 @@ class BayeuxClient
119118
* @param AbstractClientTransport $transport
120119
* @param AuthProviderInterface $authProvider
121120
* @param LoggerInterface|null $logger
121+
* @param string $version
122122
*
123123
* @throws \Exception
124124
*/
125125
public function __construct(
126126
AbstractClientTransport $transport,
127127
AuthProviderInterface $authProvider,
128-
LoggerInterface $logger = null
128+
LoggerInterface $logger = null,
129+
string $version = "44.0"
129130
) {
130131
$this->transport = $transport;
131132
$this->authProvider = $authProvider;
132-
$this->httpClient = $this->createClient();
133+
$this->httpClient = $this->createClient($version);
133134
$this->channels = new ArrayCollection();
134135
$this->extensions = new ArrayCollection();
135136
$this->logger = $logger ?: new NullLogger();
@@ -139,7 +140,7 @@ public function __construct(
139140
}
140141
}
141142

142-
protected function createClient()
143+
protected function createClient(string $version = "44.0")
143144
{
144145
$url = $this->authProvider->getInstanceUrl();
145146

@@ -150,7 +151,7 @@ protected function createClient()
150151

151152
return new Client(
152153
[
153-
'base_uri' => $url.'/cometd/'.static::SALESFORCE_VERSION.'/',
154+
'base_uri' => $url.'/cometd/'.$version.'/',
154155
'cookies' => true,
155156
]
156157
);

0 commit comments

Comments
 (0)