-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathClientTest.php
More file actions
104 lines (88 loc) · 3.41 KB
/
ClientTest.php
File metadata and controls
104 lines (88 loc) · 3.41 KB
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
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace GetStream\Unit;
use GetStream\Stream\Client;
use PHPUnit\Framework\TestCase;
class ClientTest extends TestCase
{
public function testClientSetProtocol()
{
if (!str_contains(getenv('STREAM_BASE_URL'), 'localhost')) {
$client = new Client('key', 'secret');
$client->setProtocol('asdfg');
$url = $client->buildRequestUrl('x');
$this->assertSame('asdfg://api.stream-io-api.com/api/v1.0/x', $url);
}
}
public function testClientHostnames()
{
if (!str_contains(getenv('STREAM_BASE_URL'), 'localhost')) {
$client = new Client('key', 'secret');
$client->setLocation('qa');
$url = $client->buildRequestUrl('x');
$this->assertSame('https://qa-api.stream-io-api.com/api/v1.0/x', $url);
$client = new Client('key', 'secret', $api_version = '1234', $location = 'asdfg');
$url = $client->buildRequestUrl('y');
$this->assertSame('https://asdfg-api.stream-io-api.com/api/1234/y', $url);
$client = new Client('key', 'secret');
$client->setLocation('us-east');
$url = $client->buildRequestUrl('z');
$this->assertSame('https://us-east-api.stream-io-api.com/api/v1.0/z', $url);
}
}
public function testClientSigning()
{
$client = new Client('key', 'secret');
$digested = $client->signer->signature('feed:1');
$this->assertEquals('_uLo-YmjaGyY3u6NJTXw_fHdFBM', $digested);
$digested2 = $client->signer->signature('feed:2');
$this->assertNotEquals($digested2, $digested);
}
public function testClientFeed()
{
$client = new Client('key', str_repeat('s', 32), $location='qa');
$feed1 = $client->feed('flat', '1');
$this->assertSame($feed1->getId(), 'flat:1');
}
public function testCreateReference()
{
$client = new Client('key', str_repeat('s', 32), $location='qa');
$ref = $client->collections()->createReference("item", "42");
$this->assertEquals($ref, "SO:item:42");
}
public function testCreateUserReference()
{
$client = new Client('key', str_repeat('s', 32), $location='qa');
$ref = $client->users()->createReference("42");
$this->assertEquals($ref, "SU:42");
}
public function testGetActivitiesByForeignIdExceptionNoArray()
{
$this->expectException(\GetStream\Stream\StreamFeedException::class);
$client = new Client('key', 'secret');
$client->getActivitiesByForeignId([1, 2]);
}
public function testGetActivitiesByForeignIdExceptionMalformedArray()
{
$this->expectException(\GetStream\Stream\StreamFeedException::class);
$client = new Client('key', 'secret');
$client->getActivitiesByForeignId([[1, 2], [2, 3, 4]]);
}
public function testEnvironmentVariable()
{
// Arrange
$previous = getenv('STREAM_BASE_URL');
putenv('STREAM_BASE_URL=test.stream-api.com/api');
$client = new Client('key', 'secret');
// Act
$baseUrl = $client->getBaseUrl();
// Assert
$this->assertSame('test.stream-api.com/api', $baseUrl);
// Teardown
if ($previous === false) {
// Remove the environment variable.
putenv('STREAM_BASE_URL');
} else {
putenv('STREAM_BASE_URL='.$previous);
}
}
}