-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLiveIntegrationTest.php
More file actions
107 lines (86 loc) · 3.05 KB
/
LiveIntegrationTest.php
File metadata and controls
107 lines (86 loc) · 3.05 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
105
106
107
<?php
declare(strict_types=1);
namespace GetStream\Tests\Integration;
use GetStream\ClientBuilder;
use GetStream\Exceptions\StreamApiException;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
/**
* Live integration tests - these make real API calls
* Run with: ./vendor/bin/phpunit tests/Integration/LiveIntegrationTest.php --testdox.
*/
#[Group('integration')]
class LiveIntegrationTest extends TestCase
{
private $client;
private string $testUserId;
protected function setUp(): void
{
$this->client = ClientBuilder::fromEnv()->build();
$this->testUserId = 'live-test-' . uniqid();
}
/**
* @test
*/
public function tokenGenerationWorks(): void
{
// This doesn't make API calls, just tests token generation
$token = $this->client->createUserToken($this->testUserId);
self::assertIsString($token);
self::assertNotEmpty($token);
// Verify JWT structure
$parts = explode('.', $token);
self::assertCount(3, $parts);
$payload = json_decode(base64_decode($parts[1], true), true);
self::assertSame($this->testUserId, $payload['user_id']);
echo "✅ Token generated for user: {$this->testUserId}\n";
}
/**
* @group live-api
*
* @test
*/
public function addActivityToRealAPI(): void
{
self::markTestIncomplete('Enable this test only when you want to make real API calls');
$feed = $this->client->feed('user', $this->testUserId);
$activity = [
'actor' => 'user:' . $this->testUserId,
'verb' => 'post',
'object' => 'message:' . uniqid(),
'message' => 'Live integration test from PHP SDK!',
'time' => date('c'),
];
try {
$response = $feed->addActivity($activity);
self::assertTrue($response->isSuccessful());
$data = $response->getData();
self::assertArrayHasKey('id', $data);
echo "✅ Activity added with ID: {$data['id']}\n";
} catch (StreamApiException $e) {
echo "❌ API Error: {$e->getMessage()} (Status: {$e->getStatusCode()})\n";
echo "Response: {$e->getResponseBody()}\n";
self::fail('API call failed');
}
}
/**
* @group live-api
*
* @test
*/
public function getActivitiesFromRealAPI(): void
{
self::markTestIncomplete('Enable this test only when you want to make real API calls');
$feed = $this->client->feed('user', $this->testUserId);
try {
$response = $feed->getActivities(['limit' => 5]);
self::assertTrue($response->isSuccessful());
$data = $response->getData();
self::assertArrayHasKey('results', $data);
echo '✅ Retrieved ' . count($data['results']) . " activities\n";
} catch (StreamApiException $e) {
echo "❌ API Error: {$e->getMessage()} (Status: {$e->getStatusCode()})\n";
self::fail('API call failed');
}
}
}