This repository has been archived by the owner on Nov 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClientTest.php
93 lines (78 loc) · 2.79 KB
/
ClientTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace Botamp;
class ClientTest extends TestCase
{
private $apiKey;
private $client;
private $allApiVersions;
public function setUp()
{
$this->apiKey = '123456789';
$this->client = new Client($this->apiKey);
$this->allApiVersions = TestCase::getProperty('Botamp\Client', 'allApiVersions');
}
public function test_shouldSetApiBase()
{
$newApiBase = 'https://customdomain.com/botamp-api';
$this->client->setApiBase($newApiBase);
$this->assertAttributeEquals($newApiBase, 'apiBase', $this->client);
}
public function test_shouldGetApiBase()
{
$this->assertEquals('https://app.botamp.com/api', $this->client->getApiBase());
}
public function test_ShouldGetApiKey()
{
$this->assertEquals($this->apiKey, $this->client->getApiKey());
}
public function test_ShouldGetHttpClient()
{
$this->assertInstanceOf('Http\Client\HttpClient', $this->client->getHttpClient());
}
public function test_shouldGetApiResourceInstance()
{
$this->assertInstanceOf('Botamp\Api\ApiResource', $this->client->entities);
}
public function test_ShouldGetValidApiVersion()
{
$this->assertContains($this->client->getApiVersion(), $this->allApiVersions->getValue());
}
/**
* @dataProvider apiVersionsProvider
*/
public function test_ShouldSetApiVersion($apiVersion)
{
$this->allApiVersions->setValue($this->client, array('v2', 'v3', 'v4', 'v5'));
$this->client->setApiVersion($apiVersion);
$this->assertEquals(strtolower($apiVersion), $this->client->getApiVersion());
}
public function testShouldGetPageAttributes()
{
$attributes = ['page_id' => '123456', 'page_access_token' => 'A123456Z'];
$url = 'https://app.botamp.com/api/v1/me';
$httpClient = $this->getHttpMethodsMock(array('get'));
$httpClient
->expects($this->any())
->method('get')
->with($url, array())
->will($this->returnValue($this->getPSR7Response($attributes)));
$client = $this->getMock('Botamp\Client', array('getHttpClient'), array('123456789'));
$client->expects($this->any())
->method('getHttpClient')
->willReturn($httpClient);
$this->assertEquals($attributes, $client->getPageAttributes());
}
/**
* @expectedException Botamp\Exceptions\Base
* @expectedExceptionMessage No valid api version provided.
*/
public function test_shouldThrowExceptionIfTryingToSetBadApiVersion()
{
$this->allApiVersions->setValue($this->client, array('v1'));
$this->client->setApiVersion('v2');
}
public function apiVersionsProvider()
{
return [['v2'], ['v3'], ['v4'], ['v5']];
}
}