-
Notifications
You must be signed in to change notification settings - Fork 13
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
Added code that allows user to work with different versions. #116
Conversation
|
||
namespace RonasIT\Support\Contracts; | ||
|
||
interface VersionEnumContract { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface VersionEnumContract { | |
interface VersionEnumContract | |
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/HelpersServiceProvider.php
Outdated
@@ -24,6 +27,40 @@ public function boot() | |||
app(ExcelServiceProvider::class, ['app' => app()])->boot(); | |||
|
|||
$this->loadViewsFrom(__DIR__ . '/Stubs', 'ronasit'); | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move it to the separate function extendRouter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move only router extension to the separate method, not all logic :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/Support/Version.php
Outdated
{ | ||
$route = Route::getRoutes()->match(request()); | ||
|
||
return $route->parameters()['version'] ?? str_replace('/v', '', $route->getPrefix()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return $route->parameters()['version'] ?? str_replace('/v', '', $route->getPrefix()); | |
return Arr::get($route->parameters(), 'version', str_replace('/v', '', $route->getPrefix()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/Support/Version.php
Outdated
return $route->parameters()['version'] ?? str_replace('/v', '', $route->getPrefix()); | ||
} | ||
|
||
public static function is(VersionEnumContract $checkedVersion): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static function is(VersionEnumContract $checkedVersion): bool | |
public static function is(VersionEnumContract $expectedVersion): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/Support/Version.php
Outdated
{ | ||
$version = self::current(); | ||
|
||
return $version >= $from->value && $version <= $to->value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use version_compare native function instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/TestCase.php
Outdated
@@ -68,6 +69,13 @@ public function callRawRequest(string $method, string $uri, $content, array $hea | |||
return $this->call($method, $uri, [], [], [], $server, $content); | |||
} | |||
|
|||
public function json($method, $uri, array $data = [], array $headers = [], ?VersionEnumContract $apiVersion = null): TestResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep this code in EmptyProject repository
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/HelpersServiceProvider.php
Outdated
@@ -24,6 +27,40 @@ public function boot() | |||
app(ExcelServiceProvider::class, ['app' => app()])->boot(); | |||
|
|||
$this->loadViewsFrom(__DIR__ . '/Stubs', 'ronasit'); | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move only router extension to the separate method, not all logic :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please increase test coverage
src/Enum/VersionEnum.php
Outdated
@@ -0,0 +1,23 @@ | |||
<?php | |||
|
|||
namespace RonasIT\Support\Enum; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace RonasIT\Support\Enum; | |
namespace RonasIT\Support\Tests\Support\Enum; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/Enum/VersionEnum.php
Outdated
|
||
use RonasIT\Support\Contracts\VersionEnumContract; | ||
|
||
class VersionEnum implements VersionEnumContract |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class VersionEnum implements VersionEnumContract | |
// Backward compatibility with PHP < 8 | |
class VersionEnum implements VersionEnumContract |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/HelpersServiceProvider.php
Outdated
Route::macro('whereIn', function ($parameters, array $values) { | ||
return $this->assignExpressionToParameters($parameters, implode('|', $values)); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Route::macro('whereIn', function ($parameters, array $values) { | |
return $this->assignExpressionToParameters($parameters, implode('|', $values)); | |
}); | |
Route::macro('whereIn', fn ($parameters, array $values) => $this->assignExpressionToParameters($parameters, implode('|', $values))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/HelpersServiceProvider.php
Outdated
return $this->where(collect(Arr::wrap($parameters)) | ||
->mapWithKeys(function ($parameter) use ($expression) { | ||
return [$parameter => $expression]; | ||
})->all()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return $this->where(collect(Arr::wrap($parameters)) | |
->mapWithKeys(function ($parameter) use ($expression) { | |
return [$parameter => $expression]; | |
})->all()); | |
return $this | |
->where(collect(Arr::wrap($parameters)) | |
->mapWithKeys(fn ($parameter) => [$parameter => $expression]) | |
->all()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/VersionRouteTest.php
Outdated
$versionFrom = $this->createMock(VersionEnumContract::class); | ||
$versionFrom->value = VersionEnum::v1; | ||
$versionTo = $this->createMock(VersionEnumContract::class); | ||
$versionTo->value = VersionEnum::v2; | ||
Route::group(['prefix' => 'v{version}'], function () use ($versionTo, $versionFrom) { | ||
Route::get(static::ROUTE_OBJECT, function () { | ||
return 'Route'; | ||
})->versionRange($versionFrom, $versionTo); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move it to the separate methods of the new trait RouteMockTrait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/VersionRouteTest.php
Outdated
$versionFrom = $this->createMock(VersionEnumContract::class); | ||
$versionFrom->value = VersionEnum::v11; | ||
$versionTo = $this->createMock(VersionEnumContract::class); | ||
$versionTo->value = VersionEnum::v12; | ||
Route::group(['prefix' => 'v{version}'], function () use ($versionTo, $versionFrom) { | ||
RouteFacade::versionRange($versionFrom, $versionTo)->group(function () { | ||
Route::get(static::ROUTE_FACADE, function () { | ||
return 'RouteFacade'; | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
et's move it to the separate method of the new trait RouteMockTrait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/VersionRouteTest.php
Outdated
/** | ||
* @dataProvider getTestVersionRangeData | ||
*/ | ||
public function testVersionRange(string $version, bool $assert, string $route): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function testVersionRange(string $version, bool $assert, string $route): void | |
public function testVersionRange(string $version, bool $isCorrectVersion, string $route): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/VersionRouteTest.php
Outdated
{ | ||
$response = $this->get("/v{$version}{$route}"); | ||
|
||
$status = $assert ? 200 : 404; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$status = $assert ? 200 : 404; | |
$status = ($assert) ? 200 : 404; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/VersionRouteTest.php
Outdated
return [ | ||
[ | ||
'version' => '1', | ||
'assert' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'assert' => true, | |
'is_correct_version' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/VersionRouteTest.php
Outdated
|
||
$this->app->bind(VersionEnumContract::class, VersionEnum::class); | ||
|
||
switch ($this->getProvidedData()['route']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move it to the RouteMockTrait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/VersionRouteTest.php
Outdated
public function getTestVersionRangeData(): array | ||
{ | ||
return [ | ||
// Range |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Range |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/VersionRouteTest.php
Outdated
'route' => static::ROUTE_FACADE_RANGE, | ||
], | ||
|
||
// From |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please implement several tests instead of comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
No description provided.