-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
ace7c0f
commit 5c3f272
Showing
17 changed files
with
207 additions
and
74 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
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Concerns; | ||
|
||
class Value | ||
{ | ||
public const Text1English = 'The :attribute must be accepted.'; | ||
public const Text1French = 'Le champ :attribute doit être accepté.'; | ||
public const Text2English = 'The :attribute must be a date after :date.'; | ||
public const Text2French = 'Le champ :attribute doit être une date postérieure au :date.'; | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use LaravelLang\Translator\Integrations\Deepl; | ||
use LaravelLang\Translator\Integrations\GoogleFree; | ||
use LaravelLang\Translator\Integrations\Yandex; | ||
|
||
dataset('translators', fn () => [ | ||
Deepl::class => [Deepl::class], | ||
GoogleFree::class => [GoogleFree::class], | ||
Yandex::class => [Yandex::class], | ||
]); |
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use LaravelLang\Translator\Contracts\Translator; | ||
|
||
function translator(string $class): Translator | ||
{ | ||
return app($class); | ||
} |
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,45 +1 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Test Case | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The closure you provide to your test functions is always bound to a specific PHPUnit test | ||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may | ||
| need to change it using the "uses()" function to bind a different classes or traits. | ||
| | ||
*/ | ||
|
||
// uses(Tests\TestCase::class)->in('Feature'); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Expectations | ||
|-------------------------------------------------------------------------- | ||
| | ||
| When you're writing tests, you often need to check that values meet certain conditions. The | ||
| "expect()" function gives you access to a set of "expectations" methods that you can use | ||
| to assert different things. Of course, you may extend the Expectation API at any time. | ||
| | ||
*/ | ||
|
||
expect()->extend('toBeOne', function () { | ||
return $this->toBe(1); | ||
}); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Functions | ||
|-------------------------------------------------------------------------- | ||
| | ||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your | ||
| project that you don't want to repeat in every file. Here you can also expose helpers as | ||
| global functions to help you to reduce the number of lines of code in your test files. | ||
| | ||
*/ | ||
|
||
function something() | ||
{ | ||
// .. | ||
} |
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use LaravelLang\LocaleList\Locale; | ||
|
||
test('can be translatable', function (string $translator) { | ||
$translator = translator($translator); | ||
|
||
expect($translator->can('fr'))->toBeTrue(); | ||
expect($translator->can(Locale::French))->toBeTrue(); | ||
})->with('translators'); | ||
|
||
test('cannot be translatable', function (string $translator) { | ||
$translator = translator($translator); | ||
|
||
expect($translator->can('qwerty'))->toBeTrue(); | ||
})->with('translators'); |
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use LaravelLang\LocaleList\Locale; | ||
use LaravelLang\Translator\Facades\Translate; | ||
use Tests\Concerns\Value; | ||
|
||
test('translate', function () { | ||
expect(Translate::text(Value::Text1English, Locale::French))->toBe( | ||
Value::Text1French | ||
); | ||
}); | ||
|
||
test('cannot be translated', function () { | ||
expect(Translate::text(Value::Text1English, 'qwerty'))->toBe( | ||
Value::Text1English | ||
); | ||
}); | ||
|
||
test('via deepl', function () { | ||
expect(Translate::viaDeepl(Value::Text1English, Locale::French))->toBe( | ||
Value::Text1French | ||
); | ||
}); | ||
|
||
test('via google free', function () { | ||
expect(Translate::viaGoogleFree(Value::Text1English, Locale::French))->toBe( | ||
Value::Text1French | ||
); | ||
}); | ||
|
||
test('via yandex', function () { | ||
expect(Translate::viaYandex(Value::Text1English, Locale::French))->toBe( | ||
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use LaravelLang\LocaleList\Locale; | ||
use Tests\Concerns\Value; | ||
|
||
test('as string', function (string $translator) { | ||
$translator = translator($translator); | ||
|
||
expect( | ||
$translator->translate(Value::Text1English, Locale::French) | ||
)->toBe(Value::Text1French); | ||
})->with('translators'); | ||
|
||
test('as array without keys', function (string $translator) { | ||
$translator = translator($translator); | ||
|
||
expect($translator->translate([Value::Text1English, Value::Text2English], Locale::French))->toBe([ | ||
Value::Text1French, | ||
Value::Text2French, | ||
]); | ||
})->with('translators'); | ||
|
||
test('as array with keys', function (string $translator) { | ||
$translator = translator($translator); | ||
|
||
expect($translator->translate([ | ||
'foo' => Value::Text1English, | ||
'bar' => Value::Text2English, | ||
], Locale::French))->toBe([ | ||
'foo' => Value::Text1French, | ||
'bar' => Value::Text2French, | ||
]); | ||
})->with('translators'); | ||
|
||
test('as collection', function (string $translator) { | ||
$translator = translator($translator); | ||
|
||
expect($translator->translate(collect([ | ||
'foo' => Value::Text1English, | ||
'bar' => Value::Text2English, | ||
]), Locale::French))->toBe([ | ||
'foo' => Value::Text1French, | ||
'bar' => Value::Text2French, | ||
]); | ||
})->with('translators'); |
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 Tests\Concerns\Value; | ||
|
||
test('as string', function (string $translator) { | ||
$translator = translator($translator); | ||
|
||
expect( | ||
$translator->translate(Value::Text1English, 'qwerty') | ||
)->toBe(Value::Text1English); | ||
})->with('translators'); | ||
|
||
test('as array without keys', function (string $translator) { | ||
$translator = translator($translator); | ||
|
||
expect($translator->translate([Value::Text1English, Value::Text2English], 'qwerty'))->toBe([ | ||
Value::Text1English, | ||
Value::Text2English, | ||
]); | ||
})->with('translators'); | ||
|
||
test('as array with keys', function (string $translator) { | ||
$translator = translator($translator); | ||
|
||
expect($translator->translate([ | ||
'foo' => Value::Text1English, | ||
'bar' => Value::Text2English, | ||
], 'qwerty'))->toBe([ | ||
'foo' => Value::Text1English, | ||
'bar' => Value::Text2English, | ||
]); | ||
})->with('translators'); | ||
|
||
test('as collection', function (string $translator) { | ||
$translator = translator($translator); | ||
|
||
expect($translator->translate(collect([ | ||
'foo' => Value::Text1English, | ||
'bar' => Value::Text2English, | ||
]), 'qwerty'))->toBe([ | ||
'foo' => Value::Text1English, | ||
'bar' => Value::Text2English, | ||
]); | ||
})->with('translators'); |