Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
raw copy tests
  • Loading branch information
jsklan committed Oct 7, 2025
commit 012f89697fd9c44dae61b0cb8f7776cfa46bb5e5
30 changes: 30 additions & 0 deletions tests/Legacy/IntercomAdminsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Intercom\Test;

use Intercom\IntercomAdmins;

class IntercomAdminsTest extends TestCase
{
public function testAdminsList()
{
$this->client->method('get')->willReturn('foo');

$users = new IntercomAdmins($this->client);
$this->assertSame('foo', $users->getAdmins());
}

public function testAdminsGet()
{
$this->client->method('get')->willReturn('foo');

$users = new IntercomAdmins($this->client);
$this->assertSame('foo', $users->getAdmin(1));
}

public function testAdminsGetPath()
{
$users = new IntercomAdmins($this->client);
$this->assertSame('admins/1', $users->adminPath(1));
}
}
24 changes: 24 additions & 0 deletions tests/Legacy/IntercomBulkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Intercom\Test;

use Intercom\IntercomBulk;

class IntercomBulkTest extends TestCase
{
public function testBulkUsers()
{
$this->client->method('post')->will($this->returnArgument(0));

$bulk = new IntercomBulk($this->client);
$this->assertSame('bulk/users', $bulk->users([]));
}

public function testBulkEvents()
{
$this->client->method('post')->will($this->returnArgument(0));

$bulk = new IntercomBulk($this->client);
$this->assertSame('bulk/events', $bulk->events([]));
}
}
157 changes: 157 additions & 0 deletions tests/Legacy/IntercomClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

namespace Intercom\Test;

use DateTimeImmutable;
use Http\Client\Common\Plugin\ErrorPlugin;
use Http\Client\Common\PluginClient;
use Http\Client\Exception;
use Http\Discovery\Psr18ClientDiscovery;
use Http\Discovery\Strategy\MockClientStrategy;
use Http\Mock\Client;
use Intercom\IntercomClient;
use Nyholm\Psr7\Response;
use stdClass;

class IntercomClientTest extends TestCase
{
protected function setUp(): void
{
Psr18ClientDiscovery::prependStrategy(MockClientStrategy::class);
}

public function testBasicClient()
{
$httpClient = new Client();
$httpClient->addResponse(
new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}")
);

$client = new IntercomClient('u', 'p');
$client->setHttpClient($httpClient);

$client->users->create([
'email' => 'test@intercom.io'
]);

foreach ($httpClient->getRequests() as $request) {
$basic = $request->getHeaders()['Authorization'][0];
$this->assertSame("Basic dTpw", $basic);
}
}

public function testClientWithExtraHeaders()
{
$httpClient = new Client();
$httpClient->addResponse(
new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}")
);

$client = new IntercomClient('u', 'p', ['Custom-Header' => 'value']);
$client->setHttpClient($httpClient);

$client->users->create([
'email' => 'test@intercom.io'
]);

foreach ($httpClient->getRequests() as $request) {
$headers = $request->getHeaders();
$this->assertSame('application/json', $headers['Accept'][0]);
$this->assertSame('application/json', $headers['Content-Type'][0]);
$this->assertSame('value', $headers['Custom-Header'][0]);
}
}

public function testClientErrorHandling()
{
$httpClient = new Client();
$httpClient->addResponse(
new Response(404)
);
$httpClient = new PluginClient($httpClient, [new ErrorPlugin()]);

$client = new IntercomClient('u', 'p');
$client->setHttpClient($httpClient);

$this->expectException(Exception::class);
$client->users->create([
'email' => 'test@intercom.io'
]);
}

public function testServerErrorHandling()
{
$httpClient = new Client();
$httpClient->addResponse(
new Response(500)
);
$httpClient = new PluginClient($httpClient, [new ErrorPlugin()]);

$client = new IntercomClient('u', 'p');
$client->setHttpClient($httpClient);

$this->expectException(Exception::class);
$client->users->create([
'email' => 'test@intercom.io'
]);
}

public function testPaginationHelper()
{
$httpClient = new Client();
$httpClient->addResponse(
new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}")
);

$client = new IntercomClient('u', 'p');
$client->setHttpClient($httpClient);

$pages = new stdClass;
$pages->next = 'https://foo.com';

$client->nextPage($pages);

foreach ($httpClient->getRequests() as $request) {
$host = $request->getUri()->getHost();
$this->assertSame("foo.com", $host);
}
}

public function testRateLimitDetails()
{
date_default_timezone_set('UTC');
$time = time() + 7;

$httpClient = new Client();
$httpClient->addResponse(
new Response(
200,
[
'X-RateLimit-Limit' => '83',
'X-RateLimit-Remaining' => '2',
'X-RateLimit-Reset' => $time
],
"{\"foo\":\"bar\"}"
)
);

$client = new IntercomClient('u', 'p');
$client->setHttpClient($httpClient);

$client->users->create([
'email' => 'test@intercom.io'
]);

$rateLimitDetails = $client->getRateLimitDetails();
$this->assertIsArray($rateLimitDetails);
$this->assertArrayHasKey('limit', $rateLimitDetails);
$this->assertArrayHasKey('remaining', $rateLimitDetails);
$this->assertArrayHasKey('reset_at', $rateLimitDetails);
$this->assertSame(83, $rateLimitDetails['limit']);
$this->assertSame(2, $rateLimitDetails['remaining']);
$this->assertSame(
(new DateTimeImmutable)->setTimestamp($time)->getTimestamp(),
$rateLimitDetails['reset_at']->getTimestamp()
);
}
}
60 changes: 60 additions & 0 deletions tests/Legacy/IntercomCompaniesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Intercom\Test;

use Intercom\IntercomCompanies;

class IntercomCompaniesTest extends TestCase
{
public function testCompanyCreate()
{
$this->client->method('post')->willReturn('foo');

$companies = new IntercomCompanies($this->client);
$this->assertSame('foo', $companies->create([]));
}

public function testCompanyUpdate()
{
$this->client->method('post')->willReturn('foo');

$companies = new IntercomCompanies($this->client);
$this->assertSame('foo', $companies->update([]));
}

public function testCompanyGet()
{
$this->client->method('get')->willReturn('foo');

$companies = new IntercomCompanies($this->client);
$this->assertSame('foo', $companies->getCompanies([]));
}

public function testCompanyPath()
{
$users = new IntercomCompanies($this->client);
$this->assertSame('companies/foo', $users->companyPath("foo"));
}

public function testCompanyGetById()
{
$this->client->method('get')->willReturn('foo');

$users = new IntercomCompanies($this->client);
$this->assertSame('foo', $users->getCompany("foo"));
}

public function testCompanyGetUsers()
{
$this->client->method('get')->willReturn('foo');

$companies = new IntercomCompanies($this->client);
$this->assertSame('foo', $companies->getCompanyUsers("foo"));
}

public function testCompanyUsersPath()
{
$users = new IntercomCompanies($this->client);
$this->assertSame('companies/foo/users', $users->companyUsersPath("foo"));
}
}
82 changes: 82 additions & 0 deletions tests/Legacy/IntercomContactsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Intercom\Test;

use Intercom\IntercomContacts;
use stdClass;

class IntercomContactsTest extends TestCase
{
public function testContactCreate()
{
$this->client->method('post')->willReturn('foo');

$contacts = new IntercomContacts($this->client);
$this->assertSame('foo', $contacts->create([]));
}

public function testContactUpdate()
{
$this->client->method('put')->willReturn('foo');

$contacts = new IntercomContacts($this->client);
$this->assertSame('foo', $contacts->update('', []));
}

public function testContactsGet()
{
$this->client->method('get')->willReturn('foo');

$contacts = new IntercomContacts($this->client);
$this->assertSame('foo', $contacts->getContacts([]));
}

public function testContactGet()
{
$this->client->method('get')->willReturn('foo');

$contacts = new IntercomContacts($this->client);
$this->assertSame('foo', $contacts->getContact("123"));
}

public function testContactDelete()
{
$this->client->method('delete')->willReturn('foo');

$contacts = new IntercomContacts($this->client);
$this->assertSame('foo', $contacts->deleteContact(''));
}

public function testContactSearch()
{
$this->client->method('post')->willReturn('foo');

$contacts = new IntercomContacts($this->client);
$this->assertSame('foo', $contacts->search([]));
}

public function testContactNextSearch()
{
$this->client->method('nextSearchPage')->willReturn('foo');
$query = [];
$pages = new stdClass;
$pages->per_page = "10";
$pages->next = new stdClass;
$pages->next->starting_after = "abc";

$contacts = new IntercomContacts($this->client);
$this->assertSame('foo', $contacts->nextSearch([], $pages));
}

public function testConversationNextCursor()
{
$this->client->method('nextCursorPage')->willReturn('foo');
$query = [];
$pages = new stdClass;
$pages->next = new stdClass;
$pages->next->starting_after = "abc";

$contacts = new IntercomContacts($this->client);
$this->assertSame('foo', $contacts->nextCursor($pages));
}
}
Loading