From cdb867952f1466c78ed82479b92bee3c26cd1d18 Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Mon, 29 Sep 2025 09:28:37 +0200 Subject: [PATCH 1/6] FIX validation massages --- src/Rules/ExistsEncrypted.php | 2 +- src/Rules/UniqueEncrypted.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Rules/ExistsEncrypted.php b/src/Rules/ExistsEncrypted.php index a98a0db..895e86f 100644 --- a/src/Rules/ExistsEncrypted.php +++ b/src/Rules/ExistsEncrypted.php @@ -40,6 +40,6 @@ public function passes($attribute, $value): bool public function message(): string { - return 'The selected :attribute is invalid.'; + return __('validation.exists'); } } diff --git a/src/Rules/UniqueEncrypted.php b/src/Rules/UniqueEncrypted.php index 5fdd027..35f888a 100644 --- a/src/Rules/UniqueEncrypted.php +++ b/src/Rules/UniqueEncrypted.php @@ -40,6 +40,6 @@ public function passes($attribute, $value): bool public function message(): string { - return 'The :attribute has already been taken.'; + return __('validation.unique'); } } From e77e397101d9d50e5ba82e6bc21e678c3e02a665 Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Sun, 19 Oct 2025 12:13:19 +0200 Subject: [PATCH 2/6] ADD laravel 12 e php 8.4 support --- .github/workflows/run-tests.yml | 11 +++++++++-- composer.json | 14 +++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d67827d..f807d8e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,10 +13,13 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.3, 8.2, 8.1, 8.0] - laravel: [11.*, 10.*, 9.*] + php: [8.4, 8.3, 8.2, 8.1, 8.0] + laravel: [12.*, 11.*, 10.*, 9.*] stability: [prefer-lowest, prefer-stable] include: + - laravel: 12.* + testbench: 10.* + carbon: ^3.0 - laravel: 11.* testbench: 9.* carbon: ^3.0 @@ -33,6 +36,10 @@ jobs: php: 8.1 - laravel: 11.* php: 8.0 + - laravel: 12.* + php: 8.1 + - laravel: 12.* + php: 8.0 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index 2c53119..60b7b3d 100644 --- a/composer.json +++ b/composer.json @@ -25,17 +25,17 @@ "require": { "php": "^8.0", "ext-openssl": "*", - "illuminate/contracts": "^9.0|^10.0|^11.0", - "illuminate/database": "^9.0|^10.0|^11.0", - "illuminate/support": "^9.0|^10.0|^11.0", - "illuminate/validation": "^9.0|^10.0|^11.0", + "illuminate/contracts": "^9.0|^10.0|^11.0|^12.0", + "illuminate/database": "^9.0|^10.0|^11.0|^12.0", + "illuminate/support": "^9.0|^10.0|^11.0|^12.0", + "illuminate/validation": "^9.0|^10.0|^11.0|^12.0", "spatie/laravel-package-tools": "^1.14.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.4", - "orchestra/testbench": "^7.0|^8.0|^9.0", - "phpunit/phpunit": "^9.5|^10.5", - "vimeo/psalm": "^4.20|^5.22" + "orchestra/testbench": "^7.0|^8.0|^9.0|^10.0", + "phpunit/phpunit": "^9.5|^10.5|^11.0", + "vimeo/psalm": "^4.20|^5.22|^6.0" }, "autoload": { "psr-4": { From edf93d811fac5793266e1c5c5d0ceccb9dabd455 Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Sun, 19 Oct 2025 15:20:45 +0200 Subject: [PATCH 3/6] wip --- .github/workflows/run-tests.yml | 21 ++------------------- composer.json | 16 ++++++++-------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index f807d8e..70be062 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,8 +13,8 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.4, 8.3, 8.2, 8.1, 8.0] - laravel: [12.*, 11.*, 10.*, 9.*] + php: [8.4, 8.3, 8.2] + laravel: [12.*, 11.*] stability: [prefer-lowest, prefer-stable] include: - laravel: 12.* @@ -23,23 +23,6 @@ jobs: - laravel: 11.* testbench: 9.* carbon: ^3.0 - - laravel: 10.* - testbench: 8.* - carbon: ^2.63 - - laravel: 9.* - testbench: 7.* - carbon: ^2.63 - exclude: - - laravel: 10.* - php: 8.0 - - laravel: 11.* - php: 8.1 - - laravel: 11.* - php: 8.0 - - laravel: 12.* - php: 8.1 - - laravel: 12.* - php: 8.0 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index 60b7b3d..b54a525 100644 --- a/composer.json +++ b/composer.json @@ -23,19 +23,19 @@ } ], "require": { - "php": "^8.0", + "php": "^8.2", "ext-openssl": "*", - "illuminate/contracts": "^9.0|^10.0|^11.0|^12.0", - "illuminate/database": "^9.0|^10.0|^11.0|^12.0", - "illuminate/support": "^9.0|^10.0|^11.0|^12.0", - "illuminate/validation": "^9.0|^10.0|^11.0|^12.0", + "illuminate/contracts": "^11.0|^12.0", + "illuminate/database": "^11.0|^12.0", + "illuminate/support": "^11.0|^12.0", + "illuminate/validation": "^11.0|^12.0", "spatie/laravel-package-tools": "^1.14.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.4", - "orchestra/testbench": "^7.0|^8.0|^9.0|^10.0", - "phpunit/phpunit": "^9.5|^10.5|^11.0", - "vimeo/psalm": "^4.20|^5.22|^6.0" + "orchestra/testbench": "^9.0|^10.0", + "phpunit/phpunit": "^10.5|^11.0", + "vimeo/psalm": "^5.22|^6.0" }, "autoload": { "psr-4": { From 90d8be5b5ac9c872087501274aa7e96585ac2345 Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Sun, 19 Oct 2025 15:35:38 +0200 Subject: [PATCH 4/6] wip --- .github/workflows/run-tests.yml | 25 ++++--- composer.json | 14 ++-- tests/DBEncrypterTest.php | 26 +++---- tests/EncryptableTest.php | 79 ++++++++------------- tests/EncrypterTest.php | 30 +++----- tests/ExistsEncryptedTest.php | 46 +++++------- tests/PHPEncrypterTest.php | 77 +++++++-------------- tests/Pest.php | 16 +++++ tests/SerializerTest.php | 119 ++++++++++++-------------------- tests/TestCase.php | 2 +- tests/UniqueEncryptedTest.php | 46 +++++------- 11 files changed, 204 insertions(+), 276 deletions(-) create mode 100644 tests/Pest.php diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 70be062..0b2e515 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -2,13 +2,21 @@ name: run-tests on: push: - branches: [main] - pull_request: - branches: [main] + paths: + - '**.php' + - '.github/workflows/run-tests.yml' + - 'phpunit.xml.dist' + - 'composer.json' + - 'composer.lock' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: test: runs-on: ${{ matrix.os }} + timeout-minutes: 5 strategy: fail-fast: true matrix: @@ -19,16 +27,14 @@ jobs: include: - laravel: 12.* testbench: 10.* - carbon: ^3.0 - laravel: 11.* testbench: 9.* - carbon: ^3.0 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -44,8 +50,11 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.stability }} --prefer-dist --no-interaction + - name: List Installed Dependencies + run: composer show -D + - name: Execute tests - run: vendor/bin/phpunit + run: vendor/bin/pest --ci \ No newline at end of file diff --git a/composer.json b/composer.json index b54a525..7993c81 100644 --- a/composer.json +++ b/composer.json @@ -29,11 +29,14 @@ "illuminate/database": "^11.0|^12.0", "illuminate/support": "^11.0|^12.0", "illuminate/validation": "^11.0|^12.0", + "laravel/framework": "11.*", + "orchestra/testbench": "9.*", "spatie/laravel-package-tools": "^1.14.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.4", - "orchestra/testbench": "^9.0|^10.0", + "pestphp/pest": "^3.8", + "pestphp/pest-plugin-laravel": "^3.2", "phpunit/phpunit": "^10.5|^11.0", "vimeo/psalm": "^5.22|^6.0" }, @@ -50,11 +53,14 @@ "scripts": { "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes", "psalm": "vendor/bin/psalm", - "test": "vendor/bin/phpunit --colors=always", - "test-coverage": "vendor/bin/phpunit --coverage-html coverage" + "test": "vendor/bin/pest", + "test-coverage": "vendor/bin/pest --coverage" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true + } }, "extra": { "laravel": { diff --git a/tests/DBEncrypterTest.php b/tests/DBEncrypterTest.php index a6f474b..5cfee96 100644 --- a/tests/DBEncrypterTest.php +++ b/tests/DBEncrypterTest.php @@ -1,25 +1,17 @@ expectException(EncryptException::class); - Encryption::db()->encrypt('test'); - } +it('should throw exception on db encrypt', function () { + $this->expectException(EncryptException::class); + + Encryption::db()->encrypt('test'); +}); - /** @test */ - public function it_should_return_query_on_db_decrypt() - { - $query = Encryption::db()->decrypt('test'); +it('should return query on db decrypt', function () { + $query = Encryption::db()->decrypt('test'); - $this->assertIsString($query); - } -} + expect($query)->toBeString(); +}); diff --git a/tests/EncryptableTest.php b/tests/EncryptableTest.php index 61bc501..ecd5f70 100644 --- a/tests/EncryptableTest.php +++ b/tests/EncryptableTest.php @@ -1,69 +1,50 @@ createUser(); - $this->assertDatabaseCount($user->getTable(), 1); +it('should encrypt data when saving model instance', function () { + $user = $this->createUser(); + + $this->assertDatabaseCount($user->getTable(), 1); - $userRaw = DB::table($user->getTable()) - ->select('*') - ->where('id', $user->getKey()) - ->first(); + $userRaw = DB::table($user->getTable()) + ->select('*') + ->where('id', $user->getKey()) + ->first(); - $this->assertTrue( - Encryption::isEncrypted($userRaw->first_name) - ); + expect(Encryption::isEncrypted($userRaw->first_name))->toBeTrue(); - $this->assertTrue( - Encryption::isEncrypted($userRaw->last_name) - ); - } + expect(Encryption::isEncrypted($userRaw->last_name))->toBeTrue(); +}); - /** @test */ - public function it_should_encrypt_data_when_updating_model_instance() - { - $user = $this->createUser(); +it('should encrypt data when updating model instance', function () { + $user = $this->createUser(); - $user->update([ - 'first_name' => 'Test', - ]); + $user->update([ + 'first_name' => 'Test', + ]); - $userRaw = DB::table($user->getTable()) - ->select('*') - ->where('id', $user->getKey()) - ->first(); + $userRaw = DB::table($user->getTable()) + ->select('*') + ->where('id', $user->getKey()) + ->first(); - $this->assertTrue( - Encryption::isEncrypted($userRaw->first_name) - ); + expect(Encryption::isEncrypted($userRaw->first_name))->toBeTrue(); - $this->assertEquals( - 'Test', - Encryption::php()->decrypt($userRaw->first_name) - ); - } + expect(Encryption::php()->decrypt($userRaw->first_name))->toEqual('Test'); +}); - /** @test */ - public function it_should_decrypt_data_when_retrieving_models() - { - $user = $this->createUser(); +it('should decrypt data when retrieving models', function () { + $user = $this->createUser(); - $this->assertDatabaseCount($user->getTable(), 1); + $this->assertDatabaseCount($user->getTable(), 1); - $user = User::findOrFail($user->getKey()); + $user = User::findOrFail($user->getKey()); - $this->assertEquals('Name', $user->first_name); + expect($user->first_name)->toEqual('Name'); - $this->assertEquals('Surname', $user->last_name); - } -} + expect($user->last_name)->toEqual('Surname'); +}); diff --git a/tests/EncrypterTest.php b/tests/EncrypterTest.php index f720a3c..b37bdc9 100644 --- a/tests/EncrypterTest.php +++ b/tests/EncrypterTest.php @@ -1,30 +1,22 @@ set('encryptable.key', null); - $this->expectException(MissingEncryptionKeyException::class); +it('should throw exception when encryption key is missing', function () { + config()->set('encryptable.key', null); + + $this->expectException(MissingEncryptionKeyException::class); - Encryption::php()->encrypt('test'); - } + Encryption::php()->encrypt('test'); +}); - /** @test */ - public function it_should_throw_exception_when_encryption_cipher_is_missing() - { - config()->set('encryptable.cipher', null); +it('should throw exception when encryption cipher is missing', function () { + config()->set('encryptable.cipher', null); - $this->expectException(MissingEncryptionCipherException::class); + $this->expectException(MissingEncryptionCipherException::class); - Encryption::db()->decrypt('test'); - } -} + Encryption::db()->decrypt('test'); +}); diff --git a/tests/ExistsEncryptedTest.php b/tests/ExistsEncryptedTest.php index 13b5101..b59c10f 100644 --- a/tests/ExistsEncryptedTest.php +++ b/tests/ExistsEncryptedTest.php @@ -1,40 +1,32 @@ createUser(); - $validationFails = Validator::make($user->toArray(), [ - 'first_name' => 'exists:users', - ])->fails(); +it('should validate encrypted data with custom exists rule', function () { + $user = $this->createUser(); + + $validationFails = Validator::make($user->toArray(), [ + 'first_name' => 'exists:users', + ])->fails(); - $this->assertTrue($validationFails); + expect($validationFails)->toBeTrue(); - $validationFails = Validator::make($user->toArray(), [ - 'first_name' => new ExistsEncrypted('users'), - ])->fails(); + $validationFails = Validator::make($user->toArray(), [ + 'first_name' => new ExistsEncrypted('users'), + ])->fails(); - $this->assertFalse($validationFails); - } + expect($validationFails)->toBeFalse(); +}); - /** @test */ - public function it_should_have_rule_macro() - { - $user = $this->createUser(); +it('should have rule macro', function () { + $user = $this->createUser(); - $validationFails = Validator::make($user->toArray(), [ - 'first_name' => Rule::existsEncrypted('users'), - ])->fails(); + $validationFails = Validator::make($user->toArray(), [ + 'first_name' => Rule::existsEncrypted('users'), + ])->fails(); - $this->assertFalse($validationFails); - } -} + expect($validationFails)->toBeFalse(); +}); diff --git a/tests/PHPEncrypterTest.php b/tests/PHPEncrypterTest.php index 27b2b12..799df03 100644 --- a/tests/PHPEncrypterTest.php +++ b/tests/PHPEncrypterTest.php @@ -1,55 +1,30 @@ encrypt('test'); - - $this->assertEquals( - $value, - Encryption::php()->encrypt($value) - ); - } - - /** @test */ - public function it_should_return_a_string_when_encrypting_value() - { - $value = Encryption::php()->encrypt('test'); - - $this->assertIsString($value); - - $this->assertTrue( - Encryption::isEncrypted($value) - ); - } - - /** @test */ - public function it_should_not_decrypt_an_unencrypted_value() - { - $this->assertEquals( - 'test', - Encryption::php()->decrypt('test') - ); - } - - /** @test */ - public function it_should_return_value_when_decrypting_value() - { - $value = Encryption::php()->encrypt(false); - - $this->assertIsBool( - Encryption::php()->decrypt($value) - ); - - $this->assertEquals( - false, - Encryption::php()->decrypt($value) - ); - } -} + +it('should not encrypt already encrypted value', function () { + $value = Encryption::php()->encrypt('test'); + + expect(Encryption::php()->encrypt($value))->toEqual($value); +}); + +it('should return a string when encrypting value', function () { + $value = Encryption::php()->encrypt('test'); + + expect($value)->toBeString(); + + expect(Encryption::isEncrypted($value))->toBeTrue(); +}); + +it('should not decrypt an unencrypted value', function () { + expect(Encryption::php()->decrypt('test'))->toEqual('test'); +}); + +it('should return value when decrypting value', function () { + $value = Encryption::php()->encrypt(false); + + expect(Encryption::php()->decrypt($value))->toBeBool(); + + expect(Encryption::php()->decrypt($value))->toEqual(false); +}); diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..625f9e4 --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,16 @@ +extend(TestCase::class)->in(__DIR__); diff --git a/tests/SerializerTest.php b/tests/SerializerTest.php index 4e7e52a..cdd1251 100644 --- a/tests/SerializerTest.php +++ b/tests/SerializerTest.php @@ -1,79 +1,52 @@ expectException(SerializationException::class); - - Serializer::serialize(['test array']); - } - - /** @test */ - public function it_should_serialize_all_supported_values() - { - $this->assertEquals( - 'string:test', - Serializer::serialize('test') - ); - - $this->assertEquals( - 'string:test:test', - Serializer::serialize('test:test') - ); - - $this->assertEquals( - 'integer:1', - Serializer::serialize(1) - ); - - $this->assertEquals( - 'double:1.3', - Serializer::serialize(1.3) - ); - - $this->assertEquals( - 'boolean:1', - Serializer::serialize(true) - ); - } - - /** @test */ - public function it_should_throw_exception_when_unserializing_invalid_value() - { - $this->expectException(UnserializationException::class); - - Serializer::unserialize('test'); - } - - /** @test */ - public function it_should_unserialize_all_supported_values() - { - $string = Serializer::unserialize('string:test'); - $this->assertIsString($string); - $this->assertEquals('test', $string); - - $string = Serializer::unserialize('string:test:test'); - $this->assertIsString($string); - $this->assertEquals('test:test', $string); - - $integer = Serializer::unserialize('integer:1'); - $this->assertIsInt($integer); - $this->assertEquals(1, $integer); - - $double = Serializer::unserialize('double:1.3'); - $this->assertIsFloat($double); - $this->assertEquals(1.3, $double); - - $boolean = Serializer::unserialize('boolean:1'); - $this->assertIsBool($boolean); - $this->assertEquals(true, $boolean); - } -} + +it('should throw exception when serializing unsupported type', function () { + $this->expectException(SerializationException::class); + + Serializer::serialize(['test array']); +}); + +it('should serialize all supported values', function () { + expect(Serializer::serialize('test'))->toEqual('string:test'); + + expect(Serializer::serialize('test:test'))->toEqual('string:test:test'); + + expect(Serializer::serialize(1))->toEqual('integer:1'); + + expect(Serializer::serialize(1.3))->toEqual('double:1.3'); + + expect(Serializer::serialize(true))->toEqual('boolean:1'); +}); + +it('should throw exception when unserializing invalid value', function () { + $this->expectException(UnserializationException::class); + + Serializer::unserialize('test'); +}); + +it('should unserialize all supported values', function () { + $string = Serializer::unserialize('string:test'); + expect($string)->toBeString(); + expect($string)->toEqual('test'); + + $string = Serializer::unserialize('string:test:test'); + expect($string)->toBeString(); + expect($string)->toEqual('test:test'); + + $integer = Serializer::unserialize('integer:1'); + expect($integer)->toBeInt(); + expect($integer)->toEqual(1); + + $double = Serializer::unserialize('double:1.3'); + expect($double)->toBeFloat(); + expect($double)->toEqual(1.3); + + $boolean = Serializer::unserialize('boolean:1'); + expect($boolean)->toBeBool(); + expect($boolean)->toEqual(true); +}); diff --git a/tests/TestCase.php b/tests/TestCase.php index a9461e4..53b0df8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,7 +9,7 @@ class TestCase extends Orchestra { - public function setUp(): void + protected function setUp(): void { parent::setUp(); diff --git a/tests/UniqueEncryptedTest.php b/tests/UniqueEncryptedTest.php index 2302795..3a753cc 100644 --- a/tests/UniqueEncryptedTest.php +++ b/tests/UniqueEncryptedTest.php @@ -1,40 +1,32 @@ createUser(); - $validationFails = Validator::make($user->toArray(), [ - 'first_name' => 'unique:users', - ])->fails(); +it('should validate encrypted data with custom unique rule', function () { + $user = $this->createUser(); + + $validationFails = Validator::make($user->toArray(), [ + 'first_name' => 'unique:users', + ])->fails(); - $this->assertFalse($validationFails); + expect($validationFails)->toBeFalse(); - $validationFails = Validator::make($user->toArray(), [ - 'first_name' => new UniqueEncrypted('users'), - ])->fails(); + $validationFails = Validator::make($user->toArray(), [ + 'first_name' => new UniqueEncrypted('users'), + ])->fails(); - $this->assertTrue($validationFails); - } + expect($validationFails)->toBeTrue(); +}); - /** @test */ - public function it_should_have_rule_macro() - { - $user = $this->createUser(); +it('should have rule macro', function () { + $user = $this->createUser(); - $validationFails = Validator::make($user->toArray(), [ - 'first_name' => Rule::uniqueEncrypted('users'), - ])->fails(); + $validationFails = Validator::make($user->toArray(), [ + 'first_name' => Rule::uniqueEncrypted('users'), + ])->fails(); - $this->assertTrue($validationFails); - } -} + expect($validationFails)->toBeTrue(); +}); From 379961fbc7a393ae69fb4a466afa8301ae0c3334 Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Sun, 19 Oct 2025 15:42:14 +0200 Subject: [PATCH 5/6] wip --- .../workflows/fix-php-code-style-issues.yml | 28 +++++++++++++++ .github/workflows/php-cs-fixer.yml | 23 ------------ .php-cs-fixer.dist.php | 35 ------------------- composer.json | 7 ++-- src/Encrypter.php | 4 +-- src/Utils/Serializer.php | 6 ++-- tests/DBEncrypterTest.php | 1 - tests/EncryptableTest.php | 1 - tests/EncrypterTest.php | 1 - tests/ExistsEncryptedTest.php | 1 - tests/PHPEncrypterTest.php | 1 - tests/SerializerTest.php | 1 - tests/TestCase.php | 2 +- tests/UniqueEncryptedTest.php | 1 - 14 files changed, 37 insertions(+), 75 deletions(-) create mode 100644 .github/workflows/fix-php-code-style-issues.yml delete mode 100644 .github/workflows/php-cs-fixer.yml delete mode 100644 .php-cs-fixer.dist.php diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml new file mode 100644 index 0000000..f30644a --- /dev/null +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -0,0 +1,28 @@ +name: Fix PHP code style issues + +on: + push: + paths: + - '**.php' + +permissions: + contents: write + +jobs: + php-code-styling: + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Checkout code + uses: actions/checkout@v5 + with: + ref: ${{ github.head_ref }} + + - name: Fix PHP code style issues + uses: aglipanci/laravel-pint-action@2.6 + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v6 + with: + commit_message: Fix styling diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml deleted file mode 100644 index 96e9a2d..0000000 --- a/.github/workflows/php-cs-fixer.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Check & fix styling - -on: [push] - -jobs: - php-cs-fixer: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - - name: Run PHP CS Fixer - uses: docker://oskarstark/php-cs-fixer-ga - with: - args: --config=.php-cs-fixer.dist.php --allow-risky=yes - - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v5 - with: - commit_message: Fix styling diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php deleted file mode 100644 index d612a54..0000000 --- a/.php-cs-fixer.dist.php +++ /dev/null @@ -1,35 +0,0 @@ -in([ - __DIR__ . '/src', - __DIR__ . '/tests', - ]) - ->name('*.php') - ->notName('*.blade.php') - ->ignoreDotFiles(true) - ->ignoreVCS(true); - -return (new PhpCsFixer\Config()) - ->setRules([ - '@PSR2' => true, - 'array_syntax' => ['syntax' => 'short'], - 'ordered_imports' => ['sort_algorithm' => 'alpha'], - 'no_unused_imports' => true, - 'not_operator_with_successor_space' => true, - 'trailing_comma_in_multiline' => true, - 'phpdoc_scalar' => true, - 'unary_operator_spaces' => true, - 'binary_operator_spaces' => true, - 'blank_line_before_statement' => [ - 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], - ], - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_var_without_name' => true, - 'method_argument_space' => [ - 'on_multiline' => 'ensure_fully_multiline', - 'keep_multiple_spaces_after_comma' => true, - ], - 'single_trait_insert_per_statement' => true, - ]) - ->setFinder($finder); diff --git a/composer.json b/composer.json index 7993c81..13f0572 100644 --- a/composer.json +++ b/composer.json @@ -29,12 +29,11 @@ "illuminate/database": "^11.0|^12.0", "illuminate/support": "^11.0|^12.0", "illuminate/validation": "^11.0|^12.0", - "laravel/framework": "11.*", - "orchestra/testbench": "9.*", "spatie/laravel-package-tools": "^1.14.1" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.4", + "laravel/pint": "^1.25", + "orchestra/testbench": "^9.0|^10.0", "pestphp/pest": "^3.8", "pestphp/pest-plugin-laravel": "^3.2", "phpunit/phpunit": "^10.5|^11.0", @@ -51,7 +50,7 @@ } }, "scripts": { - "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes", + "format": "vendor/bin/pint", "psalm": "vendor/bin/psalm", "test": "vendor/bin/pest", "test-coverage": "vendor/bin/pest --coverage" diff --git a/src/Encrypter.php b/src/Encrypter.php index bbb92c5..f6e41b4 100644 --- a/src/Encrypter.php +++ b/src/Encrypter.php @@ -18,7 +18,7 @@ protected function getEncryptionKey(): string $key = config('encryptable.key'); if (empty($key)) { - throw new MissingEncryptionKeyException(); + throw new MissingEncryptionKeyException; } return (string) $key; @@ -29,7 +29,7 @@ protected function getEncryptionCipher(): string $cipher = config('encryptable.cipher'); if (empty($cipher)) { - throw new MissingEncryptionCipherException(); + throw new MissingEncryptionCipherException; } return (string) $cipher; diff --git a/src/Utils/Serializer.php b/src/Utils/Serializer.php index a4aba05..0891c67 100644 --- a/src/Utils/Serializer.php +++ b/src/Utils/Serializer.php @@ -19,7 +19,7 @@ public static function serialize($value): string $valueType = gettype($value); if (! in_array($valueType, self::SUPPORTED_TYPES)) { - throw new SerializationException(); + throw new SerializationException; } $value = strval($value); @@ -32,13 +32,13 @@ public static function unserialize(string $payload) $payload = explode(':', $payload, 2); if (count($payload) !== 2) { - throw new UnserializationException(); + throw new UnserializationException; } [$valueType, $value] = $payload; if (! settype($value, $valueType)) { - throw new UnserializationException(); + throw new UnserializationException; } return $value; diff --git a/tests/DBEncrypterTest.php b/tests/DBEncrypterTest.php index 5cfee96..feadb7b 100644 --- a/tests/DBEncrypterTest.php +++ b/tests/DBEncrypterTest.php @@ -3,7 +3,6 @@ use Illuminate\Contracts\Encryption\EncryptException; use Maize\Encryptable\Encryption; - it('should throw exception on db encrypt', function () { $this->expectException(EncryptException::class); diff --git a/tests/EncryptableTest.php b/tests/EncryptableTest.php index ecd5f70..1a38aa3 100644 --- a/tests/EncryptableTest.php +++ b/tests/EncryptableTest.php @@ -4,7 +4,6 @@ use Maize\Encryptable\Encryption; use Maize\Encryptable\Tests\Models\User; - it('should encrypt data when saving model instance', function () { $user = $this->createUser(); diff --git a/tests/EncrypterTest.php b/tests/EncrypterTest.php index b37bdc9..7383025 100644 --- a/tests/EncrypterTest.php +++ b/tests/EncrypterTest.php @@ -4,7 +4,6 @@ use Maize\Encryptable\Exceptions\MissingEncryptionCipherException; use Maize\Encryptable\Exceptions\MissingEncryptionKeyException; - it('should throw exception when encryption key is missing', function () { config()->set('encryptable.key', null); diff --git a/tests/ExistsEncryptedTest.php b/tests/ExistsEncryptedTest.php index b59c10f..70668db 100644 --- a/tests/ExistsEncryptedTest.php +++ b/tests/ExistsEncryptedTest.php @@ -4,7 +4,6 @@ use Illuminate\Validation\Rule; use Maize\Encryptable\Rules\ExistsEncrypted; - it('should validate encrypted data with custom exists rule', function () { $user = $this->createUser(); diff --git a/tests/PHPEncrypterTest.php b/tests/PHPEncrypterTest.php index 799df03..e039676 100644 --- a/tests/PHPEncrypterTest.php +++ b/tests/PHPEncrypterTest.php @@ -2,7 +2,6 @@ use Maize\Encryptable\Encryption; - it('should not encrypt already encrypted value', function () { $value = Encryption::php()->encrypt('test'); diff --git a/tests/SerializerTest.php b/tests/SerializerTest.php index cdd1251..f2a982a 100644 --- a/tests/SerializerTest.php +++ b/tests/SerializerTest.php @@ -4,7 +4,6 @@ use Maize\Encryptable\Exceptions\UnserializationException; use Maize\Encryptable\Utils\Serializer; - it('should throw exception when serializing unsupported type', function () { $this->expectException(SerializationException::class); diff --git a/tests/TestCase.php b/tests/TestCase.php index 53b0df8..3627e9e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -49,7 +49,7 @@ protected function setUpDatabase($app) public function createUser(array $attrs = []) { - $user = new User(); + $user = new User; $user->forceFill(array_merge([ 'first_name' => 'Name', diff --git a/tests/UniqueEncryptedTest.php b/tests/UniqueEncryptedTest.php index 3a753cc..d00c2d7 100644 --- a/tests/UniqueEncryptedTest.php +++ b/tests/UniqueEncryptedTest.php @@ -4,7 +4,6 @@ use Illuminate\Validation\Rule; use Maize\Encryptable\Rules\UniqueEncrypted; - it('should validate encrypted data with custom unique rule', function () { $user = $this->createUser(); From 0d82b8462b1530c34427a3c3d58562e9bb9c114c Mon Sep 17 00:00:00 2001 From: enricodelazzari Date: Sun, 19 Oct 2025 15:59:58 +0200 Subject: [PATCH 6/6] wip --- .editorconfig | 4 ++-- .gitattributes | 9 +++++++- .github/workflows/phpstan.yml | 28 ++++++++++++++++++++++++ .github/workflows/psalm.yml | 33 ---------------------------- .gitignore | 41 +++++++++++++++++++++++++---------- composer.json | 6 ++--- phpstan-baseline.neon | 0 psalm.xml.dist | 16 -------------- src/Encryption.php | 4 ++-- 9 files changed, 72 insertions(+), 69 deletions(-) create mode 100644 .github/workflows/phpstan.yml delete mode 100644 .github/workflows/psalm.yml create mode 100644 phpstan-baseline.neon delete mode 100644 psalm.xml.dist diff --git a/.editorconfig b/.editorconfig index a7c44dd..c82b426 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,9 +2,9 @@ root = true [*] charset = utf-8 +end_of_line = lf indent_size = 4 indent_style = space -end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true @@ -12,4 +12,4 @@ trim_trailing_whitespace = true trim_trailing_whitespace = false [*.{yml,yaml}] -indent_size = 2 +indent_size = 2 \ No newline at end of file diff --git a/.gitattributes b/.gitattributes index 99a9952..ae436e4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,8 +6,15 @@ /.gitattributes export-ignore /.gitignore export-ignore /phpunit.xml.dist export-ignore +/art export-ignore +/docs export-ignore /tests export-ignore +/workbench export-ignore /.editorconfig export-ignore -/.php_cs.dist export-ignore +/.php_cs.dist.php export-ignore /psalm.xml export-ignore /psalm.xml.dist export-ignore +/testbench.yaml export-ignore +/UPGRADING.md export-ignore +/phpstan.neon.dist export-ignore +/phpstan-baseline.neon export-ignore \ No newline at end of file diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..6f7b974 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,28 @@ +name: PHPStan + +on: + push: + paths: + - '**.php' + - 'phpstan.neon.dist' + - '.github/workflows/phpstan.yml' + +jobs: + phpstan: + name: phpstan + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v5 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + coverage: none + + - name: Install composer dependencies + uses: ramsey/composer-install@v3 + + - name: Run PHPStan + run: ./vendor/bin/phpstan --error-format=github diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml deleted file mode 100644 index 448cb34..0000000 --- a/.github/workflows/psalm.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Psalm - -on: - push: - paths: - - '**.php' - - 'psalm.xml.dist' - -jobs: - psalm: - name: psalm - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.0' - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick - coverage: none - - - name: Cache composer dependencies - uses: actions/cache@v4 - with: - path: vendor - key: composer-${{ hashFiles('composer.lock') }} - - - name: Run composer install - run: composer install -n --prefer-dist - - - name: Run psalm - run: ./vendor/bin/psalm --output-format=github diff --git a/.gitignore b/.gitignore index e6987cc..421a237 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,32 @@ -.idea -.php_cs -.php_cs.cache -.phpunit.result.cache -build +# Composer Related composer.lock -coverage -docs +/vendor + +# Frontend Assets +/node_modules + +# Logs +npm-debug.log +yarn-error.log + +# Caches +.phpunit.cache +.phpunit.result.cache +/build + +# IDE Helper +_ide_helper.php +_ide_helper_models.php +.phpstorm.meta.php + +# Editors +/.idea +/.fleet +/.vscode + +# Misc phpunit.xml -psalm.xml +phpstan.neon testbench.yaml -vendor -node_modules -.php-cs-fixer.cache -.phpunit.cache/test-results +/docs +/coverage \ No newline at end of file diff --git a/composer.json b/composer.json index 13f0572..41b828e 100644 --- a/composer.json +++ b/composer.json @@ -32,12 +32,12 @@ "spatie/laravel-package-tools": "^1.14.1" }, "require-dev": { + "larastan/larastan": "^3.7", "laravel/pint": "^1.25", "orchestra/testbench": "^9.0|^10.0", "pestphp/pest": "^3.8", "pestphp/pest-plugin-laravel": "^3.2", - "phpunit/phpunit": "^10.5|^11.0", - "vimeo/psalm": "^5.22|^6.0" + "phpunit/phpunit": "^10.5|^11.0" }, "autoload": { "psr-4": { @@ -51,7 +51,7 @@ }, "scripts": { "format": "vendor/bin/pint", - "psalm": "vendor/bin/psalm", + "analyse": "vendor/bin/phpstan analyse", "test": "vendor/bin/pest", "test-coverage": "vendor/bin/pest --coverage" }, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..e69de29 diff --git a/psalm.xml.dist b/psalm.xml.dist deleted file mode 100644 index c6df33e..0000000 --- a/psalm.xml.dist +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - diff --git a/src/Encryption.php b/src/Encryption.php index 7176b1f..9f7d90c 100644 --- a/src/Encryption.php +++ b/src/Encryption.php @@ -13,14 +13,14 @@ public function __construct($encrypter) public static function php(): self { - return new static( + return new self( app(PHPEncrypter::class) ); } public static function db(): self { - return new static( + return new self( app(DBEncrypter::class) ); }