Skip to content

Commit bc81724

Browse files
committed
Refactor test directory structure and enhance key generation command
- Renamed test directory from `Tests` to `tests` for consistency. - Updated references in `.php-cs-fixer.dist.php`, `composer.json`, and `phpunit.xml.dist` to reflect the new directory name. - Enhanced `doctrine:encrypt:generate-secret-key` command to support generating keys for all configs or a specific config with confirmation for overwriting existing keys. - Updated documentation in `COMMANDS.md` to clarify command usage and behavior. - Added new functional tests for encryption behavior and key generation scenarios.
1 parent 811639c commit bc81724

56 files changed

Lines changed: 351 additions & 119 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$finder = PhpCsFixer\Finder::create()
44
->in(__DIR__ . '/src')
5-
->in(__DIR__ . '/Tests')
5+
->in(__DIR__ . '/tests')
66
->name('*.php');
77

88
return (new PhpCsFixer\Config())

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Key files: one per config, e.g. `.Halite.personal_data.key`, `.Defuse.financial_
8888
.Defuse.*.key
8989
```
9090

91-
Generate the default key: `php bin/console doctrine:encrypt:generate-secret-key` (Halite only). See [docs/CONFIGURATION.md](docs/CONFIGURATION.md) and [docs/COMMANDS.md](docs/COMMANDS.md).
91+
Generate keys: `php bin/console doctrine:encrypt:generate-secret-key` (creates missing Halite/Defuse keys for all configs, or pass a config alias). See [docs/CONFIGURATION.md](docs/CONFIGURATION.md) and [docs/COMMANDS.md](docs/COMMANDS.md).
9292

9393
### Single encryptor (one config)
9494

Tests/Unit/Command/GenerateSecretKeyCommandTest.php

Lines changed: 0 additions & 74 deletions
This file was deleted.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
"autoload-dev": {
6363
"psr-4": {
64-
"Nowo\\DoctrineEncryptBundle\\Tests\\": "Tests/"
64+
"Nowo\\DoctrineEncryptBundle\\Tests\\": "tests/"
6565
}
6666
},
6767
"archive": {

docs/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121

2222
---
2323

24+
## [2.0.5] - 2026-02-20
25+
26+
### Added
27+
28+
- **doctrine:encrypt:generate-secret-key:** Optional argument `config` to generate the key for a single config; when the key file already exists, the command asks for confirmation before overwriting. Without argument, the command now checks all configs (all `secret_directory_path` entries) and creates a missing key file for each Halite or Defuse config; configs that already have a key are skipped with a message.
29+
- **Makefile:** Targets `validate` (runs `composer validate --strict`) and `update` (runs `composer update`); `make qa` now runs `validate` before cs-check and test.
30+
31+
### Changed
32+
33+
- **Test directory:** The test directory has been renamed from `Tests` to `tests` (lowercase). PHP namespaces remain `Nowo\DoctrineEncryptBundle\Tests\`; only the folder and references in `phpunit.xml.dist`, `composer.json` (autoload-dev), and `.php-cs-fixer.dist.php` changed.
34+
- **symfony/var-exporter:** Kept in `require` (not only in require-dev) so that Doctrine ORM 3.x LazyGhost is available in all environments (CI and production when using lazy loading). This fixes functional test failures on PHP 8.4/8.5 with Symfony 8.0 ("Symfony LazyGhost is not available").
35+
- **CI:** Install step pins `symfony/var-exporter:^7.4` so Doctrine ORM accepts the installed version for LazyGhost; coverage job also requires `symfony/var-exporter`.
36+
- **Documentation:** [COMMANDS.md](docs/COMMANDS.md) updated: encrypt/decrypt database commands use argument `config` (config alias); generate-secret-key documents the new behaviour (all configs vs single config with confirmation).
37+
38+
No upgrade steps required from 2.0.4. See [UPGRADING.md](UPGRADING.md#upgrading-to-205).
39+
40+
---
41+
2442
## [2.0.4] - 2026-02-19
2543

2644
### Fixed

docs/COMMANDS.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ php bin/console doctrine:encrypt:database
3737

3838
Optional arguments:
3939

40-
- **encryptor**Encryptor to use (e.g. `Halite`, `Defuse`), or a class name. Default: the configured default encryptor.
40+
- **config**Config alias to use (e.g. `default`, `personal_data`, `financial_data`). If omitted, all configs are processed in turn.
4141
- **batchSize** — Number of entities to flush per batch (default: 20).
4242

4343
Examples:
4444

4545
```bash
46-
php bin/console doctrine:encrypt:database Halite
47-
php bin/console doctrine:encrypt:database Defuse 50
46+
php bin/console doctrine:encrypt:database
47+
php bin/console doctrine:encrypt:database default 50
48+
php bin/console doctrine:encrypt:database personal_data
4849
```
4950

5051
## Decrypt database
@@ -57,24 +58,33 @@ php bin/console doctrine:decrypt:database
5758

5859
Optional arguments:
5960

60-
- **encryptor**Encryptor to use (e.g. `Halite`, `Defuse`), or a class name. Default: the configured default encryptor.
61+
- **config**Config alias to use (e.g. `default`, `personal_data`). If omitted, all configs are processed in turn.
6162
- **batchSize** — Number of entities to flush per batch (default: 20).
6263

6364
Examples:
6465

6566
```bash
66-
php bin/console doctrine:decrypt:database Halite
67-
php bin/console doctrine:decrypt:database Defuse 50
67+
php bin/console doctrine:decrypt:database
68+
php bin/console doctrine:decrypt:database default 50
6869
```
6970

7071
## Generate secret key
7172

72-
Generate a new secret key file for the configured encryptor:
73+
Generates encryption key files for Halite and Defuse configs.
74+
75+
**Without argument:** Checks all configs; creates a key file in each `secret_directory_path` when missing (Halite and Defuse only). Skips configs that already have a key file.
7376

7477
```bash
7578
php bin/console doctrine:encrypt:generate-secret-key
7679
```
7780

78-
Run this before first use if no key file exists, or when rotating keys.
81+
**With config argument:** Creates or overwrites the key for that config only. If the key file already exists, the command asks for confirmation before overwriting.
82+
83+
```bash
84+
php bin/console doctrine:encrypt:generate-secret-key default
85+
php bin/console doctrine:encrypt:generate-secret-key personal_data
86+
```
87+
88+
Run this before first use if no key file exists, or when rotating keys. Configs using a custom encryptor class are skipped (only Halite and Defuse keys are generated).
7989

8090
For a full **key rotation** procedure (backup → decrypt → change keys → re-encrypt), see [Key rotation](KEY_ROTATION.md).

docs/RELEASE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232

3333
---
3434

35+
## v2.0.5 (2026-02-20)
36+
37+
- **Scope:** (1) GenerateSecretKeyCommand: support all configs (create missing Halite/Defuse keys); optional `config` argument with overwrite confirmation. (2) Rename test directory `Tests``tests`; update phpunit, composer autoload-dev, php-cs-fixer. (3) Keep symfony/var-exporter in require for LazyGhost; CI pin var-exporter ^7.4. (4) Makefile: validate and update targets; qa runs validate. (5) Docs: COMMANDS.md correct args (config) and generate-secret-key behaviour.
38+
- **Checklist:** CHANGELOG and UPGRADING updated; tag `v2.0.5` created and pushed.
39+
40+
---
41+
3542
## v2.0.4 (2026-02-19)
3643

3744
- **Scope:** (1) Fix PHPUnit unit tests (EncryptUtil, DecryptExtension) so they no longer mock the final class `EncryptorRegistry`; use real registry with mocked `EncryptorInterface` instead. Fixes test-coverage errors with PHPUnit 10/11. (2) Make `doctrine:encrypt:database` and `doctrine:decrypt:database` command `configure()` idempotent so arguments are only added when not already present; avoids "An argument with name config already exists" with Symfony Console 7/8.

docs/UPGRADING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ This guide explains how to upgrade the Doctrine Encrypt Bundle between versions.
2929

3030
---
3131

32+
## Upgrading to 2.0.5
33+
34+
No breaking changes. Update as usual:
35+
36+
```bash
37+
composer update nowo-tech/doctrine-encrypt-bundle
38+
php bin/console cache:clear
39+
```
40+
41+
If you run the test suite from the bundle source, ensure your autoload and PHPUnit config use the `tests/` directory (lowercase); the package already ships with this layout.
42+
43+
---
44+
3245
## Upgrading to 2.0.4
3346

3447
No breaking changes. Update as usual:

phpunit.xml.dist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="./Tests/bootstrap.php"
3+
<phpunit bootstrap="./tests/bootstrap.php"
44
colors="true">
55

66
<testsuites>
77
<testsuite name="unit">
8-
<directory suffix="Test.php">./Tests/Unit</directory>
8+
<directory suffix="Test.php">./tests/Unit</directory>
99
</testsuite>
1010
<testsuite name="functional">
11-
<directory suffix="Test.php">./Tests/Functional/BasicQueryTest</directory>
12-
<directory suffix="TestCase.php">./Tests/Functional/DoctrineEncryptSubscriber</directory>
11+
<directory suffix="Test.php">./tests/Functional/BasicQueryTest</directory>
12+
<directory suffix="TestCase.php">./tests/Functional/DoctrineEncryptSubscriber</directory>
1313
</testsuite>
1414
</testsuites>
1515

@@ -29,7 +29,7 @@
2929
</coverage>
3030

3131
<php>
32-
<env name="KERNEL_DIR" value="./Tests/Functional/Fixtures/app" />
32+
<env name="KERNEL_DIR" value="./tests/Functional/Fixtures/app" />
3333
<env name="KERNEL_CLASS" value="AppKernel" />
3434
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
3535
</php>

0 commit comments

Comments
 (0)