{"action":"created","issue":{"url":"https://api.github.com/repos/superdesk/web-renderer/issues/27","labels_url":"https://api.github.com/repos/superdesk/web-renderer/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/superdesk/web-renderer/issues/27/comments","events_url":"https://api.github.com/repos/superdesk/web-renderer/issues/27/events","html_url":"https://github.com/superdesk/web-renderer/pull/27","id":106298665,"number":27,"title":"[WIP] configure FixturesBundle with AliceBundle","user":{"login":"takeit","id":562536,"avatar_url":"https://avatars.githubusercontent.com/u/562536?v=3","gravatar_id":"","url":"https://api.github.com/users/takeit","html_url":"https://github.com/takeit","followers_url":"https://api.github.com/users/takeit/followers","following_url":"https://api.github.com/users/takeit/following{/other_user}","gists_url":"https://api.github.com/users/takeit/gists{/gist_id}","starred_url":"https://api.github.com/users/takeit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takeit/subscriptions","organizations_url":"https://api.github.com/users/takeit/orgs","repos_url":"https://api.github.com/users/takeit/repos","events_url":"https://api.github.com/users/takeit/events{/privacy}","received_events_url":"https://api.github.com/users/takeit/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-14T08:55:39Z","updated_at":"2015-11-06T11:11:15Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/superdesk/web-renderer/pulls/27","html_url":"https://github.com/superdesk/web-renderer/pull/27","diff_url":"https://github.com/superdesk/web-renderer/pull/27.diff","patch_url":"https://github.com/superdesk/web-renderer/pull/27.patch"},"body":"**Note:**\r\nThis PR should be merged instead of https://github.com/superdesk/web-renderer/pull/26 when  https://github.com/phpcr/phpcr-utils/pull/159 will be solved.\r\n\r\nWhat does it do:\r\n===\r\nThis bundle helps developers to create fixtures/fake data that can be used for the development or/and testing purposes. \r\n\r\nIt relies on the following 3rd party bundles:\r\n- [DoctrineFixturesBundle](https://github.com/doctrine/DoctrineFixturesBundle) (gives possibility to load data fixtures programmatically into the Doctrine ORM or ODM)\r\n- [AliceBundle](https://github.com/hautelook/AliceBundle) (bundle to manage fixtures with nelmio/alice and fzaninotto/Faker):\r\n    - [fzaninotto/Faker](https://github.com/fzaninotto/Faker) (generates fake data for you)\r\n    - [nelmio/alice](https://github.com/nelmio/alice) (It gives you a few essential tools to make it very easy to generate complex data with constraints in a readable and easy to edit way)\r\n\r\nFixturesBundle, also gives the possibility to setup, ready to use demo theme, needed for the development.\r\n\r\nHow to use it:\r\n===\r\n\r\n#### Configure bundle\r\n\r\nAdd below configuration to your config_dev.yml file:\r\n\r\n```yaml\r\n# app/config/config_dev.yml\r\nhautelook_alice:\r\n    db_drivers:\r\n        orm: ~          # Enable Doctrine ORM if is registered\r\n        phpcr: ~        # Enable Doctrine PHPCR ODM if is registered\r\n    locale: en_US       # Locale to used for faker; must be a valid Faker locale otherwise will fallback to en_EN\r\n    seed: 1             # A seed to make sure faker generates data consistently across runs, set to null to disable\r\n    persist_once: false # Only persist objects once if multiple files are passed\r\n```\r\n\r\nTo your `AppKernel.php` add:\r\n\r\n```php\r\n// app/AppKernel.php\r\nif (in_array($this->getEnvironment(), array('dev', 'test'))) {\r\n      ...\r\n      $bundles[] = new Hautelook\\AliceBundle\\HautelookAliceBundle();\r\n      $bundles[] = new SWP\\FixturesBundle\\SWPFixturesBundle();\r\n      ...\r\n}\r\n```\r\n\r\n#### Creating a simple Alice fixture (YAML format)\r\n\r\nAlice YAML fixtures should be placed inside `SWPFixturesBundle/DataFixtures/<db_driver>/<environment>`, where `<environment>` is the current environment name (Dev, Test) and `<db_driver>` is currently set database driver.\r\n\r\nReplace `db_driver` either with `ORM` for the Doctrine ORM or `PHPCR` for the Doctrine PHPCR ODM.\r\n\r\nExample Alice fixture:\r\n\r\n```yaml\r\n# SWPFixturesBundle/DataFixtures/ORM/Dev/article.yml\r\nSWP\\ContentBundle\\Document\\Article:\r\n    article1:\r\n        title: \"Test article\"\r\n        content: \"<paragraph(20)>\"\r\n    article2:\r\n        title: \"Features\"\r\n        content: \"<paragraph(20)>\"\r\n    article3:\r\n        title: \"Get Involved\"\r\n        content: \"<paragraph(20)>\"\r\n\r\n```\r\n\r\nThe above configuration states that we want to persist into database, three objects of type `SWP\\ContentBundle\\Document\\Article`.\r\n\r\nWe can use faker [formatters](https://github.com/fzaninotto/Faker#formatters) where, for example, `<paragraph(20)>` is one of the [fzaninotto/Faker](https://github.com/fzaninotto/Faker) formatter, which tells Alice to generate 20 paragraphs filled with fake data.\r\n\r\n\r\nFor instance, having `SWPFixturesBundle/DataFixtures/ORM/Test/article.yml` Alice fixture, we will be able to persist fake data defined in YAML file into the databse (using Doctrine ORM driver), only when `test` environment option is set:\r\n\r\n```bash\r\n$ php app/console h:d:f:l --env=test\r\n```\r\n\r\nPlease, see [documentation](https://github.com/hautelook/AliceBundle/blob/master/src/Resources/doc/advanced-usage.md#environment-specific-fixtures) for more details about environment specific fixtures.\r\n\r\nThere is a lot of flexibility on how to define fixtures, so it's up to developer how to create them.\r\n\r\nRead more about Alice [here](https://github.com/nelmio/alice#table-of-contents)\r\n\r\n#### Loading all fixtures\r\n\r\n**Note:** Remember to update your database schema before loading fixtures!\r\nTo do it, run in terminal:\r\n```bash\r\n$ php app/console doctrine:schema:update --force\r\n$ php app/console doctrine:phpcr:repository:init\r\n```\r\n\r\nOnce you have your fixtures defined, you can simply load them. To do that, you must execute console commands in terminal:\r\n\r\nTo load Doctrine ORM fixtures:\r\n\r\n```bash\r\n$ php app/console h:d:f:l --append\r\n# see php app/console h:d:f:l --help for more details\r\n```\r\n\r\nTo load Doctrine PHCR fixtures:\r\n\r\n```bash\r\n$ php app/console h:d:phpcr:f:l --append\r\n# see php app/console h:d:phpcr:f:l --help for more details\r\n```\r\n\r\nAfter executing above commands, your database will be filled with the fake data, which can be used by themes.\r\n\r\n#### Setting up demo theme\r\n\r\nTo make it easier to start with the WebPublisher, we created a simple demo theme. To set this theme as an active one, you need to execute the following console command in terminal:\r\n\r\n```bash\r\n$ php app/console theme:setup\r\n# see php app/console theme:setup --help for more details\r\n```\r\n\r\n#### Loading fixtures in PHPUnit tests\r\n\r\nLoading PHPCR fixtures:\r\n\r\n```php\r\n$this->loadFixtureFiles([\r\n   '@SWPFixturesBundle/DataFixtures/PHPCR/Test/article.yml',\r\n], true, null, 'doctrine_phpcr');\r\n```\r\n\r\nLoading ORM fixtures:\r\n\r\n```php\r\n$this->loadFixtureFiles([\r\n   '@SWPFixturesBundle/DataFixtures/ORM/Test/page.yml',\r\n]);\r\n```"},"comment":{"url":"https://api.github.com/repos/superdesk/web-renderer/issues/comments/154383185","html_url":"https://github.com/superdesk/web-renderer/pull/27#issuecomment-154383185","issue_url":"https://api.github.com/repos/superdesk/web-renderer/issues/27","id":154383185,"user":{"login":"ahilles107","id":298610,"avatar_url":"https://avatars.githubusercontent.com/u/298610?v=3","gravatar_id":"","url":"https://api.github.com/users/ahilles107","html_url":"https://github.com/ahilles107","followers_url":"https://api.github.com/users/ahilles107/followers","following_url":"https://api.github.com/users/ahilles107/following{/other_user}","gists_url":"https://api.github.com/users/ahilles107/gists{/gist_id}","starred_url":"https://api.github.com/users/ahilles107/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahilles107/subscriptions","organizations_url":"https://api.github.com/users/ahilles107/orgs","repos_url":"https://api.github.com/users/ahilles107/repos","events_url":"https://api.github.com/users/ahilles107/events{/privacy}","received_events_url":"https://api.github.com/users/ahilles107/received_events","type":"User","site_admin":false},"created_at":"2015-11-06T11:11:15Z","updated_at":"2015-11-06T11:11:15Z","body":"@takeit - ping"}}