Installation
composer require hautelook/alice-bundle
Add to config/bundles.php (Symfony 4+):
Hautelook\AliceBundle\HautelookAliceBundle::class => ['all' => true],
First Fixture
Create a YAML file (e.g., config/fixtures/users.yml):
App\Entity\User:
user{1..10}:
email: '<email()>'
roles: ['ROLE_USER']
plainPassword: 'password'
Load fixtures via CLI:
php bin/console hautelook:fixtures:load --env=test
Database Support
Ensure FidryAliceDataFixtures is installed (handles Doctrine ORM, Propel, etc.):
composer require theofidry/alice-data-fixtures
Test Environments
Use in phpunit.xml for test databases:
<env name="DATABASE_URL" value="sqlite:///:memory:"/>
Load fixtures before tests via setUp():
public function setUp(): void {
$this->loadFixtures(['users.yml', 'posts.yml']);
}
Dynamic Fixtures Generate fixtures programmatically:
$faker = Faker\Factory::create();
$users = [];
for ($i = 0; $i < 5; $i++) {
$users[] = new User([
'email' => $faker->email,
'roles' => ['ROLE_USER']
]);
}
$this->loadFixtures([$users]);
Dependency Injection
Inject AliceDataFixtures service in controllers/services:
use Hautelook\AliceBundle\Loader\LoaderInterface;
public function __construct(LoaderInterface $loader) {
$this->loader = $loader;
}
users.yml, posts.yml) and load them together.--env flag to load different fixtures per environment.--no-warmup flag or environment checks).Database Constraints
<uniqueEmail()> or custom Faker providers to avoid duplicates.Caching Issues
php bin/console cache:clear
ORM-Specific Quirks
FidryAliceDataFixtures\Loader\DoctrineLoader for complex relationships.propel:model:build to regenerate models after fixture changes.php bin/console hautelook:fixtures:load --env=test --debug
php bin/console hautelook:fixtures:load --env=test --dry-run
Faker\Factory::create()->extend('customProvider', function ($faker) {
return function () {
return 'custom_' . $faker->word;
};
});
Hautelook\AliceBundle\Loader\LoaderInterface for non-Doctrine databases (e.g., Eloquent).kernel.terminate) to run logic after fixture loading.php bin/console hautelook:fixtures:load --env=test --param="users.count=20"
How can I help you explore Laravel packages today?