This course is archived!

> Symfony 2 >

Course Overview

Making Fixtures Really Awesome with Alice

  • 1408 students
  • EN Captions
  • EN Script
  • Certificate of Completion

Your Guides

About this course

What PHP libraries does this tutorial use?

// 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!

Next courses in the Symfony 2: Young Jedi section of the Symfony 2 Track!

11 Comments

Sort By
Login or Register to join the conversation
Andrei-V avatar Andrei-V 5 years ago

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

| Reply |

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');
var_dump($faker->company);

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 :).

Cheers!

1 | Reply |
Default user avatar Martin Bittner 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?

| Reply |

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?

Cheers!

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

Well,

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

hautelook_alice:
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?

| Reply |

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

| Reply |
Default user avatar Daniëlle Suurlant Martin Bittner 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.

Cheers!

| Reply |
Default user avatar Daniëlle Suurlant Victor 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.

| Reply |

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

Cheers!

| Reply |

Hey Martin,

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

Cheers!

| Reply |

Delete comment?

Share this comment

astronaut with balloons in space

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