From 28290123115ded06355393f3896e96dd3d5b9fbb Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Sat, 30 Mar 2024 14:58:47 +0000 Subject: [PATCH 1/5] Created LaravelVersionFormatterResource with unit tests --- .../LaravelVersionFormatterResource.php | 19 +++++++++++++++++++ .../LaravelVersionFormatterResourceTest.php | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 app/Http/Resources/Formatters/LaravelVersionFormatterResource.php create mode 100644 tests/Unit/App/Http/Resources/Formatters/LaravelVersionFormatterResourceTest.php diff --git a/app/Http/Resources/Formatters/LaravelVersionFormatterResource.php b/app/Http/Resources/Formatters/LaravelVersionFormatterResource.php new file mode 100644 index 00000000..74ec05f5 --- /dev/null +++ b/app/Http/Resources/Formatters/LaravelVersionFormatterResource.php @@ -0,0 +1,19 @@ +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'); +}); From ada35734ca356a946074387c41d9fc7b76f49be9 Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Sat, 30 Mar 2024 14:59:26 +0000 Subject: [PATCH 2/5] Created PhpVersionFormatterResource with unit tests --- .../Formatters/PhpVersionFormatterResource.php | 18 ++++++++++++++++++ .../PhpVersionFormatterResourceTest.php | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 app/Http/Resources/Formatters/PhpVersionFormatterResource.php create mode 100644 tests/Unit/App/Http/Resources/Formatters/PhpVersionFormatterResourceTest.php diff --git a/app/Http/Resources/Formatters/PhpVersionFormatterResource.php b/app/Http/Resources/Formatters/PhpVersionFormatterResource.php new file mode 100644 index 00000000..bbe83a66 --- /dev/null +++ b/app/Http/Resources/Formatters/PhpVersionFormatterResource.php @@ -0,0 +1,18 @@ +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, '.')) . '.x'); +}); From 4c0dc20da5a5694d3c3b08d3a37dc9b85ca69c03 Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Sat, 30 Mar 2024 15:01:52 +0000 Subject: [PATCH 3/5] Hoisted CopyrightFormatterResource to new directory & updated arch tests --- .../Formatters/CopyrightFormatterResource.php | 2 +- app/Http/Resources/Views/MetadataViewResource.php | 2 +- tests/Unit/App/Http/HttpArchitectureTest.php | 12 ++++++------ .../Formatters/CopyrightFormatterResourceTest.php | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) rename app/Http/Resources/{Views/Public => }/Formatters/CopyrightFormatterResource.php (85%) rename tests/Unit/App/Http/Resources/{Views/Public => }/Formatters/CopyrightFormatterResourceTest.php (85%) diff --git a/app/Http/Resources/Views/Public/Formatters/CopyrightFormatterResource.php b/app/Http/Resources/Formatters/CopyrightFormatterResource.php similarity index 85% rename from app/Http/Resources/Views/Public/Formatters/CopyrightFormatterResource.php rename to app/Http/Resources/Formatters/CopyrightFormatterResource.php index 86cf6b93..1919cbb1 100644 --- a/app/Http/Resources/Views/Public/Formatters/CopyrightFormatterResource.php +++ b/app/Http/Resources/Formatters/CopyrightFormatterResource.php @@ -1,6 +1,6 @@ expect('App\Http\Resources\Files') ->toHaveSuffix('FileResource'); +arch('app/Http/Resources/Views/Public/Formatters has valid architecture') + ->expect('App\Http\Resources\Formatters') + ->toHaveSuffix('FormatterResource') + ->toBeUsedIn('App\Http') + ->tohaveMethod('getValue'); + arch('app/Http/Resources/Models has valid architecture') ->expect('App\Http\Resources\Models') ->toHaveSuffix('ModelResource') @@ -62,12 +68,6 @@ ->toBeUsedIn('App\Http') ->tohaveMethod('getItem'); -arch('app/Http/Resources/Views/Public/Formatters has valid architecture') - ->expect('App\Http\Resources\Views\Public\Formatters') - ->toHaveSuffix('FormatterResource') - ->toBeUsedIn('App\Http') - ->tohaveMethod('getValue'); - arch('app/Http/Resources/Views/Public/Metadata has valid architecture') ->expect('App\Http\Resources\Views\Public\Metadata') ->toHaveSuffix('MetadataResource') diff --git a/tests/Unit/App/Http/Resources/Views/Public/Formatters/CopyrightFormatterResourceTest.php b/tests/Unit/App/Http/Resources/Formatters/CopyrightFormatterResourceTest.php similarity index 85% rename from tests/Unit/App/Http/Resources/Views/Public/Formatters/CopyrightFormatterResourceTest.php rename to tests/Unit/App/Http/Resources/Formatters/CopyrightFormatterResourceTest.php index 2ebed7a0..fdc3b2cf 100644 --- a/tests/Unit/App/Http/Resources/Views/Public/Formatters/CopyrightFormatterResourceTest.php +++ b/tests/Unit/App/Http/Resources/Formatters/CopyrightFormatterResourceTest.php @@ -1,6 +1,6 @@ Date: Sat, 30 Mar 2024 15:05:35 +0000 Subject: [PATCH 4/5] Implemented new formatter resources --- .../Resources/Views/Blocks/StackBlockResource.php | 12 ++++++------ tests/Datasets/Blocks.php | 11 +++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/Http/Resources/Views/Blocks/StackBlockResource.php b/app/Http/Resources/Views/Blocks/StackBlockResource.php index 3dd0f32e..0abe75c3 100644 --- a/app/Http/Resources/Views/Blocks/StackBlockResource.php +++ b/app/Http/Resources/Views/Blocks/StackBlockResource.php @@ -2,8 +2,9 @@ namespace App\Http\Resources\Views\Blocks; +use App\Http\Resources\Formatters\LaravelVersionFormatterResource; +use App\Http\Resources\Formatters\PhpVersionFormatterResource; use App\Interfaces\Resources\Items\ConstantItemInterface; -use Illuminate\Foundation\Application; final class StackBlockResource implements ConstantItemInterface { @@ -14,10 +15,9 @@ final class StackBlockResource implements ConstantItemInterface */ public function getItem(): array { - $laravel_delimiter_position = strpos(Application::VERSION, '.'); - $laravel_version = $laravel_delimiter_position - ? substr(Application::VERSION, 0, $laravel_delimiter_position) . '.x' - : Application::VERSION; + $laravel_version = (new LaravelVersionFormatterResource)->getValue(); + + $php_version = (new PhpVersionFormatterResource)->getValue(); $php_delimiter_position = strrpos(PHP_VERSION, '.'); $php_version = $php_delimiter_position @@ -58,7 +58,7 @@ public function getItem(): array 'html' => implode('', [ '

Stack

    ', $li_elements_string, - '

For PHP v' . $php_version . '

', + '

Running on PHP v' . $php_version . '

', ]), ]; } diff --git a/tests/Datasets/Blocks.php b/tests/Datasets/Blocks.php index 2c931f2f..f2503515 100644 --- a/tests/Datasets/Blocks.php +++ b/tests/Datasets/Blocks.php @@ -1,19 +1,18 @@ getValue(); +$php_version = (new PhpVersionFormatterResource)->getValue(); $stack_html = '

Stack

For PHP v8.2.x

'; + . '

Running on PHP v' . $php_version . '

'; $tabs = ['tabs' => ['Tab One', 'Tab Two']]; From 0c36af8bfe3ed0be79eeed115f830af31a4b7ff5 Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Sat, 30 Mar 2024 15:23:07 +0000 Subject: [PATCH 5/5] Fix for type error --- .../Resources/Formatters/PhpVersionFormatterResourceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/App/Http/Resources/Formatters/PhpVersionFormatterResourceTest.php b/tests/Unit/App/Http/Resources/Formatters/PhpVersionFormatterResourceTest.php index 4ad711fb..16a0fda9 100644 --- a/tests/Unit/App/Http/Resources/Formatters/PhpVersionFormatterResourceTest.php +++ b/tests/Unit/App/Http/Resources/Formatters/PhpVersionFormatterResourceTest.php @@ -12,5 +12,5 @@ expect($actual) ->toBeString() - ->toEqual(substr(PHP_VERSION, 0, strrpos(PHP_VERSION, '.')) . '.x'); + ->toEqual(substr(PHP_VERSION, 0, strrpos(PHP_VERSION, '.') ?: null) . '.x'); });