-
Notifications
You must be signed in to change notification settings - Fork 3
Add artisan test, Laravel 9 compat for Collection::dot() #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jbboehr
wants to merge
5
commits into
coding-socks:main
Choose a base branch
from
jbboehr:topic/add-artisan-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c11cdf4
Add an artisan test via orchestra/testbench
jbboehr 041b59a
Also include lang in lang/*.json
jbboehr 8ed4f0f
Collection::dot() not available in Laravel 9, use Arr::dot()
jbboehr de7c88d
Prevent error when only a json language file is present
jbboehr 80e24d9
Use base TestCase
jbboehr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
47 changes: 47 additions & 0 deletions
47
tests/Console/Commands/FindMissingTranslationStringsTest.php
This file contains hidden or 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 | ||
|
|
||
| namespace CodingSocks\LostInTranslation\Tests\Console\Commands; | ||
|
|
||
| use CodingSocks\LostInTranslation\LostInTranslationServiceProvider; | ||
| use CodingSocks\LostInTranslation\Tests\TestCase; | ||
| use Illuminate\Config\Repository; | ||
| use Illuminate\Support\Facades\Artisan; | ||
|
|
||
| class FindMissingTranslationStringsTest extends TestCase | ||
nerg4l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| public function testBasicCommand(): void | ||
| { | ||
| $exit_code = $this | ||
| ->withoutMockingConsoleOutput() | ||
| ->artisan('lost-in-translation:find ja --no-progress --sorted'); | ||
|
|
||
| $output = Artisan::output(); | ||
|
|
||
| $this->assertSame("foobar\nglobal_key\nmessages.namespaced_key\n", $output); | ||
| $this->assertSame(0, $exit_code); | ||
| } | ||
|
|
||
| public function testMissingLocale(): void | ||
| { | ||
| $exit_code = $this | ||
| ->withoutMockingConsoleOutput() | ||
| ->artisan('lost-in-translation:find zh --no-progress --sorted'); | ||
|
|
||
| $output = Artisan::output(); | ||
|
|
||
| $this->assertSame("foobar\nglobal_key\nkey_in_both\nmessages.namespaced_key\n", $output); | ||
| $this->assertSame(0, $exit_code); | ||
| } | ||
|
|
||
| public function defineEnvironment($app) | ||
| { | ||
| $appPath = __DIR__ . '/../../application'; | ||
| $app->useLangPath($appPath . '/lang'); | ||
|
|
||
| tap($app['config'], static function (Repository $config) use ($appPath) { | ||
| $config->set('lost-in-translation.paths', [ | ||
| $appPath . '/resources/views' | ||
| ]); | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or 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,4 @@ | ||
| { | ||
| "global_key": "this is a global key", | ||
| "key_in_both": "both should have this key" | ||
| } |
This file contains hidden or 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,3 @@ | ||
| <?php return [ | ||
| 'namespaced_key' => 'this is a namespaced key', | ||
| ]; |
This file contains hidden or 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,4 @@ | ||
| { | ||
| "another_global_key": "this is another global key", | ||
| "key_in_both": "both should have this key" | ||
| } |
This file contains hidden or 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,3 @@ | ||
| <?php return [ | ||
| 'another_namespaced_key' => 'this is another namespaced key', | ||
| ]; |
This file contains hidden or 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 @@ | ||
| {{ __('foobar') }} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you let me know what this part does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah.
$this->translator->get('*')loads the global (non-namespaced) translations inlang/{$baseLocale}.json.I wonder if it might be better to use the found translations via scanning to build a list of groups/namespaces to load, that would support non-standard loaders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the point of the
lang/{lang}.json, that the key is already in the base language?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't think there's anything technically preventing you from using a json file for the base locale, but it doesn't seem like it is very common.