Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@ protected function doSend(MessageInterface $message): SentMessage

$options = $opts ? $opts->toArray() : [];
$options['app_id'] = $this->appId;
$options['include_player_ids'] = [$recipientId];
if (isset($options['external_id'])) {
$options['include_aliases'] = [
'external_id' => [
$options['external_id']
]
];
$options['target_channel'] = 'push';
unset($options['external_id']);
} else {
$options['include_subscription_ids'] = [$recipientId]; // include_player_ids has been deprecated
}

if (!isset($options['headings'])) {
$options['headings'] = ['en' => $message->getSubject()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function testSend()
->method('getContent')
->willReturn(json_encode(['id' => 'b98881cc-1e94-4366-bbd9-db8f3429292b', 'recipients' => 1, 'external_id' => null]));

$expectedBody = json_encode(['app_id' => '9fb175f0-0b32-4e99-ae97-bd228b9eb246', 'headings' => ['en' => 'Hello'], 'contents' => ['en' => 'World'], 'include_player_ids' => ['ea345989-d273-4f21-a33b-0c006efc5edb']]);
$expectedBody = json_encode(['app_id' => '9fb175f0-0b32-4e99-ae97-bd228b9eb246', 'headings' => ['en' => 'Hello'], 'contents' => ['en' => 'World'], 'include_subscription_ids' => ['ea345989-d273-4f21-a33b-0c006efc5edb']]);

$client = new MockHttpClient(function (string $method, string $url, array $options = []) use ($response, $expectedBody): ResponseInterface {
$this->assertJsonStringEqualsJsonString($expectedBody, $options['body']);
Expand All @@ -159,4 +159,32 @@ public function testSend()

$this->assertSame('b98881cc-1e94-4366-bbd9-db8f3429292b', $sentMessage->getMessageId());
}

public function testSendExternalIds()
{
$response = $this->createMock(ResponseInterface::class);
$response->expects($this->exactly(2))
->method('getStatusCode')
->willReturn(200);
$response->expects($this->once())
->method('getContent')
->willReturn(json_encode(['id' => 'b98881cc-1e94-4366-bbd9-db8f3429292b', 'recipients' => 1, 'external_id' => null]));

$expectedBody = json_encode(['app_id' => '9fb175f0-0b32-4e99-ae97-bd228b9eb246', 'headings' => ['en' => 'Hello'], 'contents' => ['en' => 'World'], 'include_aliases' => ['external_id' => ['external_id']], 'target_channel' => 'push']);

$client = new MockHttpClient(function (string $method, string $url, array $options = []) use ($response, $expectedBody): ResponseInterface {
$this->assertJsonStringEqualsJsonString($expectedBody, $options['body']);

return $response;
});

$transport = self::createTransport($client, 'ea345989-d273-4f21-a33b-0c006efc5edb');

$options = new OneSignalOptions();
$options->externalId('external_id');

$sentMessage = $transport->send(new PushMessage('Hello', 'World', $options));

$this->assertSame('b98881cc-1e94-4366-bbd9-db8f3429292b', $sentMessage->getMessageId());
}
}