This document describes how to test all commands of the AnonymizeBundle in the demo applications.
The bundle provides 6 console commands:
nowo:anonymize:info- Display information about anonymizers defined in the applicationnowo:anonymize:run- Execute anonymization of database recordsnowo:anonymize:history- View and manage anonymization historynowo:anonymize:export-db- Export databases to files with optional compressionnowo:anonymize:generate-column-migration- Generate Doctrine migration for anonymized columnnowo:anonymize:generate-mongo-field- Generate MongoDB field for anonymized tracking
A comprehensive testing script is available in the scripts/ directory: scripts/test-commands.sh
This script automatically tests all bundle commands with their main options across all demo projects, ensuring compatibility and functionality.
# Test all commands in all demos (recommended)
./.scripts/test-commands.sh all
# Test in a specific demo
./.scripts/test-commands.sh symfony7
./.scripts/test-commands.sh symfony8The script tests 26 command combinations (26 entries in the COMMANDS array in scripts/test-commands.sh):
- Without options (all connections)
- With
--connection default,postgres, andsqlite - With
--locale es_ESon the default connection - With
--verboseon the default connection
--dry-runwith connectionsdefault,postgres, andsqlite--dry-runwith--batch-size 50and--locale es_ES--dry-runwith--verbose
Note: All
nowo:anonymize:runtests use--dry-runto avoid modifying data during testing.
- Without options
- With
--limit 5 - With
--connection default - Combined
--limit 10 --connection default
- One run per connection:
default,postgres,sqlite,mongodb
Note: The export command does not define a
--dry-runflag in this bundle. These tests run the real export flow (files may be produced under the demo’s configured export paths). Use only in environments where that is acceptable.
- Without options
- With
--connection default,postgres, andsqlite
- With
--scan-documents - With
--collection user_activities
- Docker and Docker Compose must be installed
- Demo containers must be running:
cd demo/symfony7 && docker-compose up -d cd demo/symfony8 && docker-compose up -d
The script provides:
- ✅ Success indicators for passing tests
- ❌ Error messages with details for failing tests
⚠️ Skipped status for containers that aren't running- 📊 Summary statistics for each demo:
- Number of successful tests
- Number of failed tests
- Number of skipped tests
🚀 Starting AnonymizeBundle command tests
==========================================
🧪 Testing: symfony7
==========================================
Testing: nowo:anonymize:info
✅ Success
Output (first 5 lines):
Anonymizer Information
======================
Entity Manager: default
Testing: nowo:anonymize:info --connection default
✅ Success
...
==========================================
📊 Summary for symfony7:
✅ Successful: 26
❌ Failed: 2
⚠️ Skipped: 1
==========================================
To modify which commands are tested, edit the COMMANDS array in scripts/test-commands.sh:
# Commands to test - covering all commands with their main options
COMMANDS=(
"nowo:anonymize:info"
"nowo:anonymize:info --connection default"
# Add more commands here...
)Test information display for all connections:
# In each demo container
php bin/console nowo:anonymize:info --connection default
php bin/console nowo:anonymize:info --connection postgres
php bin/console nowo:anonymize:info --connection sqlite
php bin/console nowo:anonymize:info # All connectionsExpected: Should display information about all entities with #[Anonymize] attribute and their properties.
Test anonymization execution (use --dry-run first):
# Dry-run mode (safe, no changes)
php bin/console nowo:anonymize:run --connection default --dry-run
php bin/console nowo:anonymize:run --connection postgres --dry-run
php bin/console nowo:anonymize:run --connection sqlite --dry-run
# Test a single entity (e.g. to verify anonymizeService or event listeners)
php bin/console nowo:anonymize:run --entity "App\Entity\SmsNotification" --dry-run
# With options
php bin/console nowo:anonymize:run --connection default --batch-size 50
php bin/console nowo:anonymize:run --connection default --locale es_ES
php bin/console nowo:anonymize:run --connection default --interactive
php bin/console nowo:anonymize:run --connection default --stats-json stats.json
php bin/console nowo:anonymize:run --connection default --stats-csv stats.csvExpected: Should show what would be anonymized (dry-run) or actually anonymize data.
Test history viewing:
php bin/console nowo:anonymize:history
php bin/console nowo:anonymize:history --limit 5
php bin/console nowo:anonymize:history --connection default
php bin/console nowo:anonymize:history --run-id=<run-id>
php bin/console nowo:anonymize:history --compare=<run-id-1>,<run-id-2>Expected: Should display anonymization run history.
Test database export (there is no --dry-run option; exports write real dump files):
php bin/console nowo:anonymize:export-db --connection default
php bin/console nowo:anonymize:export-db --connection postgres
php bin/console nowo:anonymize:export-db --connection sqlite
php bin/console nowo:anonymize:export-db --connection mongodb
# Omit --connection to export all configured connections (default behavior)Expected: Should export databases to files (with compression if available).
Test migration generation:
php bin/console nowo:anonymize:generate-column-migration
php bin/console nowo:anonymize:generate-column-migration --connection default
php bin/console nowo:anonymize:generate-column-migration --connection postgresExpected: Should print or save SQL to add the anonymized column for anonymizable entities (see --output to write a file).
Test MongoDB field generation:
php bin/console nowo:anonymize:generate-mongo-field --scan-documents
php bin/console nowo:anonymize:generate-mongo-field --collection user_activities --database anonymize_demoExpected: Should generate a MongoDB script to add the anonymized field (see command --help for all options).
For each demo (Symfony 7 and 8):
-
nowo:anonymize:infoworks for all connections (default, postgres, sqlite) -
nowo:anonymize:run --dry-runworks for all connections -
nowo:anonymize:runwith various options works -
nowo:anonymize:historydisplays history correctly -
nowo:anonymize:export-dbworks for each connection you care about (exports are real, not dry-run) -
nowo:anonymize:generate-column-migrationgenerates correct migrations -
nowo:anonymize:generate-mongo-fieldgenerates correct field code - All commands show help text correctly (
--helpoption) - Error handling works (invalid connections, missing entities, etc.)
cd demo/symfony7 && docker-compose up -d
cd demo/symfony7 && docker-compose up -d
cd demo/symfony8 && docker-compose up -d# In each demo container
php bin/console doctrine:schema:create
php bin/console doctrine:fixtures:loadEnsure the script has execute permissions:
chmod +x scripts/test-commands.sh- Always use
--dry-runfirst when testingnowo:anonymize:runto avoid modifying data - The
--interactivemode is useful for testing step-by-step execution - Statistics export (
--stats-json,--stats-csv) helps verify anonymization results - History commands require at least one anonymization run to have data