@@ -22,6 +22,12 @@ class DeepLApiTest extends TestCase
22
22
*/
23
23
protected static $ authKey = false ;
24
24
25
+ /**
26
+ * DeepL Auth Key.
27
+ *
28
+ * @var string
29
+ */
30
+ protected static $ apiHost ;
25
31
/**
26
32
* Proxy URL
27
33
* @var bool|string
@@ -42,15 +48,17 @@ public static function setUpBeforeClass(): void
42
48
parent ::setUpBeforeClass ();
43
49
44
50
$ authKey = getenv ('DEEPL_AUTH_KEY ' );
51
+ $ apiHost = getenv ('DEEPL_HOST ' ) ?: 'api.deepl.com ' ;
45
52
$ proxy = getenv ('HTTP_PROXY ' );
46
53
$ proxyCredentials = getenv ('HTTP_PROXY_CREDENTIALS ' );
47
54
48
55
if ($ authKey === false ) {
49
56
return ;
50
57
}
51
58
52
- self ::$ authKey = $ authKey ;
53
- self ::$ proxy = $ proxy ;
59
+ self ::$ authKey = $ authKey ;
60
+ self ::$ apiHost = $ apiHost ;
61
+ self ::$ proxy = $ proxy ;
54
62
self ::$ proxyCredentials = $ proxyCredentials ;
55
63
}
56
64
@@ -82,7 +90,7 @@ public function testTranslateSuccess()
82
90
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
83
91
}
84
92
85
- $ deepl = new DeepL (self ::$ authKey );
93
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
86
94
87
95
$ germanText = 'Hallo Welt ' ;
88
96
$ expectedText = 'Hello world ' ;
@@ -101,7 +109,7 @@ public function testTranslateV1Success()
101
109
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
102
110
}
103
111
104
- $ deepl = new DeepL (self ::$ authKey , 1 );
112
+ $ deepl = new DeepL (self ::$ authKey , 1 , self :: $ apiHost );
105
113
106
114
$ germanText = 'Hallo Welt ' ;
107
115
$ expectedText = 'Hello world ' ;
@@ -120,7 +128,7 @@ public function testTranslateWrongVersion()
120
128
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
121
129
}
122
130
$ germanText = 'Hallo Welt ' ;
123
- $ deepl = new DeepL (self ::$ authKey , 3 );
131
+ $ deepl = new DeepL (self ::$ authKey , 3 , self :: $ apiHost );
124
132
125
133
$ this ->expectException ('\BabyMarkt\DeepL\DeepLException ' );
126
134
@@ -136,7 +144,7 @@ public function testTranslateTagHandlingSuccess()
136
144
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
137
145
}
138
146
139
- $ deepl = new DeepL (self ::$ authKey );
147
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
140
148
141
149
$ englishText = '<strong>text to translate</strong> ' ;
142
150
$ expectedText = '<strong>zu übersetzender Text</strong> ' ;
@@ -160,7 +168,7 @@ public function testTranslateIgnoreTagsSuccess()
160
168
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
161
169
}
162
170
163
- $ deepl = new DeepL (self ::$ authKey );
171
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
164
172
165
173
$ englishText = '<strong>text to do not translate</strong><p>text to translate</p> ' ;
166
174
$ expectedText = '<strong>text to do not translate</strong><p>zu übersetzender Text</p> ' ;
@@ -185,7 +193,7 @@ public function testUsage()
185
193
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
186
194
}
187
195
188
- $ deepl = new DeepL (self ::$ authKey );
196
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
189
197
$ response = $ deepl ->usage ();
190
198
191
199
self ::assertArrayHasKey ('character_count ' , $ response );
@@ -201,7 +209,7 @@ public function testLanguages()
201
209
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
202
210
}
203
211
204
- $ deepl = new DeepL (self ::$ authKey );
212
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
205
213
$ response = $ deepl ->languages ();
206
214
207
215
foreach ($ response as $ language ) {
@@ -219,7 +227,7 @@ public function testLanguagesSource()
219
227
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
220
228
}
221
229
222
- $ deepl = new DeepL (self ::$ authKey );
230
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
223
231
$ response = $ deepl ->languages ('source ' );
224
232
225
233
foreach ($ response as $ language ) {
@@ -237,7 +245,7 @@ public function testLanguagesTarget()
237
245
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
238
246
}
239
247
240
- $ deepl = new DeepL (self ::$ authKey );
248
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
241
249
$ response = $ deepl ->languages ('target ' );
242
250
243
251
foreach ($ response as $ language ) {
@@ -255,7 +263,7 @@ public function testLanguagesFail()
255
263
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
256
264
}
257
265
258
- $ deepl = new DeepL (self ::$ authKey );
266
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
259
267
260
268
$ this ->expectException ('\BabyMarkt\DeepL\DeepLException ' );
261
269
@@ -271,7 +279,7 @@ public function testTranslateWithAllParams()
271
279
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
272
280
}
273
281
274
- $ deepl = new DeepL (self ::$ authKey );
282
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
275
283
276
284
$ englishText = '<strong>text to do not translate</strong><p>please translate this text</p> ' ;
277
285
$ expectedText = '<strong>text to do not translate</strong><p>bitte übersetzen Sie diesen Text</p> ' ;
@@ -303,13 +311,15 @@ public function testWithProxy()
303
311
}
304
312
305
313
if (self ::$ proxy === false ) {
306
- // The test would succeed with $proxy === false but it wouln 't mean anything.
314
+ // The test would succeed with $proxy === false but it wouldn 't mean anything.
307
315
$ this ->markTestSkipped ('Proxy is not configured. ' );
308
316
}
309
317
310
- $ deepl = new DeepL (self ::$ authKey );
311
- $ deepl ->setProxy (self ::$ proxy );
312
- $ deepl ->setProxyCredentials (self ::$ proxyCredentials );
318
+ $ client = new Client (self ::$ authKey , 2 , self ::$ apiHost );
319
+ $ client ->setProxy (self ::$ proxy );
320
+ $ client ->setProxyCredentials (self ::$ proxyCredentials );
321
+
322
+ $ deepl = new DeepL (self ::$ authKey , 2 , self ::$ apiHost , $ client );
313
323
314
324
$ englishText = 'please translate this text ' ;
315
325
$ expectedText = 'Bitte übersetzen Sie diesen Text ' ;
@@ -345,7 +355,7 @@ public function testTranslateFormality()
345
355
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
346
356
}
347
357
348
- $ deepl = new DeepL (self ::$ authKey );
358
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
349
359
350
360
$ englishText = '<strong>text to do not translate</strong><p>please translate this text</p> ' ;
351
361
$ expectedText = '<strong>Nicht zu übersetzender Text</strong><p>Bitte übersetze diesen Text</p> ' ;
@@ -370,7 +380,7 @@ public function testTranslateWithHTML()
370
380
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
371
381
}
372
382
373
- $ deepl = new DeepL (self ::$ authKey );
383
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
374
384
$ textToTranslate = array (
375
385
'Hello World<strong>This should stay the same</strong> ' ,
376
386
'Another Text<br> new line <p>this is a paragraph</p> '
@@ -383,7 +393,7 @@ public function testTranslateWithHTML()
383
393
),
384
394
array (
385
395
'detected_source_language ' => "EN " ,
386
- 'text ' => "Eine weitere<br>neue Textzeile <p>, die ein Absatz ist </p></br> " ,
396
+ 'text ' => "Eine weitere<br>neue Textzeile <p>, dies ist ein Absatz</p></br> " ,
387
397
),
388
398
389
399
);
@@ -414,7 +424,7 @@ public function testTranslateWithNotSupportedSourceLanguage()
414
424
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
415
425
}
416
426
417
- $ deepl = new DeepL (self ::$ authKey );
427
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
418
428
419
429
$ this ->expectException ('\BabyMarkt\DeepL\DeepLException ' );
420
430
$ deepl ->translate ('some txt ' , 'dk ' , 'de ' );
@@ -429,7 +439,7 @@ public function testTranslateWithNotSupportedDestinationLanguage()
429
439
self ::markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
430
440
}
431
441
432
- $ deepl = new DeepL (self ::$ authKey );
442
+ $ deepl = new DeepL (self ::$ authKey, 2 , self :: $ apiHost );
433
443
434
444
$ this ->expectException ('\BabyMarkt\DeepL\DeepLException ' );
435
445
$ deepl ->translate ('some txt ' , 'en ' , 'dk ' );
0 commit comments