Skip to content

Commit d1199e9

Browse files
Update tests. (#298)
* Prefer assertSame instead of assertEquals. * Use assertIsArray. * Use assertSame instead of assertTrue. * Fix expected and actual. * Create the client mock in an abstract TestCase. * Update test/TestCase.php Co-Authored-By: Gabriel Anca Corral <[email protected]> * Update test/IntercomClientTest.php Co-Authored-By: Gabriel Anca Corral <[email protected]> Co-authored-by: Gabriel Anca Corral <[email protected]>
1 parent 6d40169 commit d1199e9

16 files changed

+174
-212
lines changed

test/IntercomAdminsTest.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,28 @@
33
namespace Intercom\Test;
44

55
use Intercom\IntercomAdmins;
6-
use PHPUnit\Framework\TestCase;
76

87
class IntercomAdminsTest extends TestCase
98
{
109
public function testAdminsList()
1110
{
12-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
13-
$stub->method('get')->willReturn('foo');
11+
$this->client->method('get')->willReturn('foo');
1412

15-
$users = new IntercomAdmins($stub);
16-
$this->assertEquals('foo', $users->getAdmins());
13+
$users = new IntercomAdmins($this->client);
14+
$this->assertSame('foo', $users->getAdmins());
1715
}
1816

1917
public function testAdminsGet()
2018
{
21-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
22-
$stub->method('get')->willReturn('foo');
19+
$this->client->method('get')->willReturn('foo');
2320

24-
$users = new IntercomAdmins($stub);
25-
$this->assertEquals('foo', $users->getAdmin(1));
21+
$users = new IntercomAdmins($this->client);
22+
$this->assertSame('foo', $users->getAdmin(1));
2623
}
2724

2825
public function testAdminsGetPath()
2926
{
30-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
31-
32-
$users = new IntercomAdmins($stub);
33-
$this->assertEquals('admins/1', $users->adminPath(1));
27+
$users = new IntercomAdmins($this->client);
28+
$this->assertSame('admins/1', $users->adminPath(1));
3429
}
3530
}

test/IntercomBulkTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,22 @@
33
namespace Intercom\Test;
44

55
use Intercom\IntercomBulk;
6-
use PHPUnit\Framework\TestCase;
76

87
class IntercomBulkTest extends TestCase
98
{
109
public function testBulkUsers()
1110
{
12-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
13-
$stub->method('post')->will($this->returnArgument(0));
11+
$this->client->method('post')->will($this->returnArgument(0));
1412

15-
$bulk = new IntercomBulk($stub);
16-
$this->assertEquals('bulk/users', $bulk->users([]));
13+
$bulk = new IntercomBulk($this->client);
14+
$this->assertSame('bulk/users', $bulk->users([]));
1715
}
1816

1917
public function testBulkEvents()
2018
{
21-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
22-
$stub->method('post')->will($this->returnArgument(0));
19+
$this->client->method('post')->will($this->returnArgument(0));
2320

24-
$bulk = new IntercomBulk($stub);
25-
$this->assertEquals('bulk/events', $bulk->events([]));
21+
$bulk = new IntercomBulk($this->client);
22+
$this->assertSame('bulk/events', $bulk->events([]));
2623
}
2724
}

test/IntercomClientTest.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace Intercom\Test;
44

55
use DateTimeImmutable;
6-
use Http\Adapter\Guzzle6\Client;
7-
use Http\Client\Exception;
8-
use Intercom\IntercomClient;
96
use GuzzleHttp\Client as GuzzleClient;
107
use GuzzleHttp\Handler\MockHandler;
11-
use GuzzleHttp\Psr7\Response;
128
use GuzzleHttp\HandlerStack;
139
use GuzzleHttp\Middleware;
10+
use GuzzleHttp\Psr7\Response;
11+
use Http\Adapter\Guzzle6\Client;
12+
use Http\Client\Exception;
13+
use Intercom\IntercomClient;
1414
use PHPUnit\Framework\TestCase;
1515
use stdClass;
1616

@@ -38,7 +38,7 @@ public function testBasicClient()
3838

3939
foreach ($container as $transaction) {
4040
$basic = $transaction['request']->getHeaders()['Authorization'][0];
41-
$this->assertTrue($basic == "Basic dTpw");
41+
$this->assertSame("Basic dTpw", $basic);
4242
}
4343
}
4444

@@ -64,7 +64,7 @@ public function testExtendedClient()
6464

6565
foreach ($container as $transaction) {
6666
$options = $transaction['options'];
67-
$this->assertEquals($options['connect_timeout'], 10);
67+
$this->assertSame(10, $options['connect_timeout']);
6868
}
6969
}
7070

@@ -90,9 +90,9 @@ public function testClientWithExtraHeaders()
9090

9191
foreach ($container as $transaction) {
9292
$headers = $transaction['request']->getHeaders();
93-
$this->assertEquals($headers['Accept'][0], 'application/json');
94-
$this->assertEquals($headers['Content-Type'][0], 'application/json');
95-
$this->assertEquals($headers['Custom-Header'][0], 'value');
93+
$this->assertSame('application/json', $headers['Accept'][0]);
94+
$this->assertSame('application/json', $headers['Content-Type'][0]);
95+
$this->assertSame('value', $headers['Custom-Header'][0]);
9696
}
9797
}
9898

@@ -163,7 +163,7 @@ public function testPaginationHelper()
163163

164164
foreach ($container as $transaction) {
165165
$host = $transaction['request']->getUri()->getHost();
166-
$this->assertTrue($host == "foo.com");
166+
$this->assertSame("foo.com", $host);
167167
}
168168
}
169169

@@ -198,12 +198,15 @@ public function testRateLimitDetails()
198198
]);
199199

200200
$rateLimitDetails = $client->getRateLimitDetails();
201-
$this->assertInternalType('array', $rateLimitDetails);
201+
$this->assertIsArray($rateLimitDetails);
202202
$this->assertArrayHasKey('limit', $rateLimitDetails);
203203
$this->assertArrayHasKey('remaining', $rateLimitDetails);
204204
$this->assertArrayHasKey('reset_at', $rateLimitDetails);
205-
$this->assertEquals(83, $rateLimitDetails['limit']);
206-
$this->assertEquals(2, $rateLimitDetails['remaining']);
207-
$this->assertEquals((new DateTimeImmutable)->setTimestamp($time), $rateLimitDetails['reset_at']);
205+
$this->assertSame(83, $rateLimitDetails['limit']);
206+
$this->assertSame(2, $rateLimitDetails['remaining']);
207+
$this->assertSame(
208+
(new DateTimeImmutable)->setTimestamp($time)->getTimestamp(),
209+
$rateLimitDetails['reset_at']->getTimestamp()
210+
);
208211
}
209212
}

test/IntercomCompaniesTest.php

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,58 @@
33
namespace Intercom\Test;
44

55
use Intercom\IntercomCompanies;
6-
use PHPUnit\Framework\TestCase;
76

87
class IntercomCompaniesTest extends TestCase
98
{
109
public function testCompanyCreate()
1110
{
12-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
13-
$stub->method('post')->willReturn('foo');
11+
$this->client->method('post')->willReturn('foo');
1412

15-
$companies = new IntercomCompanies($stub);
16-
$this->assertEquals('foo', $companies->create([]));
13+
$companies = new IntercomCompanies($this->client);
14+
$this->assertSame('foo', $companies->create([]));
1715
}
1816

1917
public function testCompanyUpdate()
2018
{
21-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
22-
$stub->method('post')->willReturn('foo');
19+
$this->client->method('post')->willReturn('foo');
2320

24-
$companies = new IntercomCompanies($stub);
25-
$this->assertEquals('foo', $companies->update([]));
21+
$companies = new IntercomCompanies($this->client);
22+
$this->assertSame('foo', $companies->update([]));
2623
}
2724

2825
public function testCompanyGet()
2926
{
30-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
31-
$stub->method('get')->willReturn('foo');
27+
$this->client->method('get')->willReturn('foo');
3228

33-
$companies = new IntercomCompanies($stub);
34-
$this->assertEquals('foo', $companies->getCompanies([]));
29+
$companies = new IntercomCompanies($this->client);
30+
$this->assertSame('foo', $companies->getCompanies([]));
3531
}
3632

3733
public function testCompanyPath()
3834
{
39-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
40-
$users = new IntercomCompanies($stub);
41-
$this->assertEquals('companies/foo', $users->companyPath("foo"));
35+
$users = new IntercomCompanies($this->client);
36+
$this->assertSame('companies/foo', $users->companyPath("foo"));
4237
}
4338

4439
public function testCompanyGetById()
4540
{
46-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
47-
$stub->method('get')->willReturn('foo');
41+
$this->client->method('get')->willReturn('foo');
4842

49-
$users = new IntercomCompanies($stub);
50-
$this->assertEquals('foo', $users->getCompany("foo"));
43+
$users = new IntercomCompanies($this->client);
44+
$this->assertSame('foo', $users->getCompany("foo"));
5145
}
5246

5347
public function testCompanyGetUsers()
5448
{
55-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
56-
$stub->method('get')->willReturn('foo');
49+
$this->client->method('get')->willReturn('foo');
5750

58-
$companies = new IntercomCompanies($stub);
59-
$this->assertEquals('foo', $companies->getCompanyUsers("foo"));
51+
$companies = new IntercomCompanies($this->client);
52+
$this->assertSame('foo', $companies->getCompanyUsers("foo"));
6053
}
6154

6255
public function testCompanyUsersPath()
6356
{
64-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
65-
$users = new IntercomCompanies($stub);
66-
$this->assertEquals('companies/foo/users', $users->companyUsersPath("foo"));
57+
$users = new IntercomCompanies($this->client);
58+
$this->assertSame('companies/foo/users', $users->companyUsersPath("foo"));
6759
}
6860
}

test/IntercomConversationsTest.php

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,42 @@
33
namespace Intercom\Test;
44

55
use Intercom\IntercomConversations;
6-
use PHPUnit\Framework\TestCase;
76

87
class IntercomConversationsTest extends TestCase
98
{
109
public function testConversationsList()
1110
{
12-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
13-
$stub->method('get')->willReturn('foo');
11+
$this->client->method('get')->willReturn('foo');
1412

15-
$users = new IntercomConversations($stub);
16-
$this->assertEquals('foo', $users->getConversations([]));
13+
$users = new IntercomConversations($this->client);
14+
$this->assertSame('foo', $users->getConversations([]));
1715
}
1816

1917
public function testConversationPath()
2018
{
21-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
22-
$users = new IntercomConversations($stub);
23-
$this->assertEquals('conversations/foo', $users->conversationPath("foo"));
19+
$users = new IntercomConversations($this->client);
20+
$this->assertSame('conversations/foo', $users->conversationPath("foo"));
2421
}
2522

2623
public function testGetConversation()
2724
{
28-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
29-
$stub->method('get')->willReturn('foo');
25+
$this->client->method('get')->willReturn('foo');
3026

31-
$users = new IntercomConversations($stub);
32-
$this->assertEquals('foo', $users->getConversation("foo"));
27+
$users = new IntercomConversations($this->client);
28+
$this->assertSame('foo', $users->getConversation("foo"));
3329
}
3430

3531
public function testConversationReplyPath()
3632
{
37-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
38-
$users = new IntercomConversations($stub);
39-
$this->assertEquals('conversations/foo/reply', $users->conversationReplyPath("foo"));
33+
$users = new IntercomConversations($this->client);
34+
$this->assertSame('conversations/foo/reply', $users->conversationReplyPath("foo"));
4035
}
4136

4237
public function testReplyToConversation()
4338
{
44-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
45-
$stub->method('post')->willReturn('foo');
39+
$this->client->method('post')->willReturn('foo');
4640

47-
$users = new IntercomConversations($stub);
48-
$this->assertEquals('foo', $users->replyToConversation("bar", []));
41+
$users = new IntercomConversations($this->client);
42+
$this->assertSame('foo', $users->replyToConversation("bar", []));
4943
}
5044
}

test/IntercomCountsTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
namespace Intercom\Test;
44

55
use Intercom\IntercomCounts;
6-
use PHPUnit\Framework\TestCase;
76

87
class IntercomCountsTest extends TestCase
98
{
109
public function testCountsList()
1110
{
12-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
13-
$stub->method('get')->willReturn('foo');
11+
$this->client->method('get')->willReturn('foo');
1412

15-
$counts = new IntercomCounts($stub);
16-
$this->assertEquals('foo', $counts->getCounts([]));
13+
$counts = new IntercomCounts($this->client);
14+
$this->assertSame('foo', $counts->getCounts([]));
1715
}
1816
}

test/IntercomCustomersTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
namespace Intercom\Test;
44

55
use Intercom\IntercomCustomers;
6-
use PHPUnit\Framework\TestCase;
76

87
class IntercomCustomersTest extends TestCase
98
{
109
public function testCustomerSearch()
1110
{
12-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
13-
$stub->method('post')->willReturn('foo');
11+
$this->client->method('post')->willReturn('foo');
1412

15-
$customers = new IntercomCustomers($stub);
16-
$this->assertEquals('foo', $customers->search(["query" => []]));
13+
$customers = new IntercomCustomers($this->client);
14+
$this->assertSame('foo', $customers->search(["query" => []]));
1715
}
1816
}

test/IntercomEventsTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,22 @@
33
namespace Intercom\Test;
44

55
use Intercom\IntercomEvents;
6-
use PHPUnit\Framework\TestCase;
76

87
class IntercomEventsTest extends TestCase
98
{
109
public function testEventCreate()
1110
{
12-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
13-
$stub->method('post')->willReturn('foo');
11+
$this->client->method('post')->willReturn('foo');
1412

15-
$users = new IntercomEvents($stub);
16-
$this->assertEquals('foo', $users->create([]));
13+
$users = new IntercomEvents($this->client);
14+
$this->assertSame('foo', $users->create([]));
1715
}
1816

1917
public function testEventsGet()
2018
{
21-
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
22-
$stub->method('get')->willReturn('foo');
19+
$this->client->method('get')->willReturn('foo');
2320

24-
$users = new IntercomEvents($stub);
25-
$this->assertEquals('foo', $users->getEvents([]));
21+
$users = new IntercomEvents($this->client);
22+
$this->assertSame('foo', $users->getEvents([]));
2623
}
2724
}

0 commit comments

Comments
 (0)