Skip to content

Commit

Permalink
Add data fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
bocharsky-bw committed Jun 23, 2016
1 parent 89b00d9 commit c0ccb1d
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function registerBundles()
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();

$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
}

return $bundles;
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
"symfony/phpunit-bridge": "^3.0",

"doctrine/doctrine-fixtures-bundle": "^2.3"
},
"scripts": {
"post-install-cmd": [
Expand Down
120 changes: 118 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions src/AppBundle/DataFixtures/ORM/LoadPostData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace AppBundle\DataFixtures\ORM;

use AppBundle\Entity\Post;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class LoadPostData implements FixtureInterface
{
public function load(ObjectManager $manager)
{
for ($i = 1; $i <= 10; $i++) {
$post = new Post();
$post->setSlug(sprintf('post-%d', $i));
$post->setHeading(sprintf('Post %d', $i));
$post->setContent(<<<HEREDOC
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
A ad at deserunt eligendi libero maiores mollitia neque nisi
nobis odio quas sit voluptate, voluptatum. Aliquam exercitationem
fugit hic recusandae voluptatibus?
HEREDOC
);
$manager->persist($post);
}

$manager->flush();
}
}

0 comments on commit c0ccb1d

Please sign in to comment.