Skip to content

Commit 93b7c1b

Browse files
committed
develop/v0.1.0: Added more documentation and created a few Unit tests
1 parent 882e8bb commit 93b7c1b

File tree

10 files changed

+281
-40
lines changed

10 files changed

+281
-40
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## v0.1.0-alpha `2025-06-14`
2+
3+
Initial Alpha release. The package is functional, with documentation and unit tests included.
4+
5+
### Added
6+
7+
- Complete package scaffolding and setup.
8+
- Database migration for encrypted data storage.
9+
- Encryption table Eloquent model.
10+
- Reusable trait for model property/attribute encryption.
11+
- Core encryption controller.
12+
- Comprehensive documentation, including installation and usage guides.
13+
- Configuration file for package customization.

CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contributing
2+
3+
Thank you for considering to contribute to `laravel-db-encryption` 💖
4+
5+
We are always open for code improvements and features.
6+
7+
Please note that this project is released with a [Code of Conduct](https://github.com/wazzac/laravel-db-encryption/blob/main/CODE_OF_CONDUCT.md). By participating you agree to abide by its terms.
8+
9+
Since this package provides encryption features, please be mindful what data is written to the log file.
10+
11+
Lastly, for any new coding updates; please also include a unit test. Thank you 😉
12+
13+
## Setup
14+
15+
#### Fork this repo
16+
17+
[https://github.com/wazzac/laravel-db-encryption](https://github.com/wazzac/laravel-db-encryption)
18+
19+
#### Check the issues section if there are already issues and see if you can fix them
20+
21+
22+
[https://github.com/wazzac/laravel-db-encryption/issues](https://github.com/wazzac/laravel-db-encryption/issues)
23+
24+
#### If the issue is new, add the code to the fork of the repository and then create a pull request.
25+
26+
#### Add Feat or Fix to the pull request title so maintainer understand what this issue is about.

composer.lock

Lines changed: 39 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
3+
<testsuites>
4+
<testsuite name="Unit">
5+
<directory>./tests/Unit</directory>
6+
</testsuite>
7+
<testsuite name="Feature">
8+
<directory>./tests/Feature</directory>
9+
</testsuite>
10+
</testsuites>
11+
<source>
12+
<include>
13+
<directory suffix=".php">./src</directory>
14+
</include>
15+
</source>
16+
<php>
17+
<env name="APP_ENV" value="testing"/>
18+
<env name="DB_ENCRYPT_DB_PRIMARY_KEY_FORMAT" value="int"/>
19+
<env name="DB_ENCRYPT_KEY" value="Ky4cw2sqPi0Hm7w0UqYa"/>
20+
<env name="DB_ENCRYPT_LOG_INDICATOR" value="sync-modeltocrm"/>
21+
<env name="DB_ENCRYPT_LOG_LEVEL" value="3"/>
22+
</php>
23+
</phpunit>

tests/Feature/ExampleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
it('contains a successful example feature test', function () {
4+
expect(true)->toBeTrue();
5+
});

tests/Pest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Test Case
6+
|--------------------------------------------------------------------------
7+
|
8+
| The closure you provide to your test functions is always bound to a specific PHPUnit test
9+
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
10+
| need to change it using the "pest()" function to bind a different classes or traits.
11+
|
12+
*/
13+
14+
uses(\Wazza\DbEncrypt\Tests\TestCase::class)->in('Unit', 'Feature');
15+
16+
/*
17+
|--------------------------------------------------------------------------
18+
| Expectations
19+
|--------------------------------------------------------------------------
20+
|
21+
| When you're writing tests, you often need to check that values meet certain conditions. The
22+
| "expect()" function gives you access to a set of "expectations" methods that you can use
23+
| to assert different things. Of course, you may extend the Expectation API at any time.
24+
|
25+
*/
26+
27+
expect()->extend('toBeOne', function () {
28+
return $this->toBe(1);
29+
});
30+
31+
/*
32+
|--------------------------------------------------------------------------
33+
| Functions
34+
|--------------------------------------------------------------------------
35+
|
36+
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
37+
| project that you don't want to repeat in every file. Here you can also expose helpers as
38+
| global functions to help you to reduce the number of lines of code in your test files.
39+
|
40+
*/
41+
42+
function something()
43+
{
44+
// ..
45+
}

tests/TestCase.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace Wazza\DbEncrypt\Tests;
4+
5+
use Orchestra\Testbench\TestCase as OrchestraTestCase;
6+
use Illuminate\Foundation\Testing\DatabaseMigrations;
7+
use Illuminate\Foundation\Testing\DatabaseTransactions;
8+
use Wazza\DbEncrypt\Providers\DbEncryptServiceProvider;
9+
use Wazza\DbEncrypt\Models\EncryptedAttributes;
10+
11+
abstract class TestCase extends OrchestraTestCase
12+
{
13+
use DatabaseMigrations, DatabaseTransactions;
14+
15+
/**
16+
* Setup the test environment.
17+
*
18+
* @return void
19+
*/
20+
protected function setUp(): void
21+
{
22+
parent::setUp();
23+
24+
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
25+
// $this->withFactories(__DIR__ . '/../database/factories');
26+
}
27+
28+
/**
29+
* Add the package provider
30+
*
31+
* @param $app
32+
* @return array
33+
*/
34+
protected function getPackageProviders($app)
35+
{
36+
return [
37+
DbEncryptServiceProvider::class,
38+
];
39+
}
40+
41+
/**
42+
* Define environment setup.
43+
*
44+
* @param \Illuminate\Foundation\Application $app
45+
* @return void
46+
*/
47+
protected function getEnvironmentSetUp($app)
48+
{
49+
$app['config']->set('database.default', 'testdb');
50+
$app['config']->set('database.connections.testdb', [
51+
'driver' => 'sqlite',
52+
'database' => __DIR__ . '/testdb.sqlite',
53+
'prefix' => '',
54+
]);
55+
$app['config']->set('db-encrypt.db.primary_key_format', env('DB_ENCRYPT_DB_PRIMARY_KEY_FORMAT', 'int'));
56+
$app['config']->set('db-encrypt.logging.level', env('DB_ENCRYPT_LOG_LEVEL'));
57+
$app['config']->set('db-encrypt.logging.indicator', env('DB_ENCRYPT_LOG_INDICATOR'));
58+
$app['config']->set('db-encrypt.key', env('DB_ENCRYPT_KEY'));
59+
}
60+
61+
/**
62+
* Define aliases for the package
63+
*/
64+
protected function getPackageAliases($app)
65+
{
66+
return [
67+
'config' => 'Illuminate\Config\Repository'
68+
];
69+
}
70+
}

0 commit comments

Comments
 (0)