-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPingTest.php
More file actions
104 lines (85 loc) · 3.38 KB
/
PingTest.php
File metadata and controls
104 lines (85 loc) · 3.38 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 ExportComments\Tests;
use PHPUnit\Framework\TestCase;
use ExportComments\Client;
use ExportComments\ExportCommentsException;
use ExportComments\ExportCommentsResponse;
class PingTest extends TestCase
{
private $client;
private $apiToken;
protected function setUp(): void
{
parent::setUp();
// Use environment variable for API token in tests
$this->client = new Client($this->apiToken);
$this->apiToken = $_ENV['EXPORTCOMMENTS_API_TOKEN'] ?? 'test_token_123';
}
protected function tearDown(): void
{
$this->client = null;
parent::tearDown();
}
public function testPingMethodExists()
{
$this->assertTrue(method_exists($this->client, 'ping'));
}
public function testPingEndpoint()
{
$this->markTestSkipped('Requires valid API token for actual API calls');
try {
$response = $this->client->ping();
$this->assertInstanceOf(ExportCommentsResponse::class, $response);
$this->assertArrayHasKey('message', $response->result);
$this->assertEquals('pong', $response->result['message']);
} catch (ExportCommentsException $e) {
// If we get an authentication error, that means the endpoint is reachable
$this->assertStringContainsString('auth', strtolower($e->getMessage()));
}
}
public function testClientInitialization()
{
$client = new Client($this->apiToken);
$this->assertInstanceOf(Client::class, $client);
}
public function testClientWithCustomEndpoint()
{
$customEndpoint = 'https://api.example.com/v3';
$client = new Client($this->apiToken, $customEndpoint);
$this->assertInstanceOf(Client::class, $client);
}
/**
* Test basic connectivity by trying to list exports (which would verify API connection)
*/
public function testApiConnectivity()
{
$this->markTestSkipped('Requires valid API token for actual API calls');
try {
$response = $this->client->exports->listExports(1, 1);
$this->assertNotNull($response);
} catch (ExportCommentsException $e) {
// If we get an authentication error, that means the endpoint is reachable
$this->assertStringContainsString('auth', strtolower($e->getMessage()));
}
}
public function testPingWithInvalidToken()
{
$this->markTestSkipped('Requires actual API call to test authentication');
$invalidClient = new Client('invalid_token');
try {
$response = $invalidClient->ping();
// Ping might not require authentication, so we check the response
$this->assertInstanceOf(ExportCommentsResponse::class, $response);
} catch (ExportCommentsException $e) {
// If authentication is required, we should get an auth error
$this->assertStringContainsString('auth', strtolower($e->getMessage()));
}
}
public function testNetworkErrorHandling()
{
$invalidEndpointClient = new Client($this->apiToken, 'https://invalid-endpoint.example.com/api/v3');
$this->markTestSkipped('Requires network call to test error handling');
$this->expectException(ExportCommentsException::class);
$invalidEndpointClient->ping();
}
}