-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from musimana/feature/AppVersionFormatters
App Version Formatters
- Loading branch information
Showing
10 changed files
with
90 additions
and
21 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...Formatters/CopyrightFormatterResource.php → ...Formatters/CopyrightFormatterResource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/Http/Resources/Formatters/LaravelVersionFormatterResource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources\Formatters; | ||
|
||
use App\Interfaces\Resources\Formatters\ConstantStringFormatterInterface; | ||
use Illuminate\Foundation\Application; | ||
|
||
final class LaravelVersionFormatterResource implements ConstantStringFormatterInterface | ||
{ | ||
/** Get the formatted string of the app's Laravel version. */ | ||
public function getValue(): string | ||
{ | ||
$delimiter_position = strpos(Application::VERSION, '.'); | ||
|
||
return $delimiter_position | ||
? substr(Application::VERSION, 0, $delimiter_position) . '.x' | ||
: Application::VERSION; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/Http/Resources/Formatters/PhpVersionFormatterResource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources\Formatters; | ||
|
||
use App\Interfaces\Resources\Formatters\ConstantStringFormatterInterface; | ||
|
||
final class PhpVersionFormatterResource implements ConstantStringFormatterInterface | ||
{ | ||
/** Get the formatted string of the app's PHP version. */ | ||
public function getValue(): string | ||
{ | ||
$delimiter_position = strrpos(PHP_VERSION, '.'); | ||
|
||
return $delimiter_position | ||
? substr(PHP_VERSION, 0, $delimiter_position) . '.x' | ||
: PHP_VERSION; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...atters/CopyrightFormatterResourceTest.php → ...atters/CopyrightFormatterResourceTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/Unit/App/Http/Resources/Formatters/LaravelVersionFormatterResourceTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
use App\Http\Resources\Formatters\LaravelVersionFormatterResource; | ||
use App\Interfaces\Resources\Formatters\ConstantStringFormatterInterface; | ||
use Illuminate\Foundation\Application; | ||
|
||
arch('it implements the expected interface') | ||
->expect(LaravelVersionFormatterResource::class) | ||
->toImplement(ConstantStringFormatterInterface::class); | ||
|
||
test('getValue returns ok with valid inputs', function () { | ||
$actual = (new LaravelVersionFormatterResource())->getValue(); | ||
|
||
expect($actual) | ||
->toBeString() | ||
->toEqual(substr(Application::VERSION, 0, strpos(Application::VERSION, '.') ?: null) . '.x'); | ||
}); |
16 changes: 16 additions & 0 deletions
16
tests/Unit/App/Http/Resources/Formatters/PhpVersionFormatterResourceTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
use App\Http\Resources\Formatters\PhpVersionFormatterResource; | ||
use App\Interfaces\Resources\Formatters\ConstantStringFormatterInterface; | ||
|
||
arch('it implements the expected interface') | ||
->expect(PhpVersionFormatterResource::class) | ||
->toImplement(ConstantStringFormatterInterface::class); | ||
|
||
test('getValue returns ok with valid inputs', function () { | ||
$actual = (new PhpVersionFormatterResource())->getValue(); | ||
|
||
expect($actual) | ||
->toBeString() | ||
->toEqual(substr(PHP_VERSION, 0, strrpos(PHP_VERSION, '.') ?: null) . '.x'); | ||
}); |