From aa6b6ce881abf4056635d4e0bf3b39e162130cdd Mon Sep 17 00:00:00 2001 From: Constantin Druc Date: Sat, 20 Nov 2021 20:28:45 +0200 Subject: [PATCH] Prepare release --- .github/workflows/php-cs-fixer.yml | 23 ++++++ .github/workflows/run-tests.yml | 37 ++++++++++ .gitignore | 2 +- .php-cs-fixer.dist.php | 39 ++++++++++ README.md | 1 + composer.json | 107 ++++++++++++++-------------- config/langscanner.php | 10 --- src/CachedFileTranslations.php | 35 +++++++++ src/Commands/LangscannerCommand.php | 60 ++++++++-------- src/Contracts/FileTranslations.php | 14 ++++ src/FileTranslations.php | 51 +++++++++---- src/LangscannerServiceProvider.php | 1 - src/Languages.php | 31 ++++---- src/MissingTranslations.php | 32 +++++++++ src/RequiredTranslations.php | 70 +++++++++--------- tests/FileTranslationsTest.php | 64 ++++++++++++++--- tests/LanguagesTest.php | 15 ++-- tests/MissingTranslationsTest.php | 35 +++++++++ tests/RequiredTranslationsTest.php | 10 +-- tests/fixtures/lang/en.json | 4 -- tests/fixtures/lang/es.json | 5 -- 21 files changed, 455 insertions(+), 191 deletions(-) create mode 100644 .github/workflows/php-cs-fixer.yml create mode 100644 .github/workflows/run-tests.yml create mode 100644 .php-cs-fixer.dist.php create mode 100644 src/CachedFileTranslations.php create mode 100644 src/Contracts/FileTranslations.php create mode 100644 src/MissingTranslations.php create mode 100644 tests/MissingTranslationsTest.php delete mode 100644 tests/fixtures/lang/en.json delete mode 100644 tests/fixtures/lang/es.json diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 0000000..a00a754 --- /dev/null +++ b/.github/workflows/php-cs-fixer.yml @@ -0,0 +1,23 @@ +name: Check & fix styling + +on: [ push ] + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Run PHP CS Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --config=.php-cs-fixer.dist.php --allow-risky=yes + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Fix styling diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..7d2d724 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,37 @@ +name: Tests + +on: [ push, pull_request ] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ ubuntu-latest, windows-latest ] + php: [ 7.4, 8.0 ] + stability: [ prefer-lowest, prefer-stable ] + + name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: Execute tests + run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index 75da92f..adc6804 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,5 @@ coverage docs phpunit.xml psalm.xml -testbench.yaml vendor +.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..4a9ed8f --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,39 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->name('*.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +return (new PhpCsFixer\Config()) + ->setRules([ + '@PSR12' => true, + 'array_syntax' => ['syntax' => 'short'], + 'ordered_imports' => ['sort_algorithm' => 'alpha'], + 'no_unused_imports' => true, + 'not_operator_with_successor_space' => false, + 'trailing_comma_in_multiline' => true, + 'phpdoc_scalar' => true, + 'unary_operator_spaces' => true, + 'binary_operator_spaces' => true, + 'blank_line_before_statement' => [ + 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], + ], + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_var_without_name' => true, + 'class_attributes_separation' => [ + 'elements' => [ + 'method' => 'one', + ], + ], + 'method_argument_space' => [ + 'on_multiline' => 'ensure_fully_multiline', + 'keep_multiple_spaces_after_comma' => true, + ], + 'single_trait_insert_per_statement' => true, + ]) + ->setFinder($finder); diff --git a/README.md b/README.md index cadb31e..2e0076b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # laravel-langscanner [![Latest Version on Packagist](https://img.shields.io/packagist/v/druc/laravel-langscanner.svg?style=flat-square)](https://packagist.org/packages/druc/laravel-langscanner) +[![Tests](https://github.com/druc/laravel-langscanner/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/druc/laravel-langscanner/actions/workflows/run-tests.yml) [![Total Downloads](https://img.shields.io/packagist/dt/druc/laravel-langscanner.svg?style=flat-square)](https://packagist.org/packages/druc/laravel-langscanner) This package scans your project for missing translation keys and then writes them into individual json files for you to fill in. diff --git a/composer.json b/composer.json index 9aec182..d404aee 100644 --- a/composer.json +++ b/composer.json @@ -1,56 +1,55 @@ { - "name": "druc/laravel-langscanner", - "description": "Scan missing language translations.", - "keywords": [ - "druc", - "laravel-langscanner" - ], - "homepage": "https://github.com/druc/laravel-langscanner", - "license": "MIT", - "authors": [ - { - "name": "Constantin Druc", - "email": "druc@pinsmile.com", - "role": "Developer" - } - ], - "require": { - "php": "^7.4|^8.0", - "spatie/laravel-package-tools": "^1.4.3", - "illuminate/contracts": "^8.0", - "illuminate/support": "^8.0", - "illuminate/filesystem": "^8.0", - "ext-json": "*" - }, - "require-dev": { - "nunomaduro/collision": "^5.3", - "orchestra/testbench": "^6.15", - "phpunit/phpunit": "^9.3" - }, - "autoload": { - "psr-4": { - "Druc\\Langscanner\\": "src" - } - }, - "autoload-dev": { - "psr-4": { - "Druc\\Langscanner\\Tests\\": "tests" - } - }, - "scripts": { - "test": "./vendor/bin/testbench package:test", - "test-coverage": "vendor/bin/phpunit --coverage-html coverage" - }, - "config": { - "sort-packages": true - }, - "extra": { - "laravel": { - "providers": [ - "Druc\\Langscanner\\LangscannerServiceProvider" - ] - } - }, - "minimum-stability": "dev", - "prefer-stable": true + "name": "druc/laravel-langscanner", + "description": "Scan missing language translations.", + "keywords": [ + "druc", + "laravel-langscanner" + ], + "homepage": "https://github.com/druc/laravel-langscanner", + "license": "MIT", + "authors": [ + { + "name": "Constantin Druc", + "email": "druc@pinsmile.com", + "role": "Developer" + } + ], + "require": { + "php": "^7.4|^8.0", + "spatie/laravel-package-tools": "^1.4.3", + "illuminate/contracts": "^8.0", + "ext-json": "*" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.3", + "nunomaduro/collision": "^5.3", + "orchestra/testbench": "^6.15", + "phpunit/phpunit": "^9.3" + }, + "autoload": { + "psr-4": { + "Druc\\Langscanner\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Druc\\Langscanner\\Tests\\": "tests" + } + }, + "scripts": { + "test": "./vendor/bin/testbench package:test", + "test-coverage": "vendor/bin/phpunit --coverage-html coverage" + }, + "config": { + "sort-packages": true + }, + "extra": { + "laravel": { + "providers": [ + "Druc\\Langscanner\\LangscannerServiceProvider" + ] + } + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/config/langscanner.php b/config/langscanner.php index 5e83fac..e7d19ca 100644 --- a/config/langscanner.php +++ b/config/langscanner.php @@ -40,14 +40,4 @@ | */ 'excluded_paths' => [], - - /* - |-------------------------------------------------------------------------- - | Excluded languages - |-------------------------------------------------------------------------- - | - | Which languages to exclude when scanning for missing translations. - | - */ - 'excluded_languages' => ['en'], ]; diff --git a/src/CachedFileTranslations.php b/src/CachedFileTranslations.php new file mode 100644 index 0000000..a3c2046 --- /dev/null +++ b/src/CachedFileTranslations.php @@ -0,0 +1,35 @@ +fileTranslations = $fileTranslations; + } + + public function update(array $translations): void + { + $this->fileTranslations->update($translations); + } + + public function all(): array + { + $this->fileTranslations->all(); + } + + public function contains(string $key): bool + { + return $this->fileTranslations->contains($key); + } + + public function language(): string + { + return $this->fileTranslations->language(); + } +} diff --git a/src/Commands/LangscannerCommand.php b/src/Commands/LangscannerCommand.php index ae530d2..5168a93 100644 --- a/src/Commands/LangscannerCommand.php +++ b/src/Commands/LangscannerCommand.php @@ -2,8 +2,10 @@ namespace Druc\Langscanner\Commands; +use Druc\Langscanner\CachedFileTranslations; use Druc\Langscanner\FileTranslations; use Druc\Langscanner\Languages; +use Druc\Langscanner\MissingTranslations; use Druc\Langscanner\RequiredTranslations; use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; @@ -11,51 +13,45 @@ class LangscannerCommand extends Command { protected $signature = 'langscanner {language?}'; - protected $description = "Finds keys without a corresponding translation and writes them into the translation (json) files."; + protected $description = "Updates translation files with missing translation keys."; - public function handle(Filesystem $filesystem) + public function handle(Filesystem $filesystem): void { if ($this->argument('language')) { - $languages = [$this->argument('language')]; + $languages = new Languages([$this->argument('language')]); } else { - $languages = (new Languages($filesystem, resource_path('lang'), config('langscanner.excluded_languages')))->toArray(); + $languages = Languages::fromPath(resource_path('lang'), $filesystem); } - $requiredTranslations = (new RequiredTranslations($filesystem, config('langscanner')))->toArray(); + foreach ($languages->all() as $language) { + $fileTranslations = new CachedFileTranslations( + new FileTranslations(['language' => $language]) + ); - $rows = []; - - foreach ($languages as $language) { - if ($filesystem->exists(resource_path("lang/$language.json"))) { - $existingTranslations = json_decode($filesystem->get(resource_path("lang/$language.json")), true); - } else { - $existingTranslations = []; - } - - $missingTranslations = $this->missingTranslations($requiredTranslations, $existingTranslations); - - foreach ($missingTranslations as $key => $path) { - $rows[] = [$language, $key, $path]; - } + $missingTranslations = new MissingTranslations( + new RequiredTranslations(config('langscanner')), + $fileTranslations + ); + $fileTranslations->update( // sets translation values to empty string - $missingTranslations = array_fill_keys(array_keys($missingTranslations), ''); - (new FileTranslations(resource_path("lang/$language.json")))->update($missingTranslations); - } + array_fill_keys( + array_keys($missingTranslations->all()), + '' + ) + ); - $this->table(["Language", "Key", "Path"], $rows); - } + // Render table + $this->comment(PHP_EOL); + $this->comment(strtoupper($language) . " missing translations:"); - private function missingTranslations(array $required, array $existing): array - { - $missing = []; + $rows = []; - foreach ($required as $key => $value) { - if (empty($existing[$key])) { - $missing[$key] = $value; + foreach ($missingTranslations->all() as $key => $path) { + $rows[] = [$key, $path]; } - } - return $missing; + $this->table(["Key", "Path"], $rows); + } } } diff --git a/src/Contracts/FileTranslations.php b/src/Contracts/FileTranslations.php new file mode 100644 index 0000000..50fd006 --- /dev/null +++ b/src/Contracts/FileTranslations.php @@ -0,0 +1,14 @@ +path = $path; + Assert::keyExists($opts, 'language'); + + $this->language = $opts['language']; + $this->disk = $opts['disk'] ?? resolve(Filesystem::class); + $this->rootPath = $opts['rootPath'] ?? resource_path('lang/'); } - public function update(array $translations) + public function language(): string { - if (file_exists($this->path)) { - $existingTranslations = json_decode(file_get_contents($this->path), true); - } else { - $existingTranslations = []; - } + return $this->language; + } - $translations = array_merge($existingTranslations, $translations); + public function update(array $translations): void + { + $translations = array_merge($this->all(), $translations); $translations = json_encode($translations, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); - file_put_contents($this->path, $translations); + $this->disk->put($this->path(), $translations); + } + + public function all(): array + { + if (file_exists($this->path())) { + return json_decode($this->disk->get($this->path()), true); + } + + return []; + } + + public function contains(string $key): bool + { + return !empty($this->all()[$key]); + } + + private function path(): string + { + return $this->rootPath . "{$this->language()}.json"; } } diff --git a/src/LangscannerServiceProvider.php b/src/LangscannerServiceProvider.php index 4b806c0..161d3bb 100644 --- a/src/LangscannerServiceProvider.php +++ b/src/LangscannerServiceProvider.php @@ -3,7 +3,6 @@ namespace Druc\Langscanner; use Druc\Langscanner\Commands\LangscannerCommand; -use Druc\Langscanner\Commands\LangscannerInitCommand; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; diff --git a/src/Languages.php b/src/Languages.php index c7d68cf..d08d8d0 100644 --- a/src/Languages.php +++ b/src/Languages.php @@ -7,28 +7,27 @@ class Languages { - private Filesystem $disk; - private array $excludedLanguages; - private string $path; + private array $languages; - public function __construct(Filesystem $disk, string $path, array $excludedLanguages) + public function __construct(array $languages) { - $this->disk = $disk; - $this->path = $path; - $this->excludedLanguages = $excludedLanguages; + $this->languages = $languages; } - public function toArray(): array + public static function fromPath(string $path, Filesystem $filesystem = null): self { - return Collection::make($this->disk->files($this->path)) - ->filter(function ($file) { - return $file->getExtension() === 'json'; - })->map(function ($file) { - return $file->getFilenameWithoutExtension(); - })->filter(function ($lang) { - return !in_array($lang, $this->excludedLanguages); - }) + $filesystem ??= resolve(Filesystem::class); + $languages = Collection::make($filesystem->files($path)) + ->filter(fn ($file) => $file->getExtension() === 'json') + ->map(fn ($file) => $file->getFilenameWithoutExtension()) ->values() ->toArray(); + + return new self($languages); + } + + public function all(): array + { + return $this->languages; } } diff --git a/src/MissingTranslations.php b/src/MissingTranslations.php new file mode 100644 index 0000000..a3ff92c --- /dev/null +++ b/src/MissingTranslations.php @@ -0,0 +1,32 @@ +requiredTranslations = $requiredTranslations; + $this->fileTranslations = $fileTranslations; + } + + public function all(): array + { + return Collection::make($this->requiredTranslations->all()) + ->filter(fn ($value, $key) => !$this->fileTranslations->contains($key)) + ->toArray(); + } + + public function language(): string + { + return $this->fileTranslations->language(); + } +} diff --git a/src/RequiredTranslations.php b/src/RequiredTranslations.php index 7376758..5aea3d4 100644 --- a/src/RequiredTranslations.php +++ b/src/RequiredTranslations.php @@ -16,41 +16,28 @@ class RequiredTranslations private array $excludedPaths; private array $translations; - public function __construct(Filesystem $disk, $options) + public function __construct(array $options, Filesystem $disk = null) { Assert::keyExists($options, 'paths'); Assert::keyExists($options, 'excluded_paths'); Assert::keyExists($options, 'translation_methods'); - $this->disk = $disk; + $this->disk = $disk ?? resolve(Filesystem::class); $this->paths = $options['paths']; $this->excludedPaths = $options['excluded_paths']; $this->translationMethods = $options['translation_methods']; } - public function toArray(): array + public function all(): array { if (isset($this->translations)) { return $this->translations; } - $pattern = - // See https://regex101.com/r/jS5fX0/5 - '[^\w]'. // Must not start with any alphanum or _ - '(?)'. // Must not start with -> - '('.implode('|', $this->translationMethods).')'.// Must start with one of the functions - "\(".// Match opening parentheses - "[\'\"]".// Match " or ' - '('.// Start a new group to match: - '.*'.// Must start with group - ')'.// Close group - "[\'\"]".// Closing quote - "[\),]" // Close parentheses or new parameter - ; - $results = []; + foreach ($this->files() as $file) { - if (preg_match_all("/$pattern/siuU", $file->getContents(), $matches)) { + if (preg_match_all($this->pattern(), $file->getContents(), $matches)) { foreach ($matches[2] as $key) { if (!empty($key)) { $results[$key] = $file->getFilename(); @@ -60,7 +47,7 @@ public function toArray(): array } // exclude php translations - $results = array_diff_key($results, $this->getPhpTranslations()); + $results = array_diff_key($results, $this->existingPhpTranslations()); return $this->translations = $results; } @@ -69,30 +56,41 @@ private function files(): array { $files = $this->disk->allFiles($this->paths); - foreach ($files as $i => $file) { - foreach ($this->excludedPaths as $path) { - if (Str::startsWith($file->getPathName(), $path)) { - unset($files[$i]); - } - } - } - - return $files; + return Collection::make($files) + ->filter(fn ($file) => !Str::startsWith($file->getPathName(), $this->excludedPaths)) + ->toArray(); } - private function getPhpTranslations(): array + private function existingPhpTranslations(): array { return Collection::make($this->disk->allFiles(resource_path('lang'))) - ->filter(function ($file) { - return $file->getExtension() === 'php'; - })->reduce(function ($carry, $file) { + ->filter(fn ($file) => $file->getExtension() === 'php') + ->reduce(function ($carry, $file) { $translations = $this->disk->getRequire($file->getRealPath()); return $carry->merge(Arr::dot([ - $file->getFilenameWithoutExtension() => $translations + $file->getFilenameWithoutExtension() => $translations, ])); - }, collect())->filter(function ($item) { - return is_string($item); - })->toArray(); + }, Collection::make([])) + ->filter(fn ($item) => is_string($item)) + ->toArray(); + } + + private function pattern(): string + { + // See https://regex101.com/r/jS5fX0/5 + return + "/" . + "[^\w]" . // Must not start with any alphanum or _ + "(?)" . // Must not start with -> + '(' . implode('|', $this->translationMethods) . ')' .// Must start with one of the functions + "\(" .// Match opening parentheses + "[\'\"]" .// Match " or ' + "(" .// Start a new group to match: + ".*" .// Must start with group + ")" .// Close group + "[\'\"]" .// Closing quote + "[\),]" . // Close parentheses or new parameter + "/siuU"; } } diff --git a/tests/FileTranslationsTest.php b/tests/FileTranslationsTest.php index 258b92e..9a250d6 100644 --- a/tests/FileTranslationsTest.php +++ b/tests/FileTranslationsTest.php @@ -3,27 +3,75 @@ namespace Druc\Langscanner\Tests; use Druc\Langscanner\FileTranslations; +use Illuminate\Filesystem\Filesystem; class FileTranslationsTest extends TestCase { /** @test */ - public function it_finds_all_existing_translations() + public function it_finds_all_file_translations(): void { - $path = __DIR__.'/fixtures/lang/es.json'; - $originalContent = file_get_contents($path); + $translations = ['Existing translation' => 'Some Translation']; + $this->putTranslations("en", $translations); + + $this->assertEquals($translations, $this->fileTranslations()->all()); + + unlink($this->langPath("en")); + } + + /** @test */ + public function it_checks_if_it_contains_translation_key(): void + { + $translations = ['Existing translation' => 'Some Translation']; + $this->putTranslations("en", $translations); + + $fileTranslations = $this->fileTranslations(); + + $this->assertTrue($fileTranslations->contains('Existing translation')); + $this->assertFalse($fileTranslations->contains('Missing translation')); + + unlink($this->langPath('en')); + } + + /** @test */ + public function it_updates_translations(): void + { + $translations = ['Existing translation' => 'Some Translation']; + $this->putTranslations("en", $translations); + + $fileTranslations = $this->fileTranslations(); - $fileTranslations = new FileTranslations($path); $fileTranslations->update([ "Missing translation" => "", "Missing translation2" => "this one has content", ]); - $updatedTranslations = json_decode(file_get_contents($path), true); - + $updatedTranslations = $fileTranslations->all(); $this->assertEquals("", $updatedTranslations["Missing translation"]); $this->assertEquals("this one has content", $updatedTranslations["Missing translation2"]); - // Restore original content - file_put_contents($path, $originalContent); + unlink($this->langPath('en')); + } + + private function putTranslations($language, array $translations): void + { + $disk = resolve(Filesystem::class); + $disk->put($this->langPath($language), json_encode($translations, JSON_THROW_ON_ERROR)); + } + + private function langPath(string $filename = null): string + { + if ($filename !== null) { + return __DIR__ . "/fixtures/$filename.json"; + } + + return __DIR__ . "/fixtures/"; + } + + private function fileTranslations(): FileTranslations + { + return (new FileTranslations([ + 'language' => 'en', + 'rootPath' => $this->langPath(), + ])); } } diff --git a/tests/LanguagesTest.php b/tests/LanguagesTest.php index 6df8317..5701385 100644 --- a/tests/LanguagesTest.php +++ b/tests/LanguagesTest.php @@ -8,14 +8,15 @@ class LanguagesTest extends TestCase { /** @test */ - public function it_finds_all_required_languages() + public function it_gets_all_languages_in_path(): void { - $requiredLanguages = new Languages( - new Filesystem, - __DIR__.'/fixtures/lang', - ['en'] - ); + $disk = resolve(Filesystem::class); + $disk->makeDirectory(__DIR__ . "/fixtures/lang/"); + $disk->put(__DIR__ . "/fixtures/lang/en.json", ""); + $disk->put(__DIR__ . "/fixtures/lang/es.json", ""); - $this->assertEquals(['es'], $requiredLanguages->toArray()); + $this->assertEquals(['en', 'es'], Languages::fromPath(__DIR__ . '/fixtures/lang')->all()); + + $disk->deleteDirectory(__DIR__ . "/fixtures/lang/"); } } diff --git a/tests/MissingTranslationsTest.php b/tests/MissingTranslationsTest.php new file mode 100644 index 0000000..c215110 --- /dev/null +++ b/tests/MissingTranslationsTest.php @@ -0,0 +1,35 @@ +mock(RequiredTranslations::class, function (MockInterface $mock) { + $mock->shouldReceive("all")->andReturn([ + 'Existing translation' => 'app.blade.php', + 'Missing translation' => 'app.blade.php', + ]); + }); + + $fileTranslations = $this->mock(FileTranslations::class, function (MockInterface $mock) { + $mock->shouldReceive("contains")->with("Existing translation")->andReturn(true); + $mock->shouldReceive("contains")->with("Missing translation")->andReturn(false); + }); + + $missingTranslations = (new MissingTranslations( + $requiredTranslations, + $fileTranslations + ))->all(); + + $this->assertArrayHasKey("Missing translation", $missingTranslations); + $this->assertArrayNotHasKey("Existing translation", $missingTranslations); + } +} diff --git a/tests/RequiredTranslationsTest.php b/tests/RequiredTranslationsTest.php index 4accb1b..e6bd954 100644 --- a/tests/RequiredTranslationsTest.php +++ b/tests/RequiredTranslationsTest.php @@ -8,15 +8,15 @@ class RequiredTranslationsTest extends TestCase { /** @test */ - public function it_finds_all_required_translations() + public function it_finds_all_required_translations(): void { $requiredTranslations = new RequiredTranslations( - new Filesystem, [ - 'paths' => [__DIR__.'/fixtures/test-files'], + 'paths' => [__DIR__ . '/fixtures/test-files'], 'excluded_paths' => [], - 'translation_methods' => ['__', 'trans', 'trans_choice', '@lang', 'Lang::get'] + 'translation_methods' => ['__', 'trans', 'trans_choice', '@lang', 'Lang::get'], ], + new Filesystem(), ); $this->assertEquals([ @@ -28,6 +28,6 @@ public function it_finds_all_required_translations() 'trans' => 'trans.txt', 'trans.third_match' => 'trans.txt', 'trans_choice.with_params' => 'trans_choice.txt', - ], $requiredTranslations->toArray()); + ], $requiredTranslations->all()); } } diff --git a/tests/fixtures/lang/en.json b/tests/fixtures/lang/en.json deleted file mode 100644 index 0853b1e..0000000 --- a/tests/fixtures/lang/en.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "Hello": "Hello", - "What's up": "What's up!" -} diff --git a/tests/fixtures/lang/es.json b/tests/fixtures/lang/es.json deleted file mode 100644 index 75e96bf..0000000 --- a/tests/fixtures/lang/es.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "Hello": "Hello", - "What's up": "What's up!", - "Missing translation": "app.blade.php" -} \ No newline at end of file