spiral / app

Spiral Framework Skeleton HTTP Application: Queue, Console, Cycle ORM
https://spiral.dev/
MIT License
191 stars 20 forks source link

Bug: "Spiral\Translator\Exception\LocaleException" thrown when 'accept-language' missing #2

Closed krwu closed 4 years ago

krwu commented 4 years ago

Bug description

When I tried to test my controller with PHPUnit, it throws an error: Spiral\Translator\Exception\LocaleException: Undefined locale '' in //Data/Dev/spiral/vendor/spiral/translator/src/Translator.php at line 72

This is caused by the LocaleSelector middleware. It detects the client's locale by the 'accept-language' line in headers of the request.

When the request headers don't have 'accept-language', it will call:

$this->translator->setLocale('');

Reproducible Steps

  1. create a new project with `composer create-project
  2. start the server
  3. run `curl http://localhost:8080' in terminal or CMD.