From 648e5d7ba5769aba4209bb2fc0b7d715af174462 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Tue, 29 Mar 2016 09:53:06 +0300 Subject: [PATCH] Fixtures for post with large discussion. --- .../DataFixtures/ORM/LoadCommentsData.php | 54 +++++++++++++++++++ .../DataFixtures/ORM/LoadPostData.php | 37 +++++++++++++ .../DataFixtures/ORM/LoadUserData.php | 28 ++++++++++ 3 files changed, 119 insertions(+) create mode 100644 src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadCommentsData.php create mode 100644 src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php create mode 100644 src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php diff --git a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadCommentsData.php b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadCommentsData.php new file mode 100644 index 0000000..c44f2c5 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadCommentsData.php @@ -0,0 +1,54 @@ +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; + } +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php new file mode 100644 index 0000000..ac33393 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php @@ -0,0 +1,37 @@ +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; + } +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php new file mode 100644 index 0000000..3d43073 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php @@ -0,0 +1,28 @@ +setCreatedAt(new \DateTime()) + ; + + $om->persist($user); + $om->flush(); + + $this->addReference('test_user', $user); + } + + public function getOrder() + { + return 1; + } +} \ No newline at end of file