Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine
This course is archived!

Making Fixtures Really Awesome with Alice


What you'll be learning

// composer.json
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.5.*", // v2.5.5
        "doctrine/orm": "~2.2,>=2.2.3", // v2.4.6
        "doctrine/doctrine-bundle": "~1.2", // v1.2.0
        "twig/extensions": "~1.0", // v1.1.0
        "symfony/assetic-bundle": "~2.3", // v2.5.0
        "symfony/swiftmailer-bundle": "~2.3", // v2.3.7
        "symfony/monolog-bundle": "~2.4", // v2.6.1
        "sensio/distribution-bundle": "~3.0", // v3.0.6
        "sensio/framework-extra-bundle": "~3.0", // v3.0.2
        "incenteev/composer-parameter-handler": "~2.0", // v2.1.0
        "hautelook/alice-bundle": "~0.1" // 0.1.5
    "require-dev": {
        "sensio/generator-bundle": "~2.3" // v2.4.0

Fixtures: those little bits of test data you load (and reload) locally so that you can test your site with some real-ish content. Until now, creating fixtures was boring. But with Alice, they're video-game-level exciting. Seriously!

Your Guides

Ryan Weaver Leanna Pelham

Buy Access

Join the Conversation?

Login or Register to join the conversation
Andrei V. Avatar
Andrei V. Avatar Andrei V. | posted 5 years ago

Is there any easy way to get access to current() in my custom provider?


Hey there!

Actually, I don't think this is possible right now - that value is "locked up" in a class from "Alice" that we can't access. You can use most of the Faker functions inside your custom formatter/provider by creating your own Faker instance:

$faker = \Faker\Factory::create('en');

But current() is the one formatter that's different, and we can't get to it. You also can't nest formatters (e.g. <avatar(<current()>)>, which would be kind of cool :).


1 Reply
Default user avatar
Default user avatar Martin Bittner | posted 5 years ago

I followed this tutorial, and nothing loads into my DB, yet no error displayed. Any idea? Can it be linked to the newer version of the HautelookAliceBundle?


Hey Martin,

Yes, it can be. What version do you use? Many concepts are the same, but they change something in the new version. What command do you run to load your fixtures? What output exactly do you have after this command?


Default user avatar
Default user avatar Martin Bittner | Victor | posted 5 years ago


Here is my composer.json
"require": {
"php": ">=5.5.9",
"symfony/symfony": "3.2.*",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.2",
"symfony/swiftmailer-bundle": "^2.3.10",
"symfony/monolog-bundle": "^3.0.2",
"symfony/polyfill-apcu": "^1.0",
"sensio/distribution-bundle": "^5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "^2.0",
"twig/twig": "^1.0||^2.0"
"require-dev": {
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0",
"nelmio/alice": "3.0.*@beta",
"hautelook/alice-bundle": "2.0.*@beta",
"theofidry/alice-data-fixtures": "1.0.*@beta",
"doctrine/data-fixtures": "^1.2",
"doctrine/doctrine-fixtures-bundle": "^2.3"

I tried with creating a fixture class in php like in the tutorial and adding my .yml in it and used app/console doctrine:fixtures:load, it does ask me if I want to purge my data, I say yes, and the prompt returns without error, and no data in DB.

Then I look at the alice bundle doc, and added
# app/config/config_dev.yml

fixtures_path: 'Resources/fixtures/orm' # Path to which to look for fixtures relative to the bundle path.

and tried using bin/console hautelook:fixtures:load and samething happens, purge data prompt, then the prompt returns without error and no DB.

Can you spot anything wrong?

Default user avatar

I finally got it to work, following Alice-Bundle instructions!

Default user avatar
Default user avatar Daniëlle Suurlant | Martin Bittner | posted 5 years ago

I am having the same problem. Could you specify what you missed before and what you did to fix it?

1 Reply

Hey Daniëlle Suurlant ,

Till we're waiting for Martin, could you double check the docs step by step? I bet you miss an important step in their README.


Default user avatar
Default user avatar Daniëlle Suurlant | Victor | posted 5 years ago

I eventually found out it was a bug: https://github.com/hauteloo...
I was able to fix it by putting the yaml files into AppBundle/Resources/fixtures/orm instead of app/Resources/fixtures/orm.


Good catch, thank you for sharing it with other users!



Hey Martin,

Glad you got it working so fast! Docs FTW! :)


Cat in space

"Houston: no signs of life"
Start the conversation!