Skip to content

Commit

Permalink
Refactor constraints testing
Browse files Browse the repository at this point in the history
  • Loading branch information
chinleung committed Aug 17, 2020
1 parent d159e6d commit 2aedb09
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function () {
/** @test **/
public function the_home_page_can_be_registered(): void
{
Route::multilingual('/', function () {
Route::multilingual('/', static function () {
//
})->name('home');

Expand Down Expand Up @@ -220,7 +220,7 @@ public function a_route_with_prefix_stack_can_be_registered(): void
{
$this->registerTestTranslations();

Route::prefix('prefix')->group(function () {
Route::prefix('prefix')->group(static function () {
Route::multilingual('test');
});

Expand Down Expand Up @@ -285,8 +285,11 @@ public function a_route_param_can_have_constraints(): void

Route::multilingual('search')->where('filter', '.*')->name('search.results');

$this->assertEquals(url('search/Foo'), localized_route('search.results', ['filter' => 'Foo']));
$this->assertEquals(url('fr/recherche/Bar'), localized_route('search.results', ['filter' => 'Bar'], 'fr'));
foreach (locales() as $locale) {
$route = Route::getRoutes()->getByName("{$locale}.search.results");

$this->assertEquals('.*', Arr::get($route->wheres, 'filter'));
}
}

/** @test **/
Expand All @@ -303,7 +306,7 @@ public function a_starting_slash_will_be_trimmed_from_translation(): void
{
$this->registerTestTranslations();

Route::multilingual('/test', function () {
Route::multilingual('/test', static function () {
//
});

Expand All @@ -326,7 +329,7 @@ public function the_current_route_can_be_retrieved_in_a_different_locale_with_qu
{
$this->registerTestRoute();

app()->bind('request', function () {
app()->bind('request', static function () {
return Request::create(localized_route('test'), 'GET', [
'foo' => 'bar',
]);
Expand All @@ -345,7 +348,7 @@ public function the_current_route_will_fallback_to_current_route_by_default(): v
{
Route::view('test', 'app');

app()->bind('request', function () {
app()->bind('request', static function () {
return Request::create(url('test'), 'GET');
});

Expand All @@ -360,7 +363,7 @@ public function the_current_route_can_have_a_custom_fallback(): void
Route::view('test', 'app');
Route::view('fallback', 'app');

app()->bind('request', function () {
app()->bind('request', static function () {
return Request::create(url('test'), 'GET');
});

Expand All @@ -375,7 +378,7 @@ public function the_current_route_can_have_a_custom_fallback(): void
/** @test **/
public function a_route_prefix_can_be_registered_after_the_locale(): void
{
Route::name('prefix.')->group(function () {
Route::name('prefix.')->group(static function () {
Route::multilingual('test');
});

Expand All @@ -390,7 +393,7 @@ public function a_route_prefix_can_be_registered_before_the_locale(): void
'laravel-multilingual-routes.name_prefix_before_locale' => true,
]);

Route::name('prefix.')->group(function () {
Route::name('prefix.')->group(static function () {
Route::multilingual('test');
});

Expand All @@ -401,7 +404,7 @@ public function a_route_prefix_can_be_registered_before_the_locale(): void
/** @test **/
public function a_route_with_defaults_parameters_can_be_registered(): void
{
$params = ['param_1'=>'value_1', 'param_2'=>'value_2'];
$params = ['param_1' => 'value_1', 'param_2' => 'value_2'];
Route::multilingual('test')->defaults($params)->name('test');

foreach (config('locales.supported') as $locale) {
Expand All @@ -422,7 +425,7 @@ public function the_default_home_page_can_be_registered_with_prefix(): void
'laravel-multilingual-routes.prefix_default_home' => true,
]);

Route::multilingual('/', function () {
Route::multilingual('/', static function () {
//
})->name('home');

Expand All @@ -438,7 +441,7 @@ public function the_default_home_page_can_be_registered_without_prefix(): void
'laravel-multilingual-routes.prefix_default_home' => false,
]);

Route::multilingual('/', function () {
Route::multilingual('/', static function () {
//
})->name('home');

Expand All @@ -462,7 +465,7 @@ protected function registerTestRoute(): MultilingualRoutePendingRegistration

return Route::multilingual(
'test',
function () {
static function () {
//
}
);
Expand Down

0 comments on commit 2aedb09

Please sign in to comment.