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

Commit 937c77d

Browse files
author
sathielemann
committed
Fix wrong expectations in tests and switch authentication to DeepL header based authentication
1 parent 7ad203c commit 937c77d

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

src/Client.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public function __construct($authKey, $apiVersion = 2, $host = 'api.deepl.com')
8383
$this->apiVersion = $apiVersion;
8484
$this->host = $host;
8585
$this->curl = curl_init();
86+
87+
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
8688
}
8789

8890
/**
@@ -117,9 +119,6 @@ public function request($url, $body = '', $method = 'POST')
117119
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $body);
118120
break;
119121
case 'GET':
120-
curl_setopt($this->curl, CURLOPT_POST, false);
121-
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'GET');
122-
break;
123122
default:
124123
break;
125124
}
@@ -158,7 +157,6 @@ public function request($url, $body = '', $method = 'POST')
158157
*/
159158
public function setProxy($proxy)
160159
{
161-
162160
$this->proxy = $proxy;
163161
}
164162

@@ -192,16 +190,16 @@ public function setTimeout($timeout)
192190
*/
193191
public function buildBaseUrl(string $resource = 'translate'): string
194192
{
195-
if (!empty($this->authKey)) {
196-
return sprintf(
197-
self::API_URL_BASE,
198-
self::API_URL_SCHEMA,
199-
$this->host,
200-
$this->apiVersion,
201-
$resource,
202-
$this->authKey
203-
);
204-
}
193+
// if (!empty($this->authKey)) {
194+
// return sprintf(
195+
// self::API_URL_BASE,
196+
// self::API_URL_SCHEMA,
197+
// $this->host,
198+
// $this->apiVersion,
199+
// $resource,
200+
// $this->authKey
201+
// );
202+
// }
205203

206204
return sprintf(
207205
self::API_URL_BASE_NO_AUTH,

src/Glossary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct($authKey, $apiVersion = 2, $host = 'api.deepl.com',
3939
*/
4040
public function listGlossaries()
4141
{
42-
return $this->client->request($this->client->buildBaseUrl(self::API_URL_RESOURCE_GLOSSARIES));
42+
return $this->client->request($this->client->buildBaseUrl(self::API_URL_RESOURCE_GLOSSARIES), '', 'GET');
4343
}
4444

4545
/**

tests/integration/DeepLApiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public function testTranslateWithHTML()
383383
),
384384
array(
385385
'detected_source_language' => "EN",
386-
'text' => "Ein weiterer Text<br>neue Zeile <p>dies ist ein Absatz</p></br> ",
386+
'text' => "Eine weitere<br>neue Textzeile <p>, die ein Absatz ist</p></br> ",
387387
),
388388

389389
);

tests/integration/GlossaryTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ public static function setUpBeforeClass(): void
3131
self::$authKey = $authKey;
3232
}
3333

34+
public static function tearDownAfterClass(): void
35+
{
36+
$glossaryAPI = new Glossary(self::$authKey);
37+
38+
$glossariesResponse = $glossaryAPI->listGlossaries();
39+
40+
foreach ($glossariesResponse['glossaries'] as $glossary) {
41+
$glossaryAPI->deleteGlossary($glossary['glossary_id']);
42+
}
43+
}
44+
3445
/**
3546
* Test Glossary creation
3647
*/

tests/unit/ClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function testBuildBaseUrlHost()
190190
{
191191
$authKey = '123456';
192192
$host = 'myownhost.dev';
193-
$expectedUrl = 'https://' . $host . '/v2/translate?auth_key=' . $authKey;
193+
$expectedUrl = 'https://' . $host . '/v2/translate';
194194
$testSubject = new Client($authKey, 2, $host);
195195
$result = $testSubject->buildBaseUrl();
196196

@@ -203,7 +203,7 @@ public function testBuildBaseUrlHost()
203203
public function testBuildBaseUrl()
204204
{
205205
$authKey = '123456';
206-
$expectedUrl = 'https://api.deepl.com/v2/translate?auth_key=' . $authKey;
206+
$expectedUrl = 'https://api.deepl.com/v2/translate';
207207
$testSubject = new Client($authKey);
208208
$result = $testSubject->buildBaseUrl();
209209

0 commit comments

Comments
 (0)