-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-all-methods.php
More file actions
114 lines (97 loc) · 3.18 KB
/
test-all-methods.php
File metadata and controls
114 lines (97 loc) · 3.18 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
108
109
110
111
112
113
114
<?php
/**
* Test script for all API methods in the PHP SDK
*
* This script tests all available methods in the PHP SDK with real API calls
* to ensure they work correctly with our fixed implementation.
*
* Usage: php test-all-methods.php <api_key>
*/
require "vendor/autoload.php";
use LingoDotDev\Sdk\LingoDotDevEngine;
use GuzzleHttp\Exception\RequestException;
$apiKey = $argv[1] ?? null;
if (!$apiKey) {
echo "Error: API key is required. Pass it as a command-line argument.\n";
exit(1);
}
$engine = new LingoDotDevEngine([
"apiKey" => $apiKey,
]);
function runTest($name, $callback) {
echo "\n=== Testing $name ===\n";
try {
$result = $callback();
echo "✅ Test passed!\n";
echo "Result: " . json_encode($result, JSON_PRETTY_PRINT) . "\n";
return true;
} catch (\Exception $e) {
echo "❌ Test failed!\n";
echo "Error: " . $e->getMessage() . "\n";
if ($e instanceof RequestException && $e->hasResponse()) {
$response = $e->getResponse();
echo "Status Code: " . $response->getStatusCode() . "\n";
echo "Response Body: " . $response->getBody() . "\n";
}
return false;
}
}
runTest("localizeText", function() use ($engine) {
return $engine->localizeText("Hello, this is my first localization with Lingo.dev!", [
"sourceLocale" => "en",
"targetLocale" => "es",
]);
});
runTest("localizeObject", function() use ($engine) {
return $engine->localizeObject([
"greeting" => "Hello",
"farewell" => "Goodbye",
"messages" => [
"welcome" => "Welcome to our service",
"thanks" => "Thank you for your business"
]
], [
"sourceLocale" => "en",
"targetLocale" => "fr",
]);
});
runTest("localizeChat", function() use ($engine) {
return $engine->localizeChat([
["name" => "Alice", "text" => "Hello, how are you?"],
["name" => "Bob", "text" => "I am fine, thank you!"],
["name" => "Alice", "text" => "What are you doing today?"]
], [
"sourceLocale" => "en",
"targetLocale" => "de",
]);
});
runTest("batchLocalizeText", function() use ($engine) {
return $engine->batchLocalizeText("Hello, world!", [
"sourceLocale" => "en",
"targetLocales" => ["es", "fr", "de"],
]);
});
runTest("recognizeLocale", function() use ($engine) {
return $engine->recognizeLocale("Bonjour le monde");
});
runTest("Progress Callback", function() use ($engine) {
$progressCalled = false;
$progressValue = 0;
$result = $engine->localizeText("Hello, this is a test with progress callback!", [
"sourceLocale" => "en",
"targetLocale" => "es",
], function ($progress) use (&$progressCalled, &$progressValue) {
$progressCalled = true;
$progressValue = $progress;
echo "Progress: $progress%\n";
});
if (!$progressCalled) {
throw new \Exception("Progress callback was not called");
}
return [
"result" => $result,
"progressCalled" => $progressCalled,
"progressValue" => $progressValue
];
});
echo "\n=== All tests completed ===\n";