From d4f6884e076c301eda9d4b96395dca916e37594d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Dalmolin?= Date: Fri, 25 Oct 2024 08:58:14 -0300 Subject: [PATCH] Adding L10 support (#18) * Adding L10 support --- .github/workflows/run-tests.yml | 34 ++++++++++++++++--- src/Generators/EnumGenerator.php | 2 +- tests/Architecture/AttributesTest.php | 4 +-- tests/Architecture/CommandsTest.php | 16 +++++---- tests/Architecture/DiscoveryTest.php | 14 +++++--- tests/Architecture/GeneratorsTest.php | 18 ++++++---- tests/Architecture/PresetTest.php | 9 +++-- tests/Unit/Commands/ClearCacheCommandTest.php | 6 ++++ 8 files changed, 76 insertions(+), 27 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a4367c1..32cd2b6 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -2,7 +2,6 @@ name: run-tests on: push: - pull_request: jobs: pest: @@ -12,8 +11,32 @@ jobs: strategy: fail-fast: true matrix: - php: [ 8.2, 8.3 ] - laravel: [ 11.* ] + php: [ 8.1, 8.2, 8.3 ] + laravel: [ 10.*, 11.* ] + include: + - php: 8.1 + laravel: 10.* + pest: 2.* + testbench: 8.* + - php: 8.2 + laravel: 10.* + pest: 2.* + testbench: 8.* + - php: 8.3 + laravel: 10.* + pest: 2.* + testbench: 8.* + - php: 8.2 + laravel: 11.* + pest: 3.* + testbench: 9.* + - php: 8.3 + laravel: 11.* + pest: 3.* + testbench: 9.* + exclude: + - php: 8.1 + laravel: 11.* name: Paragon Tests - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} @@ -37,7 +60,10 @@ jobs: - name: Install dependencies run: | - composer install --no-interaction --no-suggest --dev + composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update + composer require "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update --dev + composer require "pestphp/pest:${{ matrix.pest }}" "pestphp/pest-plugin-laravel:${{ matrix.pest }}" --no-interaction --no-update --dev + composer update --prefer-dist --no-interaction --no-suggest --dev composer dump - name: Execute tests diff --git a/src/Generators/EnumGenerator.php b/src/Generators/EnumGenerator.php index 2e33f7d..8b08527 100644 --- a/src/Generators/EnumGenerator.php +++ b/src/Generators/EnumGenerator.php @@ -82,7 +82,7 @@ protected function prepareEnumCode(): Fluent { $cases = collect($this->reflector->getCases()); - return fluent([ + return new Fluent([ 'type' => $this->buildTypeDefinition(), 'cases' => $this->buildCases($cases), 'getters' => $this->buildGetters($cases), diff --git a/tests/Architecture/AttributesTest.php b/tests/Architecture/AttributesTest.php index 41e1436..9be7f1d 100644 --- a/tests/Architecture/AttributesTest.php +++ b/tests/Architecture/AttributesTest.php @@ -2,8 +2,8 @@ use Kirschbaum\Paragon\Concerns\IgnoreParagon; -arch()->expect(IgnoreParagon::class) +arch('IgnoreParagon::Should extend nothing')->expect(IgnoreParagon::class) ->toExtendNothing(); -arch()->expect(IgnoreParagon::class) +arch('IgnoreParagon::Should have attribute')->expect(IgnoreParagon::class) ->toHaveAttribute(Attribute::class); diff --git a/tests/Architecture/CommandsTest.php b/tests/Architecture/CommandsTest.php index 0bd8d71..26970a4 100644 --- a/tests/Architecture/CommandsTest.php +++ b/tests/Architecture/CommandsTest.php @@ -2,15 +2,19 @@ use Symfony\Component\Console\Attribute\AsCommand; -arch()->expect('Kirschbaum\Paragon\Commands') +arch('Commands should have suffix')->expect('Kirschbaum\Paragon\Commands') ->classes() ->toHaveSuffix('Command'); -arch()->expect('Kirschbaum\Paragon\Commands') +arch('Commands should have attribute')->expect('Kirschbaum\Paragon\Commands') ->toHaveAttribute(AsCommand::class); -arch()->expect('Kirschbaum\Paragon\Commands') - ->not->toHavePrivateMethodsBesides(['__construct', 'handle']); +exec('composer show pestphp/pest', $output); -arch()->expect('Kirschbaum\Paragon\Commands') - ->not->toHavePublicMethodsBesides(['__construct', 'handle']); +if ($output[3] === 'versions : * v3') { + arch('Commands should not have private methods')->expect('Kirschbaum\Paragon\Commands') + ->not->toHavePrivateMethodsBesides(['__construct', 'handle']); + + arch('Commands should not have public methods')->expect('Kirschbaum\Paragon\Commands') + ->not->toHavePublicMethodsBesides(['__construct', 'handle']); +} \ No newline at end of file diff --git a/tests/Architecture/DiscoveryTest.php b/tests/Architecture/DiscoveryTest.php index 9cdc754..183ddff 100644 --- a/tests/Architecture/DiscoveryTest.php +++ b/tests/Architecture/DiscoveryTest.php @@ -2,11 +2,15 @@ use Kirschbaum\Paragon\Concerns\DiscoverEnums; -arch()->expect(DiscoverEnums::class) +arch('DiscoverEnums should extend nothing')->expect(DiscoverEnums::class) ->toExtendNothing(); -arch()->expect(DiscoverEnums::class) - ->not->toHavePrivateMethodsBesides(['within']); +exec('composer show pestphp/pest', $output); -arch()->expect(DiscoverEnums::class) - ->not->toHavePublicMethodsBesides(['within']); +if ($output[3] === 'versions : * v3') { + arch('DiscoverEnums should not have private methods')->expect(DiscoverEnums::class) + ->not->toHavePrivateMethodsBesides(['within']); + + arch('DiscoverEnums should not have public methods')->expect(DiscoverEnums::class) + ->not->toHavePublicMethodsBesides(['within']); +} \ No newline at end of file diff --git a/tests/Architecture/GeneratorsTest.php b/tests/Architecture/GeneratorsTest.php index bf2029e..f1befb9 100644 --- a/tests/Architecture/GeneratorsTest.php +++ b/tests/Architecture/GeneratorsTest.php @@ -1,17 +1,21 @@ expect('Kirschbaum\Paragon\Generators') +arch('Generators should have suffix')->expect('Kirschbaum\Paragon\Generators') ->classes() ->toHaveSuffix('Generator'); -arch()->expect('Kirschbaum\Paragon\Generators') +arch('Generators should extend nothing')->expect('Kirschbaum\Paragon\Generators') ->toExtendNothing(); -arch()->expect('Kirschbaum\Paragon\Generators') +arch('Generators should be invokable')->expect('Kirschbaum\Paragon\Generators') ->toBeInvokable(); -arch()->expect('Kirschbaum\Paragon\Generators') - ->not->toHavePrivateMethodsBesides(['__construct', '__invoke']); +exec('composer show pestphp/pest', $output); -arch()->expect('Kirschbaum\Paragon\Generators') - ->not->toHavePublicMethodsBesides(['__construct', '__invoke']); +if ($output[3] === 'versions : * v3') { + arch('Generators should not have private methods')->expect('Kirschbaum\Paragon\Generators') + ->not->toHavePrivateMethodsBesides(['__construct', '__invoke']); + + arch('Generators should not have public methods')->expect('Kirschbaum\Paragon\Generators') + ->not->toHavePublicMethodsBesides(['__construct', '__invoke']); +} \ No newline at end of file diff --git a/tests/Architecture/PresetTest.php b/tests/Architecture/PresetTest.php index e34bff7..d1b31eb 100644 --- a/tests/Architecture/PresetTest.php +++ b/tests/Architecture/PresetTest.php @@ -1,9 +1,14 @@ preset()->php(); +// Pest Presets are available beginning in version 3. +exec('composer show pestphp/pest', $output); + +if ($output[3] === 'versions : * v3') { + arch('PHP preset')->preset()->php(); +} // Security without the md5 method as we need it for caching. -arch() +arch('Not to use vulnerable functions') ->expect([ 'array_rand', 'assert', diff --git a/tests/Unit/Commands/ClearCacheCommandTest.php b/tests/Unit/Commands/ClearCacheCommandTest.php index 93d8ba5..dd5a3e9 100644 --- a/tests/Unit/Commands/ClearCacheCommandTest.php +++ b/tests/Unit/Commands/ClearCacheCommandTest.php @@ -3,6 +3,12 @@ use Kirschbaum\Paragon\Commands\ClearCacheCommand; use Kirschbaum\Paragon\Commands\GenerateEnumsCommand; +exec('composer show pestphp/pest', $output); + +if ($output[3] !== 'versions : * v3') { + return; +} + it('removes the cache directory', function () { // Assemble. $this->artisan(GenerateEnumsCommand::class);