Skip to content

Commit

Permalink
Sometimes the succesful flag on the message payload is not set, in th…
Browse files Browse the repository at this point in the history
…ese situations, successful should be treated as true (#52)
  • Loading branch information
Alex Boyce authored Jun 27, 2019
1 parent 944895a commit a1b65e3
Show file tree
Hide file tree
Showing 54 changed files with 653 additions and 264 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ $client = new Client(
"https://login.salesforce.com",
"SF_USER",
"SF_PASS"
)
),
"46.0", // optional version number, defaults to 44.0
"MyAppName" // optional client app name, used when filtering out Change Data Events in the Streaming API
);
```

> For more information about using client app names with Change Data Capture, see
> [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)
If you have an authorization code returned to your redirectUrl and wish to use it, you can do so like this:

```php
Expand Down Expand Up @@ -157,14 +162,22 @@ while (!$result->isDone()) {
}

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

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

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

> For more information on Batch Sizes and the Sforce-Query-Options header, see
> [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).
>
> *It should be noted that batch size may not be respected in Salesforce if it is not optimal for performance*
## Instantiate the Streaming Client
[Reference](https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/intro_stream.htm)

Expand All @@ -182,7 +195,8 @@ $client = new BayeuxClient(
"https://login.salesforce.com",
"SF_USER",
"SF_PASS"
)
),
"46.0" // optional version number, defaults to 44.0
);

```
Expand Down
4 changes: 3 additions & 1 deletion Tests/Bayeux/BayeuxClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ protected function setUp()
getenv("SF_LOGIN_URL"),
getenv("SF_USER"),
getenv("SF_PASS")
)
),
null,
"45.0"
);
}

Expand Down
15 changes: 8 additions & 7 deletions Tests/Bulk/BulkClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ protected function setUp()/* The :void return type declaration that should be he
getenv("SF_LOGIN_URL"),
getenv("SF_USER"),
getenv("SF_PASS")
)
),
"45.0"
);

$builder = SerializerBuilder::create();
Expand Down Expand Up @@ -131,14 +132,14 @@ public function testCSV()

$this->assertNotNull($result);

$objects = $result->getContents();

$this->assertNotEmpty($objects);
$this->assertNotNull($objects[0]['Id']);
$this->assertNotNull($objects[0]['Name']);

$closeJob = $this->client->closeJob($job);
$this->assertEquals($job->getId(), $closeJob->getId());
$this->assertEquals(JobInfo::STATE_CLOSED, $closeJob->getState());

$object = $result->getContents(true)->current();

$this->assertNotEmpty($object);
$this->assertNotNull($object["Id"]);
$this->assertNotNull($object["Name"]);
}
}
24 changes: 24 additions & 0 deletions Tests/Psr7/CsvStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,28 @@ public function testRead()
$row
);
}

public function testGetContents()
{
$testLine = '"Name","Alt Name","Description","Alt Desc"'.PHP_EOL.
'"Item 1","Item 2","This is a longer'.PHP_EOL.'multiline field","Last Field"'.PHP_EOL;
$stream = stream_for($testLine);
$csv = new CsvStream($stream);

foreach ($csv->getContents(true) as $row) {
if (false === $row) {
break;
}
}

$this->assertEquals(
[
"Name" => 'Item 1',
"Alt Name" => 'Item 2',
"Description" => 'This is a longer'.PHP_EOL.'multiline field',
"Alt Desc" => 'Last Field',
],
$row
);
}
}
4 changes: 3 additions & 1 deletion Tests/Rest/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ protected function setUp()/* The :void return type declaration that should be he
getenv("SF_LOGIN_URL"),
getenv("SF_USER"),
getenv("SF_PASS")
)
),
"45.0",
"testing_sdk"
);
}

Expand Down
32 changes: 16 additions & 16 deletions Tests/Rest/Composite/CompositeClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use AE\SalesforceRestSdk\Model\Rest\Composite\CompositeSObject;
use AE\SalesforceRestSdk\Model\SObject;
use AE\SalesforceRestSdk\Rest\Client;
use AE\SalesforceRestSdk\Rest\Composite\Builder\BatchRequestBuilder;
use AE\SalesforceRestSdk\Rest\Composite\Builder\CompositeRequestBuilder;
use AE\SalesforceRestSdk\Rest\Composite\CompositeClient;
use AE\SalesforceRestSdk\Model\Rest\Composite\CollectionRequest;
use PHPUnit\Framework\TestCase;
Expand All @@ -41,7 +39,9 @@ protected function setUp()
getenv("SF_LOGIN_URL"),
getenv("SF_USER"),
getenv("SF_PASS")
)
),
"45.0",
2000
);

$this->client = $this->restClient->getCompositeClient();
Expand Down Expand Up @@ -167,7 +167,7 @@ public function testDelete(array $ids)
public function testCompositeRequest()
{
$now = new \DateTime();
$builder = new CompositeRequestBuilder();
$builder = $this->client->compositeRequestBuilder();

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

$builder
->createSObjectCollection(
Expand Down Expand Up @@ -340,7 +340,7 @@ public function testCompositeCollectionRequest()

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

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

$create = $response->findResultByReferenceId("create");
$this->assertNotNull($create);
Expand Down Expand Up @@ -432,7 +432,7 @@ public function testTree()

public function testBatchSObject()
{
$builder = new BatchRequestBuilder();
$builder = $this->client->batchRequestBuilder();

$builder
->limits()
Expand Down Expand Up @@ -486,7 +486,7 @@ public function testBatchSObject()
*/
public function testBatchSObject2(string $id)
{
$builder = new BatchRequestBuilder();
$builder = $this->client->batchRequestBuilder();
$now = new \DateTime();

$builder
Expand Down Expand Up @@ -540,33 +540,33 @@ public function testBulkRead()
{
// Get 1000 Accounts
$ids = [];
$query = $this->restClient->getSObjectClient()->query("SELECT Id FROM Account LIMIT 1000");
$query = $this->restClient->getSObjectClient()->query("SELECT Id FROM Account LIMIT 500");
do {
foreach ($query->getRecords() as $record) {
$ids[] = $record->Id;
}
} while (!($query = $this->restClient->getSObjectClient()->query($query))->isDone());

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

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

public function testBulkReadComposite()
{
// Get 1000 Accounts
$ids = [];
$query = $this->restClient->getSObjectClient()->query("SELECT Id FROM Account LIMIT 1000");
$query = $this->restClient->getSObjectClient()->query("SELECT Id FROM Account LIMIT 500");
do {
foreach ($query->getRecords() as $record) {
$ids[] = $record->Id;
}
} while (!($query = $this->restClient->getSObjectClient()->query($query))->isDone());

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

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

$subResult = $result->findResultByReferenceId('test_bulk_4');
$this->assertEquals(200, $subResult->getHttpStatusCode());
/** @var CompositeSObject[] $body */
$body = $subResult->getBody();
$this->assertCount(1000, $body);
$this->assertCount(500, $body);
}
}
3 changes: 2 additions & 1 deletion Tests/Rest/GenericEventClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ protected function setUp()/* The :void return type declaration that should be he
getenv("SF_LOGIN_URL"),
getenv("SF_USER"),
getenv("SF_PASS")
)
),
"45.0"
);
$this->sObjectClient = $restClient->getSObjectClient();

Expand Down
6 changes: 3 additions & 3 deletions Tests/Rest/SObject/SObjectClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ protected function setUp()/* The :void return type declaration that should be he
getenv("SF_LOGIN_URL"),
getenv("SF_USER"),
getenv("SF_PASS")
)
),
"45.0",
"testing_sdk"
);

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

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

return $account;
}
Expand Down Expand Up @@ -172,7 +173,6 @@ public function testUpdate(SObject $SObject): SObject
try {
$this->client->persist("Account", $SObject);
$this->assertNotNull($SObject->Id);
$this->assertEquals("Account", $SObject->Type);
} catch (\RuntimeException $e) {
$this->assertTrue(false, $e->getMessage());
}
Expand Down
11 changes: 6 additions & 5 deletions src/Bayeux/BayeuxClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class BayeuxClient

public const VERSION = '1.0';
public const MINIMUM_VERSION = '1.0';
public const SALESFORCE_VERSION = '44.0';

/**
* @var Client
Expand Down Expand Up @@ -119,17 +118,19 @@ class BayeuxClient
* @param AbstractClientTransport $transport
* @param AuthProviderInterface $authProvider
* @param LoggerInterface|null $logger
* @param string $version
*
* @throws \Exception
*/
public function __construct(
AbstractClientTransport $transport,
AuthProviderInterface $authProvider,
LoggerInterface $logger = null
LoggerInterface $logger = null,
string $version = "44.0"
) {
$this->transport = $transport;
$this->authProvider = $authProvider;
$this->httpClient = $this->createClient();
$this->httpClient = $this->createClient($version);
$this->channels = new ArrayCollection();
$this->extensions = new ArrayCollection();
$this->logger = $logger ?: new NullLogger();
Expand All @@ -139,7 +140,7 @@ public function __construct(
}
}

protected function createClient()
protected function createClient(string $version = "44.0")
{
$url = $this->authProvider->getInstanceUrl();

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

return new Client(
[
'base_uri' => $url.'/cometd/'.static::SALESFORCE_VERSION.'/',
'base_uri' => $url.'/cometd/'.$version.'/',
'cookies' => true,
]
);
Expand Down
Loading

0 comments on commit a1b65e3

Please sign in to comment.