Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8ddac25

Browse files
committed
- Add ability to run integration-Test against both Free and Pro Api-Urls.
- probably fix testWithProxy, but i need a proxy to test it
1 parent f8ec91a commit 8ddac25

File tree

2 files changed

+47
-28
lines changed

2 files changed

+47
-28
lines changed

tests/integration/DeepLApiTest.php

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ class DeepLApiTest extends TestCase
2222
*/
2323
protected static $authKey = false;
2424

25+
/**
26+
* DeepL Auth Key.
27+
*
28+
* @var string
29+
*/
30+
protected static $apiHost;
2531
/**
2632
* Proxy URL
2733
* @var bool|string
@@ -42,15 +48,17 @@ public static function setUpBeforeClass(): void
4248
parent::setUpBeforeClass();
4349

4450
$authKey = getenv('DEEPL_AUTH_KEY');
51+
$apiHost = getenv('DEEPL_HOST') ?: 'api.deepl.com';
4552
$proxy = getenv('HTTP_PROXY');
4653
$proxyCredentials = getenv('HTTP_PROXY_CREDENTIALS');
4754

4855
if ($authKey === false) {
4956
return;
5057
}
5158

52-
self::$authKey = $authKey;
53-
self::$proxy = $proxy;
59+
self::$authKey = $authKey;
60+
self::$apiHost = $apiHost;
61+
self::$proxy = $proxy;
5462
self::$proxyCredentials = $proxyCredentials;
5563
}
5664

@@ -82,7 +90,7 @@ public function testTranslateSuccess()
8290
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
8391
}
8492

85-
$deepl = new DeepL(self::$authKey);
93+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
8694

8795
$germanText = 'Hallo Welt';
8896
$expectedText = 'Hello world';
@@ -101,7 +109,7 @@ public function testTranslateV1Success()
101109
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
102110
}
103111

104-
$deepl = new DeepL(self::$authKey, 1);
112+
$deepl = new DeepL(self::$authKey, 1, self::$apiHost);
105113

106114
$germanText = 'Hallo Welt';
107115
$expectedText = 'Hello world';
@@ -120,7 +128,7 @@ public function testTranslateWrongVersion()
120128
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
121129
}
122130
$germanText = 'Hallo Welt';
123-
$deepl = new DeepL(self::$authKey, 3);
131+
$deepl = new DeepL(self::$authKey, 3, self::$apiHost);
124132

125133
$this->expectException('\BabyMarkt\DeepL\DeepLException');
126134

@@ -136,7 +144,7 @@ public function testTranslateTagHandlingSuccess()
136144
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
137145
}
138146

139-
$deepl = new DeepL(self::$authKey);
147+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
140148

141149
$englishText = '<strong>text to translate</strong>';
142150
$expectedText = '<strong>zu übersetzender Text</strong>';
@@ -160,7 +168,7 @@ public function testTranslateIgnoreTagsSuccess()
160168
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
161169
}
162170

163-
$deepl = new DeepL(self::$authKey);
171+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
164172

165173
$englishText = '<strong>text to do not translate</strong><p>text to translate</p>';
166174
$expectedText = '<strong>text to do not translate</strong><p>zu übersetzender Text</p>';
@@ -185,7 +193,7 @@ public function testUsage()
185193
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
186194
}
187195

188-
$deepl = new DeepL(self::$authKey);
196+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
189197
$response = $deepl->usage();
190198

191199
self::assertArrayHasKey('character_count', $response);
@@ -201,7 +209,7 @@ public function testLanguages()
201209
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
202210
}
203211

204-
$deepl = new DeepL(self::$authKey);
212+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
205213
$response = $deepl->languages();
206214

207215
foreach ($response as $language) {
@@ -219,7 +227,7 @@ public function testLanguagesSource()
219227
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
220228
}
221229

222-
$deepl = new DeepL(self::$authKey);
230+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
223231
$response = $deepl->languages('source');
224232

225233
foreach ($response as $language) {
@@ -237,7 +245,7 @@ public function testLanguagesTarget()
237245
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
238246
}
239247

240-
$deepl = new DeepL(self::$authKey);
248+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
241249
$response = $deepl->languages('target');
242250

243251
foreach ($response as $language) {
@@ -255,7 +263,7 @@ public function testLanguagesFail()
255263
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
256264
}
257265

258-
$deepl = new DeepL(self::$authKey);
266+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
259267

260268
$this->expectException('\BabyMarkt\DeepL\DeepLException');
261269

@@ -271,7 +279,7 @@ public function testTranslateWithAllParams()
271279
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
272280
}
273281

274-
$deepl = new DeepL(self::$authKey);
282+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
275283

276284
$englishText = '<strong>text to do not translate</strong><p>please translate this text</p>';
277285
$expectedText = '<strong>text to do not translate</strong><p>bitte übersetzen Sie diesen Text</p>';
@@ -303,13 +311,15 @@ public function testWithProxy()
303311
}
304312

305313
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.
307315
$this->markTestSkipped('Proxy is not configured.');
308316
}
309317

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);
313323

314324
$englishText = 'please translate this text';
315325
$expectedText = 'Bitte übersetzen Sie diesen Text';
@@ -345,7 +355,7 @@ public function testTranslateFormality()
345355
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
346356
}
347357

348-
$deepl = new DeepL(self::$authKey);
358+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
349359

350360
$englishText = '<strong>text to do not translate</strong><p>please translate this text</p>';
351361
$expectedText = '<strong>Nicht zu übersetzender Text</strong><p>Bitte übersetze diesen Text</p>';
@@ -370,7 +380,7 @@ public function testTranslateWithHTML()
370380
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
371381
}
372382

373-
$deepl = new DeepL(self::$authKey);
383+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
374384
$textToTranslate = array(
375385
'Hello World<strong>This should stay the same</strong>',
376386
'Another Text<br> new line <p>this is a paragraph</p>'
@@ -383,7 +393,7 @@ public function testTranslateWithHTML()
383393
),
384394
array(
385395
'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> ",
387397
),
388398

389399
);
@@ -414,7 +424,7 @@ public function testTranslateWithNotSupportedSourceLanguage()
414424
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
415425
}
416426

417-
$deepl = new DeepL(self::$authKey);
427+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
418428

419429
$this->expectException('\BabyMarkt\DeepL\DeepLException');
420430
$deepl->translate('some txt', 'dk', 'de');
@@ -429,7 +439,7 @@ public function testTranslateWithNotSupportedDestinationLanguage()
429439
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
430440
}
431441

432-
$deepl = new DeepL(self::$authKey);
442+
$deepl = new DeepL(self::$authKey, 2, self::$apiHost);
433443

434444
$this->expectException('\BabyMarkt\DeepL\DeepLException');
435445
$deepl->translate('some txt', 'en', 'dk');

tests/integration/GlossaryTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ class GlossaryTest extends TestCase
1515
*/
1616
protected static $authKey = false;
1717

18+
/**
19+
* DeepL Auth Key.
20+
*
21+
* @var string
22+
*/
23+
protected static $apiHost;
24+
1825
/**
1926
* Setup DeepL Auth Key.
2027
*/
@@ -23,17 +30,19 @@ public static function setUpBeforeClass(): void
2330
parent::setUpBeforeClass();
2431

2532
$authKey = getenv('DEEPL_AUTH_KEY');
33+
$apiHost = getenv('DEEPL_HOST') ?: 'api.deepl.com';
2634

2735
if ($authKey === false) {
2836
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
2937
}
3038

3139
self::$authKey = $authKey;
40+
self::$apiHost = $apiHost;
3241
}
3342

3443
public static function tearDownAfterClass(): void
3544
{
36-
$glossaryAPI = new Glossary(self::$authKey);
45+
$glossaryAPI = new Glossary(self::$authKey, 2, self::$apiHost);
3746

3847
$glossariesResponse = $glossaryAPI->listGlossaries();
3948

@@ -62,7 +71,7 @@ public function testCreateGlossary()
6271
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
6372
}
6473

65-
$deepl = new Glossary(self::$authKey);
74+
$deepl = new Glossary(self::$authKey, 2, self::$apiHost);
6675
$entries = ['Hallo' => 'Hello'];
6776
$glossary = $deepl->createGlossary('test', $entries, 'de', 'en');
6877

@@ -80,7 +89,7 @@ public function testListGlossaries()
8089
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
8190
}
8291

83-
$deepl = new Glossary(self::$authKey);
92+
$deepl = new Glossary(self::$authKey, 2, self::$apiHost);
8493
$glossaries = $deepl->listGlossaries();
8594

8695
self::assertNotEmpty($glossaries['glossaries']);
@@ -97,7 +106,7 @@ public function testGlossaryInformation($glossaryId)
97106
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
98107
}
99108

100-
$deepl = new Glossary(self::$authKey);
109+
$deepl = new Glossary(self::$authKey, 2, self::$apiHost);
101110
$information = $deepl->glossaryInformation($glossaryId);
102111

103112
self::assertArrayHasKey('glossary_id', $information);
@@ -114,7 +123,7 @@ public function testGlossaryEntries($glossaryId)
114123
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
115124
}
116125

117-
$deepl = new Glossary(self::$authKey);
126+
$deepl = new Glossary(self::$authKey, 2, self::$apiHost);
118127
$entries = $deepl->glossaryEntries($glossaryId);
119128

120129
self::assertEquals($entries, ['Hallo' => 'Hello']);
@@ -131,7 +140,7 @@ public function testDeleteGlossary($glossaryId)
131140
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
132141
}
133142

134-
$deepl = new Glossary(self::$authKey);
143+
$deepl = new Glossary(self::$authKey, 2, self::$apiHost);
135144
$response = $deepl->deleteGlossary($glossaryId);
136145

137146
self::assertNull($response);

0 commit comments

Comments
 (0)