h4cc/alice-fixtures-bundle
Symfony2 bundle for flexible data fixtures using nelmio/alice and Faker. Load fixtures from YAML/PHP, decouple from Doctrine DataFixtures, and optionally drop & recreate Doctrine ORM schema. Supports Doctrine ORM and MongoDB ODM. Work in progress (<1.0).
DataFixtures, which is tightly coupled to ORM lifecycle events. This aligns well with modern Symfony architectures where fixtures are treated as environment-specific data (e.g., dev/test environments).nelmio/alice and Faker for synthetic data generation, reducing boilerplate for test data. Custom providers/processors extend functionality (e.g., domain-specific fake data).Bundle system and ManagerRegistry. Porting would require:
Kernel-based bundle registration with Laravel’s service providers.nelmio/alice library directly in Laravel (no bundle wrapper).AliceFixturesBundle functionality (if Symfony2 is also used in the stack).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Deprecated Symfony2 | High | Evaluate effort to backport or replace with nelmio/alice directly. |
| Schema Recreation | Critical | Restrict usage to non-production environments; implement safeguards (e.g., dry runs). |
| Lack of Maintenance | Medium | Fork the repo to apply critical fixes or migrate to alternatives (e.g., Laravel Fixtures). |
| Multi-Manager Complexity | Medium | Document configuration thoroughly; default to a single manager unless needed. |
| Test Data Isolation | Low | Use transactions or soft deletes instead of schema drops for safer testing. |
loadFiles() with production-like volumes.DataFixtures for dependencies (e.g., load() order, references) and adapt to AliceFixturesBundle’s model.ManagerRegistry deprecations). May need to override services or use a compatibility layer.nelmio/alice Usage: Skip the bundle and use Alice’s standalone loader.
use Nelmio\Alice\Loader\NativeLoader;
$loader = new NativeLoader();
$objects = $loader->load(__DIR__.'/fixtures/users.yml');
// app/Providers/FixtureServiceProvider.php
public function register()
{
$this->app->singleton('fixtures', function () {
return new AliceFixturesManager($this->app);
});
}
DataFixtures and identify dependencies (e.g., load() order, references).UserBundle) to test the migration.config_dev.yml (e.g., locale, seed).doctrine:fixtures:load with:
php artisan h4cc_alice_fixtures:load:files path/to/fixtures/*.yml
| Component | Compatibility Notes |
|---|---|
| Doctrine ORM | Fully supported; uses ManagerRegistry. |
| Doctrine MongoDB ODM | Supported but may require additional configuration for hybrid setups. |
| Faker Providers | Extendable via service tags; ensure providers are compatible with Faker’s version. |
| Symfony Console | Commands work in Symfony; Laravel would need custom Artisan commands. |
| PHPUnit | Integrates via setUp(); use Symfony’s test client or Laravel’s DatabaseMigrations. |
composer.json to include dependencies:
"require": {
"h4cc/alice-fixtures-bundle": "dev-master",
"nelmio/alice": "^1.6",
"fzaninotto/faker": "^1.9"
}
AppKernel.php (Symfony2) or create a provider (Laravel).config_dev.yml:
h4cc_alice_fixtures:
locale: en_US
seed: 12345
doctrine: orm
src/Acme/Bundle/Resources/fixtures/ (Symfony) or database/fixtures/ (Laravel).Users.yml:
App\Entity\User:
user{1..10}:
email: <email()>
roles: [ROLE_USER]
php app/console h4cc_alice_fixtures:load:files --drop src/Acme/UserBundle/Resources/fixtures/Users.yml
# .github/workflows/test.yml
- run: php bin/console h4cc_alice_fixtures:load:sets
- run: phpunit
How can I help you explore Laravel packages today?