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

Commit 2ed495f

Browse files
author
sathielemann
committed
Remove unnecessary condition in buildBaseUrl
1 parent b8d701d commit 2ed495f

File tree

5 files changed

+125
-92
lines changed

5 files changed

+125
-92
lines changed

src/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,16 @@ public function setTimeout($timeout)
183183
}
184184

185185
/**
186-
* Creates the Base-Url which all of the 3 API-resources have in common.
186+
* Creates the Base-Url which all the API-resources have in common.
187187
*
188188
* @param string $resource
189189
* @param bool $withAuth
190190
*
191191
* @return string
192192
*/
193-
public function buildBaseUrl(string $resource = 'translate', bool $withAuth = true): string
193+
public function buildBaseUrl(string $resource = 'translate'): string
194194
{
195-
if ($withAuth) {
195+
if ($this->authKey) {
196196
return sprintf(
197197
self::API_URL_BASE,
198198
self::API_URL_SCHEMA,

src/ClientInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function setTimeout($timeout);
4949
*
5050
* @return string
5151
*/
52-
public function buildBaseUrl(string $resource = 'translate', bool $withAuth = true): string;
52+
public function buildBaseUrl(string $resource = 'translate'): string;
5353

5454
/**
5555
* @param array $paramsArray

src/Glossary.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function createGlossary(
7373
'entries_format' => $entriesFormat
7474
];
7575

76-
$url = $this->client->buildBaseUrl(self::API_URL_RESOURCE_GLOSSARIES, false);
76+
$url = $this->client->buildBaseUrl(self::API_URL_RESOURCE_GLOSSARIES);
7777
$body = $this->client->buildQuery($paramsArray);
7878

7979
return $this->client->request($url, $body);
@@ -88,7 +88,7 @@ public function createGlossary(
8888
*/
8989
public function deleteGlossary(string $glossaryId)
9090
{
91-
$url = $this->client->buildBaseUrl(self::API_URL_RESOURCE_GLOSSARIES, false);
91+
$url = $this->client->buildBaseUrl(self::API_URL_RESOURCE_GLOSSARIES);
9292
$url .= "/$glossaryId";
9393

9494
return $this->client->request($url, '', 'DELETE');
@@ -103,7 +103,7 @@ public function deleteGlossary(string $glossaryId)
103103
*/
104104
public function glossaryInformation(string $glossaryId)
105105
{
106-
$url = $this->client->buildBaseUrl(self::API_URL_RESOURCE_GLOSSARIES, false);
106+
$url = $this->client->buildBaseUrl(self::API_URL_RESOURCE_GLOSSARIES);
107107
$url .= "/$glossaryId";
108108

109109
return $this->client->request($url, '', 'GET');
@@ -118,7 +118,7 @@ public function glossaryInformation(string $glossaryId)
118118
*/
119119
public function glossaryEntries(string $glossaryId)
120120
{
121-
$url = $this->client->buildBaseUrl(self::API_URL_RESOURCE_GLOSSARIES, false);
121+
$url = $this->client->buildBaseUrl(self::API_URL_RESOURCE_GLOSSARIES);
122122
$url .= "/$glossaryId/entries";
123123

124124
$response = $this->client->request($url, '', 'GET');

tests/integration/DeepLApiTest.php

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -434,88 +434,4 @@ public function testTranslateWithNotSupportedDestinationLanguage()
434434
$this->expectException('\BabyMarkt\DeepL\DeepLException');
435435
$deepl->translate('some txt', 'en', 'dk');
436436
}
437-
438-
/**
439-
* Test Glossary creation
440-
*/
441-
public function testCreateGlossary()
442-
{
443-
if (self::$authKey === false) {
444-
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
445-
}
446-
447-
$deepl = new DeepL(self::$authKey);
448-
$entries = ['Hallo' => 'Hello'];
449-
$glossary = $deepl->createGlossary('test', $entries, 'de', 'en');
450-
451-
self::assertArrayHasKey('glossary_id', $glossary);
452-
453-
return $glossary['glossary_id'];
454-
}
455-
456-
/**
457-
* Test Glossary listing
458-
*/
459-
public function testListGlossaries()
460-
{
461-
if (self::$authKey === false) {
462-
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
463-
}
464-
465-
$deepl = new DeepL(self::$authKey);
466-
$glossaries = $deepl->listGlossaries();
467-
468-
self::assertNotEmpty($glossaries['glossaries']);
469-
}
470-
471-
/**
472-
* Test listing information about a glossary
473-
*
474-
* @depends testCreateGlossary
475-
*/
476-
public function testGlossaryInformation($glossaryId)
477-
{
478-
if (self::$authKey === false) {
479-
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
480-
}
481-
482-
$deepl = new DeepL(self::$authKey);
483-
$information = $deepl->glossaryInformation($glossaryId);
484-
485-
self::assertArrayHasKey('glossary_id', $information);
486-
}
487-
488-
/**
489-
* Test listing entries in a glossary
490-
*
491-
* @depends testCreateGlossary
492-
*/
493-
public function testGlossaryEntries($glossaryId)
494-
{
495-
if (self::$authKey === false) {
496-
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
497-
}
498-
499-
$deepl = new DeepL(self::$authKey);
500-
$entries = $deepl->glossaryEntries($glossaryId);
501-
502-
self::assertEquals($entries, ['Hallo' => 'Hello']);
503-
}
504-
505-
/**
506-
* Test deleting a glossary
507-
*
508-
* @depends testCreateGlossary
509-
*/
510-
public function testDeleteGlossary($glossaryId)
511-
{
512-
if (self::$authKey === false) {
513-
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
514-
}
515-
516-
$deepl = new DeepL(self::$authKey);
517-
$response = $deepl->deleteGlossary($glossaryId);
518-
519-
self::assertNull($response);
520-
}
521437
}

tests/integration/GlossaryTest.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
namespace BabyMarkt\DeepL\integration;
4+
5+
use BabyMarkt\DeepL\DeepL;
6+
use BabyMarkt\DeepL\Glossary;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class GlossaryTest extends TestCase
10+
{
11+
/**
12+
* DeepL Auth Key.
13+
*
14+
* @var bool|string
15+
*/
16+
protected static $authKey = false;
17+
18+
/**
19+
* Setup DeepL Auth Key.
20+
*/
21+
public static function setUpBeforeClass(): void
22+
{
23+
parent::setUpBeforeClass();
24+
25+
$authKey = getenv('DEEPL_AUTH_KEY');
26+
27+
if ($authKey === false) {
28+
return;
29+
}
30+
31+
self::$authKey = $authKey;
32+
}
33+
34+
/**
35+
* Test Glossary creation
36+
*/
37+
public function testCreateGlossary()
38+
{
39+
if (self::$authKey === false) {
40+
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
41+
}
42+
43+
$deepl = new Glossary(self::$authKey);
44+
$entries = ['Hallo' => 'Hello'];
45+
$glossary = $deepl->createGlossary('test', $entries, 'de', 'en');
46+
47+
self::assertArrayHasKey('glossary_id', $glossary);
48+
49+
return $glossary['glossary_id'];
50+
}
51+
52+
/**
53+
* Test Glossary listing
54+
*/
55+
public function testListGlossaries()
56+
{
57+
if (self::$authKey === false) {
58+
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
59+
}
60+
61+
$deepl = new Glossary(self::$authKey);
62+
$glossaries = $deepl->listGlossaries();
63+
64+
self::assertNotEmpty($glossaries['glossaries']);
65+
}
66+
67+
/**
68+
* Test listing information about a glossary
69+
*
70+
* @depends testCreateGlossary
71+
*/
72+
public function testGlossaryInformation($glossaryId)
73+
{
74+
if (self::$authKey === false) {
75+
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
76+
}
77+
78+
$deepl = new Glossary(self::$authKey);
79+
$information = $deepl->glossaryInformation($glossaryId);
80+
81+
self::assertArrayHasKey('glossary_id', $information);
82+
}
83+
84+
/**
85+
* Test listing entries in a glossary
86+
*
87+
* @depends testCreateGlossary
88+
*/
89+
public function testGlossaryEntries($glossaryId)
90+
{
91+
if (self::$authKey === false) {
92+
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
93+
}
94+
95+
$deepl = new Glossary(self::$authKey);
96+
$entries = $deepl->glossaryEntries($glossaryId);
97+
98+
self::assertEquals($entries, ['Hallo' => 'Hello']);
99+
}
100+
101+
/**
102+
* Test deleting a glossary
103+
*
104+
* @depends testCreateGlossary
105+
*/
106+
public function testDeleteGlossary($glossaryId)
107+
{
108+
if (self::$authKey === false) {
109+
self::markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
110+
}
111+
112+
$deepl = new Glossary(self::$authKey);
113+
$response = $deepl->deleteGlossary($glossaryId);
114+
115+
self::assertNull($response);
116+
}
117+
}

0 commit comments

Comments
 (0)