Skip to content

Remove code specific to Laravel < 7.0 #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/LocalizedUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,6 @@ protected function getLocalizedRouteKey($key, UrlRoutable $model, $locale)
*/
protected function getBindingFieldFor($key, UrlRoutable $model)
{
if (version_compare(App::version(), '7.0.0') === -1) {
return $model->getRouteKeyName();
}

return $this->route->bindingFieldFor($key) ?: $model->getRouteKeyName();
}
}
39 changes: 22 additions & 17 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str;
use Illuminate\Testing\TestResponse;
use Orchestra\Testbench\TestCase as BaseTestCase;
use PHPUnit\Framework\Assert;

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

if (version_compare($this->app->version(), '7.0.0') === -1) {
\Illuminate\Foundation\Testing\TestResponse::macro('assertResponseHasNoView', function () {
if (isset($this->original) && $this->original instanceof View) {
Illuminate\Foundation\Testing\Assert::fail('The response has a view.');
}

return $this;
});
} else {
\Illuminate\Testing\TestResponse::macro('assertResponseHasNoView', function () {
if (isset($this->original) && $this->original instanceof View) {
Illuminate\Testing\Assert::fail('The response has a view.');
}

return $this;
});
}
TestResponse::macro('assertResponseHasNoView', function () {
if (isset($this->original) && $this->original instanceof View) {
Assert::fail('The response has a view.');
}

return $this;
});
}

/**
* Skip test if laravel version is lower than the given version.
*
* @param string $version
*
* @return void
*/
protected function skipTestIfLaravelVersionIsLowerThan($version)
{
if (version_compare(App::version(), $version) === -1) {
$this->markTestSkipped("This test only applies to Laravel {$version} and higher.");
}
}

/**
Expand Down
6 changes: 1 addition & 5 deletions tests/Unit/HelpersFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ function it_throws_when_route_helper_locale_is_unsupported(): void
Route::get('route')->name('route');
});

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

route('route', [], true, 'wk');
}
Expand Down
4 changes: 0 additions & 4 deletions tests/Unit/Macros/Route/LocalizedUrlMacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ public function it_generates_urls_for_the_current_route_with_different_models_us
/** @test */
public function it_generates_urls_with_custom_localized_route_keys_for_the_current_route_using_route_model_binding()
{
if (version_compare($this->app->version(), '7.0.0') === -1) {
$this->markTestSkipped('This feature is only available in Laravel 7 and newer.');
}

$this->withoutExceptionHandling();
$this->setSupportedLocales(['en', 'nl']);

Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Middleware/SetLocaleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ public function it_looks_for_a_locale_on_the_authenticated_user()
/** @test */
public function it_will_bypass_missing_attribute_exception_if_the_locale_attribute_is_missing_on_the_user_model()
{
if (version_compare(App::version(), '9.35.0') === -1) {
$this->markTestSkipped('This test only applies to Laravel 9.35.0 and higher.');
}
$this->skipTestIfLaravelVersionIsLowerThan('9.35.0');

$this->setSupportedLocales(['en', 'nl']);
$this->setAppLocale('en');
Expand Down
4 changes: 0 additions & 4 deletions tests/Unit/RouteModelBindingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public function it_loads_a_route_with_a_localized_route_key_based_on_the_active_
/** @test */
public function it_loads_a_route_with_a_custom_localized_route_key_based_on_the_active_locale()
{
if (version_compare($this->app->version(), '7.0.0') === -1) {
$this->markTestSkipped('This feature is only available in Laravel 7 and newer.');
}

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

$model = (new Model([
Expand Down
18 changes: 3 additions & 15 deletions tests/Unit/UrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ public function it_generates_a_url_for_a_route_with_a_default_localized_route_ke
/** @test */
public function it_generates_a_url_for_a_route_with_a_custom_localized_route_key()
{
if (version_compare($this->app->version(), '7.0.0') === -1) {
$this->markTestSkipped('This feature is only available in Laravel 7 and newer.');
}

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

Expand Down Expand Up @@ -299,17 +295,9 @@ protected function cacheRoutes()
$route->prepareForSerialization();
}

$isLaravel7orGreater = method_exists($routes, 'compile');

if ($isLaravel7orGreater) {
$this->app['router']->setCompiledRoutes(
$routes->compile()
);

return;
}

$this->app['router']->setRoutes($routes);
$this->app['router']->setCompiledRoutes(
$routes->compile()
);
}

/**
Expand Down