Тестирование перенаправления с промежуточного ПО

У меня есть этот тестовый пример:

public function testRedirectToAndSetDefaultLocale()
{
$locale = config('app.locale');
$this->visit('/')->assertRedirectedTo('/' . $locale);
$this->assertEquals($locale, app()->getLocale());
}

И следующее промежуточное ПО:

class SetLocale
{
public function __construct(Application $app, Redirector $redirector, Request $request)
{
$this->app = $app;
$this->redirector = $redirector;
$this->request = $request;
}

/**
* Handle an incoming request.
*
* @param  \Illuminate\Http\Request $request
* @param  \Closure $next
* @param  string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
$locale = $request->segment(1);

if (!array_key_exists($locale, $this->app->config->get('app.locales'))) {
$segments = $request->segments();
$segments[0] = $this->app->config->get('app.fallback_locale');

return $this->redirector->to(implode('/', $segments));
}

$this->app->setLocale($locale);

return $next($request);
}
}

Приведенный выше тест завершается неудачно со следующей трассировкой:

  A request to [http://localhost:8000/en] failed. Received status code [404]./Users/xxx/xxxxxxxxxx/xxxxxxxxx.project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:196
/Users/xxx/xxxxxxxxxx/xxxxxxxxx.project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:80
/Users/xxx/xxxxxxxxxx/xxxxxxxxx.project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:138
/Users/xxx/xxxxxxxxxx/xxxxxxxxx.project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:80
/Users/xxx/xxxxxxxxxx/xxxxxxxxx.project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:61
/Users/xxx/xxxxxxxxxx/xxxxxxxxx.project/tests/HomepageTests.php:17

Я предполагаю, что сервер не запущен или что-то в этом роде. Однако я не знаю, что делать.

Редактировать:

Вот что у меня в моем RouteServiceProvider.php:

$locale = $this->app->request->segment(1);
$this->app->setLocale($locale);$router->group([
'namespace' => $this->namespace,
'middleware' => 'web',
'prefix' => $locale
], function ($router) {
require app_path('Http/routes.php');
});

И в routes.php:

Route::get('/', [
'uses' => 'HomeController@index',
'as' => 'get.index'
]);

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector