Skip to content

Commit ad4b49e

Browse files
authored
Remove code specific to Laravel < 7.0 (#86)
1 parent 9da3af3 commit ad4b49e

File tree

7 files changed

+27
-52
lines changed

7 files changed

+27
-52
lines changed

src/LocalizedUrlGenerator.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,6 @@ protected function getLocalizedRouteKey($key, UrlRoutable $model, $locale)
330330
*/
331331
protected function getBindingFieldFor($key, UrlRoutable $model)
332332
{
333-
if (version_compare(App::version(), '7.0.0') === -1) {
334-
return $model->getRouteKeyName();
335-
}
336-
337333
return $this->route->bindingFieldFor($key) ?: $model->getRouteKeyName();
338334
}
339335
}

tests/TestCase.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use Illuminate\Support\Facades\Route;
1414
use Illuminate\Support\Facades\Session;
1515
use Illuminate\Support\Str;
16+
use Illuminate\Testing\TestResponse;
1617
use Orchestra\Testbench\TestCase as BaseTestCase;
18+
use PHPUnit\Framework\Assert;
1719

1820
abstract class TestCase extends BaseTestCase
1921
{
@@ -37,24 +39,27 @@ protected function setUp(): void
3739
$this->sessionKey = Config::get('localized-routes.session_key');
3840
$this->cookieName = Config::get('localized-routes.cookie_name');
3941

40-
if (version_compare($this->app->version(), '7.0.0') === -1) {
41-
\Illuminate\Foundation\Testing\TestResponse::macro('assertResponseHasNoView', function () {
42-
if (isset($this->original) && $this->original instanceof View) {
43-
Illuminate\Foundation\Testing\Assert::fail('The response has a view.');
44-
}
45-
46-
return $this;
47-
});
48-
} else {
49-
\Illuminate\Testing\TestResponse::macro('assertResponseHasNoView', function () {
50-
if (isset($this->original) && $this->original instanceof View) {
51-
Illuminate\Testing\Assert::fail('The response has a view.');
52-
}
53-
54-
return $this;
55-
});
56-
}
42+
TestResponse::macro('assertResponseHasNoView', function () {
43+
if (isset($this->original) && $this->original instanceof View) {
44+
Assert::fail('The response has a view.');
45+
}
46+
47+
return $this;
48+
});
49+
}
5750

51+
/**
52+
* Skip test if laravel version is lower than the given version.
53+
*
54+
* @param string $version
55+
*
56+
* @return void
57+
*/
58+
protected function skipTestIfLaravelVersionIsLowerThan($version)
59+
{
60+
if (version_compare(App::version(), $version) === -1) {
61+
$this->markTestSkipped("This test only applies to Laravel {$version} and higher.");
62+
}
5863
}
5964

6065
/**

tests/Unit/HelpersFileTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ function it_throws_when_route_helper_locale_is_unsupported(): void
3333
Route::get('route')->name('route');
3434
});
3535

36-
if (version_compare($this->app->version(), '6.0.0') === -1) {
37-
$this->expectExceptionMessage('Route [wk.route] not defined.');
38-
} else {
39-
$this->expectException(RouteNotFoundException::class);
40-
}
36+
$this->expectException(RouteNotFoundException::class);
4137

4238
route('route', [], true, 'wk');
4339
}

tests/Unit/Macros/Route/LocalizedUrlMacroTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ public function it_generates_urls_for_the_current_route_with_different_models_us
9696
/** @test */
9797
public function it_generates_urls_with_custom_localized_route_keys_for_the_current_route_using_route_model_binding()
9898
{
99-
if (version_compare($this->app->version(), '7.0.0') === -1) {
100-
$this->markTestSkipped('This feature is only available in Laravel 7 and newer.');
101-
}
102-
10399
$this->withoutExceptionHandling();
104100
$this->setSupportedLocales(['en', 'nl']);
105101

tests/Unit/Middleware/SetLocaleTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ public function it_looks_for_a_locale_on_the_authenticated_user()
135135
/** @test */
136136
public function it_will_bypass_missing_attribute_exception_if_the_locale_attribute_is_missing_on_the_user_model()
137137
{
138-
if (version_compare(App::version(), '9.35.0') === -1) {
139-
$this->markTestSkipped('This test only applies to Laravel 9.35.0 and higher.');
140-
}
138+
$this->skipTestIfLaravelVersionIsLowerThan('9.35.0');
141139

142140
$this->setSupportedLocales(['en', 'nl']);
143141
$this->setAppLocale('en');

tests/Unit/RouteModelBindingTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ public function it_loads_a_route_with_a_localized_route_key_based_on_the_active_
4747
/** @test */
4848
public function it_loads_a_route_with_a_custom_localized_route_key_based_on_the_active_locale()
4949
{
50-
if (version_compare($this->app->version(), '7.0.0') === -1) {
51-
$this->markTestSkipped('This feature is only available in Laravel 7 and newer.');
52-
}
53-
5450
$this->setSupportedLocales(['en', 'nl']);
5551

5652
$model = (new Model([

tests/Unit/UrlGeneratorTest.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,6 @@ public function it_generates_a_url_for_a_route_with_a_default_localized_route_ke
204204
/** @test */
205205
public function it_generates_a_url_for_a_route_with_a_custom_localized_route_key()
206206
{
207-
if (version_compare($this->app->version(), '7.0.0') === -1) {
208-
$this->markTestSkipped('This feature is only available in Laravel 7 and newer.');
209-
}
210-
211207
$this->setSupportedLocales(['en', 'nl']);
212208
$this->setAppLocale('en');
213209

@@ -299,17 +295,9 @@ protected function cacheRoutes()
299295
$route->prepareForSerialization();
300296
}
301297

302-
$isLaravel7orGreater = method_exists($routes, 'compile');
303-
304-
if ($isLaravel7orGreater) {
305-
$this->app['router']->setCompiledRoutes(
306-
$routes->compile()
307-
);
308-
309-
return;
310-
}
311-
312-
$this->app['router']->setRoutes($routes);
298+
$this->app['router']->setCompiledRoutes(
299+
$routes->compile()
300+
);
313301
}
314302

315303
/**

0 commit comments

Comments
 (0)