Skip to content

Commit 90d8be5

Browse files
wip
1 parent 4a30c64 commit 90d8be5

File tree

11 files changed

+204
-276
lines changed

11 files changed

+204
-276
lines changed

.github/workflows/run-tests.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ name: run-tests
22

33
on:
44
push:
5-
branches: [main]
6-
pull_request:
7-
branches: [main]
5+
paths:
6+
- '**.php'
7+
- '.github/workflows/run-tests.yml'
8+
- 'phpunit.xml.dist'
9+
- 'composer.json'
10+
- 'composer.lock'
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
815

916
jobs:
1017
test:
1118
runs-on: ${{ matrix.os }}
19+
timeout-minutes: 5
1220
strategy:
1321
fail-fast: true
1422
matrix:
@@ -19,16 +27,14 @@ jobs:
1927
include:
2028
- laravel: 12.*
2129
testbench: 10.*
22-
carbon: ^3.0
2330
- laravel: 11.*
2431
testbench: 9.*
25-
carbon: ^3.0
2632

2733
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2834

2935
steps:
3036
- name: Checkout code
31-
uses: actions/checkout@v4
37+
uses: actions/checkout@v5
3238

3339
- name: Setup PHP
3440
uses: shivammathur/setup-php@v2
@@ -44,8 +50,11 @@ jobs:
4450
4551
- name: Install dependencies
4652
run: |
47-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
53+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
4854
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
4955
56+
- name: List Installed Dependencies
57+
run: composer show -D
58+
5059
- name: Execute tests
51-
run: vendor/bin/phpunit
60+
run: vendor/bin/pest --ci

composer.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@
2929
"illuminate/database": "^11.0|^12.0",
3030
"illuminate/support": "^11.0|^12.0",
3131
"illuminate/validation": "^11.0|^12.0",
32+
"laravel/framework": "11.*",
33+
"orchestra/testbench": "9.*",
3234
"spatie/laravel-package-tools": "^1.14.1"
3335
},
3436
"require-dev": {
3537
"friendsofphp/php-cs-fixer": "^3.4",
36-
"orchestra/testbench": "^9.0|^10.0",
38+
"pestphp/pest": "^3.8",
39+
"pestphp/pest-plugin-laravel": "^3.2",
3740
"phpunit/phpunit": "^10.5|^11.0",
3841
"vimeo/psalm": "^5.22|^6.0"
3942
},
@@ -50,11 +53,14 @@
5053
"scripts": {
5154
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
5255
"psalm": "vendor/bin/psalm",
53-
"test": "vendor/bin/phpunit --colors=always",
54-
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
56+
"test": "vendor/bin/pest",
57+
"test-coverage": "vendor/bin/pest --coverage"
5558
},
5659
"config": {
57-
"sort-packages": true
60+
"sort-packages": true,
61+
"allow-plugins": {
62+
"pestphp/pest-plugin": true
63+
}
5864
},
5965
"extra": {
6066
"laravel": {

tests/DBEncrypterTest.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
<?php
22

3-
namespace Maize\Encryptable\Tests;
4-
53
use Illuminate\Contracts\Encryption\EncryptException;
64
use Maize\Encryptable\Encryption;
75

8-
class DBEncrypterTest extends TestCase
9-
{
10-
/** @test */
11-
public function it_should_throw_exception_on_db_encrypt()
12-
{
13-
$this->expectException(EncryptException::class);
146

15-
Encryption::db()->encrypt('test');
16-
}
7+
it('should throw exception on db encrypt', function () {
8+
$this->expectException(EncryptException::class);
9+
10+
Encryption::db()->encrypt('test');
11+
});
1712

18-
/** @test */
19-
public function it_should_return_query_on_db_decrypt()
20-
{
21-
$query = Encryption::db()->decrypt('test');
13+
it('should return query on db decrypt', function () {
14+
$query = Encryption::db()->decrypt('test');
2215

23-
$this->assertIsString($query);
24-
}
25-
}
16+
expect($query)->toBeString();
17+
});

tests/EncryptableTest.php

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,50 @@
11
<?php
22

3-
namespace Maize\Encryptable\Tests;
4-
53
use Illuminate\Support\Facades\DB;
64
use Maize\Encryptable\Encryption;
75
use Maize\Encryptable\Tests\Models\User;
86

9-
class EncryptableTest extends TestCase
10-
{
11-
/** @test */
12-
public function it_should_encrypt_data_when_saving_model_instance()
13-
{
14-
$user = $this->createUser();
157

16-
$this->assertDatabaseCount($user->getTable(), 1);
8+
it('should encrypt data when saving model instance', function () {
9+
$user = $this->createUser();
10+
11+
$this->assertDatabaseCount($user->getTable(), 1);
1712

18-
$userRaw = DB::table($user->getTable())
19-
->select('*')
20-
->where('id', $user->getKey())
21-
->first();
13+
$userRaw = DB::table($user->getTable())
14+
->select('*')
15+
->where('id', $user->getKey())
16+
->first();
2217

23-
$this->assertTrue(
24-
Encryption::isEncrypted($userRaw->first_name)
25-
);
18+
expect(Encryption::isEncrypted($userRaw->first_name))->toBeTrue();
2619

27-
$this->assertTrue(
28-
Encryption::isEncrypted($userRaw->last_name)
29-
);
30-
}
20+
expect(Encryption::isEncrypted($userRaw->last_name))->toBeTrue();
21+
});
3122

32-
/** @test */
33-
public function it_should_encrypt_data_when_updating_model_instance()
34-
{
35-
$user = $this->createUser();
23+
it('should encrypt data when updating model instance', function () {
24+
$user = $this->createUser();
3625

37-
$user->update([
38-
'first_name' => 'Test',
39-
]);
26+
$user->update([
27+
'first_name' => 'Test',
28+
]);
4029

41-
$userRaw = DB::table($user->getTable())
42-
->select('*')
43-
->where('id', $user->getKey())
44-
->first();
30+
$userRaw = DB::table($user->getTable())
31+
->select('*')
32+
->where('id', $user->getKey())
33+
->first();
4534

46-
$this->assertTrue(
47-
Encryption::isEncrypted($userRaw->first_name)
48-
);
35+
expect(Encryption::isEncrypted($userRaw->first_name))->toBeTrue();
4936

50-
$this->assertEquals(
51-
'Test',
52-
Encryption::php()->decrypt($userRaw->first_name)
53-
);
54-
}
37+
expect(Encryption::php()->decrypt($userRaw->first_name))->toEqual('Test');
38+
});
5539

56-
/** @test */
57-
public function it_should_decrypt_data_when_retrieving_models()
58-
{
59-
$user = $this->createUser();
40+
it('should decrypt data when retrieving models', function () {
41+
$user = $this->createUser();
6042

61-
$this->assertDatabaseCount($user->getTable(), 1);
43+
$this->assertDatabaseCount($user->getTable(), 1);
6244

63-
$user = User::findOrFail($user->getKey());
45+
$user = User::findOrFail($user->getKey());
6446

65-
$this->assertEquals('Name', $user->first_name);
47+
expect($user->first_name)->toEqual('Name');
6648

67-
$this->assertEquals('Surname', $user->last_name);
68-
}
69-
}
49+
expect($user->last_name)->toEqual('Surname');
50+
});

tests/EncrypterTest.php

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
<?php
22

3-
namespace Maize\Encryptable\Tests;
4-
53
use Maize\Encryptable\Encryption;
64
use Maize\Encryptable\Exceptions\MissingEncryptionCipherException;
75
use Maize\Encryptable\Exceptions\MissingEncryptionKeyException;
86

9-
class EncrypterTest extends TestCase
10-
{
11-
/** @test */
12-
public function it_should_throw_exception_when_encryption_key_is_missing()
13-
{
14-
config()->set('encryptable.key', null);
157

16-
$this->expectException(MissingEncryptionKeyException::class);
8+
it('should throw exception when encryption key is missing', function () {
9+
config()->set('encryptable.key', null);
10+
11+
$this->expectException(MissingEncryptionKeyException::class);
1712

18-
Encryption::php()->encrypt('test');
19-
}
13+
Encryption::php()->encrypt('test');
14+
});
2015

21-
/** @test */
22-
public function it_should_throw_exception_when_encryption_cipher_is_missing()
23-
{
24-
config()->set('encryptable.cipher', null);
16+
it('should throw exception when encryption cipher is missing', function () {
17+
config()->set('encryptable.cipher', null);
2518

26-
$this->expectException(MissingEncryptionCipherException::class);
19+
$this->expectException(MissingEncryptionCipherException::class);
2720

28-
Encryption::db()->decrypt('test');
29-
}
30-
}
21+
Encryption::db()->decrypt('test');
22+
});

tests/ExistsEncryptedTest.php

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
11
<?php
22

3-
namespace Maize\Encryptable\Tests;
4-
53
use Illuminate\Support\Facades\Validator;
64
use Illuminate\Validation\Rule;
75
use Maize\Encryptable\Rules\ExistsEncrypted;
86

9-
class ExistsEncryptedTest extends TestCase
10-
{
11-
/** @test */
12-
public function it_should_validate_encrypted_data_with_custom_exists_rule()
13-
{
14-
$user = $this->createUser();
157

16-
$validationFails = Validator::make($user->toArray(), [
17-
'first_name' => 'exists:users',
18-
])->fails();
8+
it('should validate encrypted data with custom exists rule', function () {
9+
$user = $this->createUser();
10+
11+
$validationFails = Validator::make($user->toArray(), [
12+
'first_name' => 'exists:users',
13+
])->fails();
1914

20-
$this->assertTrue($validationFails);
15+
expect($validationFails)->toBeTrue();
2116

22-
$validationFails = Validator::make($user->toArray(), [
23-
'first_name' => new ExistsEncrypted('users'),
24-
])->fails();
17+
$validationFails = Validator::make($user->toArray(), [
18+
'first_name' => new ExistsEncrypted('users'),
19+
])->fails();
2520

26-
$this->assertFalse($validationFails);
27-
}
21+
expect($validationFails)->toBeFalse();
22+
});
2823

29-
/** @test */
30-
public function it_should_have_rule_macro()
31-
{
32-
$user = $this->createUser();
24+
it('should have rule macro', function () {
25+
$user = $this->createUser();
3326

34-
$validationFails = Validator::make($user->toArray(), [
35-
'first_name' => Rule::existsEncrypted('users'),
36-
])->fails();
27+
$validationFails = Validator::make($user->toArray(), [
28+
'first_name' => Rule::existsEncrypted('users'),
29+
])->fails();
3730

38-
$this->assertFalse($validationFails);
39-
}
40-
}
31+
expect($validationFails)->toBeFalse();
32+
});

0 commit comments

Comments
 (0)