Fixtures for post with large discussion.

This commit is contained in:
Alexey Skobkin 2016-03-29 09:53:06 +03:00
parent f4f33a8947
commit 648e5d7ba5
3 changed files with 119 additions and 0 deletions

View file

@ -0,0 +1,54 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment;
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
class LoadCommentsData extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $om)
{
/** @var Post $post */
$post = $this->getReference('test_post');
/** @var User $user */
$user = $this->getReference('test_user');
$comments = [];
foreach (range(1, 10000) as $num) {
$comment = (new Comment())
->setNumber($num)
->setDeleted(rand(0, 15) ? false : true)
->setCreatedAt(new \DateTime())
->setAuthor($user)
->setRec(false)
->setText('Some text with [link to @skobkin-ru site](https://skobk.in/) and `code block`
and some quotation:
> test test quote
and some text after')
;
if (count($comments) > 0 && rand(0, 1)) {
$comment->setParent($comments[rand(0, count($comments) - 1)]);
}
$post->addComment($comment);
$comments[] = $comment;
$om->persist($comment);
}
$om->flush();
}
public function getOrder()
{
return 3;
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
class LoadPostData extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $om)
{
/** @var User $user */
$user = $this->getReference('test_user');
$post = (new Post('testpost'))
->setAuthor($user)
->setCreatedAt(new \DateTime())
->setText('Test post with many comments')
->setPrivate(false)
->setType(Post::TYPE_POST)
->setDeleted(false)
;
$om->persist($post);
$om->flush();
$this->addReference('test_post', $post);
}
public function getOrder()
{
return 2;
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
class LoadUserData extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $om)
{
$user = (new User(99999, 'testuser', 'Test User'))
->setCreatedAt(new \DateTime())
;
$om->persist($user);
$om->flush();
$this->addReference('test_user', $user);
}
public function getOrder()
{
return 1;
}
}