stevegrunwell / lost-in-translation

Uncover missing translations and localization strings in Laravel applications.
https://stevegrunwell.com/blog/find-missing-laravel-translations/
MIT License
36 stars 8 forks source link

Error using TRANS_ERROR_ON_MISSING with phpunit #2

Open jartaud opened 6 years ago

jartaud commented 6 years ago
1) Tests\Unit\CustomValidationTest::validate_user_status_cannot_be_updated_from_locked_to_active
LostInTranslation\Exceptions\MissingTranslationException: Could not find translation for "validation.attributes".

F:\lamp\proj\THE_APP\vendor\stevegrunwell\lost-in-translation\src\Translator.php:49
F:\lamp\proj\THE_APP\vendor\laravel\framework\src\Illuminate\Translation\Translator.php:101
F:\lamp\proj\THE_APP\vendor\laravel\framework\src\Illuminate\Validation\Concerns\FormatsMessages.php:251
F:\lamp\proj\THE_APP\vendor\laravel\framework\src\Illuminate\Validation\Concerns\FormatsMessages.php:228
F:\lamp\proj\THE_APP\vendor\laravel\framework\src\Illuminate\Validation\Concerns\FormatsMessages.php:190
F:\lamp\proj\THE_APP\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:578
F:\lamp\proj\THE_APP\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:360
F:\lamp\proj\THE_APP\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:268
F:\lamp\proj\THE_APP\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:293
F:\lamp\proj\THE_APP\tests\Unit\CustomValidationTest.php:32

[en,fr]/validation.php

[
  'attributes' => [],
]

phpunit.xml

<php>
        <env name="TRANS_ERROR_ON_MISSING" value="true"/>
</php>

Can't test it, but i think changing this line: Translator to something like this: if ($translation === $key && !in_array($key, ['validation.attributes'])) {... should fix the problem.

jartaud commented 6 years ago

To get green, i'm adding to en/validation.php:

'attributes' => [
     'user_status' => '',
 ],
jartaud commented 6 years ago

Now keeps failing: validation.custom.ATTRIBUTE.required . I don't understand why it forcing me to use the custom array for: 'first_name' => 'required|string'