-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c3f272
commit d778961
Showing
13 changed files
with
95 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Concerns; | ||
namespace Tests\Constants; | ||
|
||
class Value | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use DeepL\Translator as DeeplTranslator; | ||
use LaravelLang\Translator\Integrations\Deepl; | ||
use LaravelLang\Translator\Integrations\Google; | ||
use LaravelLang\Translator\Integrations\Yandex; | ||
use LaravelLang\Translator\Requests\YandexCloud; | ||
use Stichoza\GoogleTranslate\GoogleTranslate; | ||
use Tests\Constants\Value; | ||
|
||
function mockTranslator(string $translator, string $integration, array $methods = []): void | ||
{ | ||
$service = mock($integration); | ||
|
||
foreach ($methods as $key => $value) { | ||
is_string($key) | ||
? $service->shouldReceive($key)->andReturn($value) | ||
: $service->shouldReceive($value)->andReturnSelf(); | ||
} | ||
|
||
app()->forgetInstance($translator); | ||
app()->singleton($translator, fn () => new $translator($service)); | ||
} | ||
|
||
function mockTranslators( | ||
array|string|null $deepl = null, | ||
array|string|null $google = null, | ||
array|string|null $yandex = null, | ||
): void { | ||
mockTranslator(Deepl::class, DeeplTranslator::class, [ | ||
'translateText' => $deepl ?? Value::Text1French, | ||
]); | ||
|
||
mockTranslator(Google::class, GoogleTranslate::class, [ | ||
'translate' => $google ?? Value::Text1French, | ||
'preserveParameters', | ||
'setSource', | ||
'setTarget', | ||
]); | ||
|
||
mockTranslator(Yandex::class, YandexCloud::class, [ | ||
'translate' => $yandex ?? [Value::Text1French], | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
<?php | ||
|
||
uses(Tests\TestCase::class) | ||
->compact() | ||
->beforeEach(fn () => mockTranslators()) | ||
->in(__DIR__); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters