-
Notifications
You must be signed in to change notification settings - Fork 16
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
fdffde0
commit e049315
Showing
8 changed files
with
99 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Larswiegers\LaravelTranslationsChecker\Console\Domain\Features; | ||
|
||
use Larswiegers\LaravelTranslationsChecker\Console\Domain\Line; | ||
|
||
class KeyExclusion | ||
{ | ||
|
||
/** | ||
* @var array|false|string[] | ||
*/ | ||
private static array $excludedKeys = []; | ||
|
||
public static function shouldExclude(Line $line): bool | ||
{ | ||
return in_array($line->getKey(), self::$excludedKeys); | ||
} | ||
|
||
/** | ||
* @param array<string> $options | ||
*/ | ||
public static function getExcludedKeys(array $options): void | ||
{ | ||
if ($options['excludedKeys'] === 'config') { | ||
self::$excludedKeys = (array) config('translations-checker.excluded_keys', []); | ||
} elseif ($options['excludedKeys']) { | ||
self::$excludedKeys = explode(',', $options['excludedKeys']); | ||
} elseif (empty((array) config('translations-checker.excluded_keys', []))) { | ||
self::$excludedKeys = (array) config('translations-checker.excluded_keys', []); | ||
} else { | ||
self::$excludedKeys = []; | ||
} | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
tests/Tests/Unit/Console/Commands/CheckExcludeKeysTest.php
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,38 @@ | ||
<?php | ||
|
||
namespace Console\Commands; | ||
|
||
use Tests\TestCase; | ||
|
||
class CheckExcludeKeysTest extends TestCase | ||
{ | ||
private string $exclusionDir = 'tests/resources/lang/excluded_keys'; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
} | ||
|
||
public function testItWorksFineIfKeyExistButIsExcluded() | ||
{ | ||
$command = $this->artisan('translations:check', [ | ||
'--directory' => $this->exclusionDir .'/excluded_but_existing', | ||
'--excludedKeys' => 'test.existing_key', | ||
]); | ||
|
||
$command->assertExitCode(0); | ||
} | ||
|
||
public function testItWorksFineIfKeyIsMissingButIsExcluded() | ||
{ | ||
config()->set('translations-checker.excluded_keys', null); | ||
|
||
|
||
$command = $this->artisan('translations:check', [ | ||
'--directory' => $this->exclusionDir .'/excluded_but_missing', | ||
'--excludedKeys' => 'existing_key', | ||
]); | ||
|
||
$command->assertExitCode(0); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/resources/lang/excluded_keys/excluded_but_existing/de/test.php
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,5 @@ | ||
<?php | ||
|
||
return [ | ||
'existing_key' => 'existing_key', | ||
]; |
5 changes: 5 additions & 0 deletions
5
tests/resources/lang/excluded_keys/excluded_but_existing/en/test.php
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,5 @@ | ||
<?php | ||
|
||
return [ | ||
'existing_key' => 'existing_key', | ||
]; |
5 changes: 5 additions & 0 deletions
5
tests/resources/lang/excluded_keys/excluded_but_missing/de/test.php
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,5 @@ | ||
<?php | ||
|
||
return [ | ||
'existing_key' => 'existing_key', | ||
]; |
4 changes: 4 additions & 0 deletions
4
tests/resources/lang/excluded_keys/excluded_but_missing/en/test.php
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,4 @@ | ||
<?php | ||
|
||
return [ | ||
]; |