From 22784542bf58305baba4560e7e9d2da7ea9f6060 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 12 Dec 2016 01:53:56 +0300 Subject: [PATCH] Many test users in fixtures --- .../DataFixtures/ORM/LoadCommentsData.php | 30 ++++++++++++------- .../DataFixtures/ORM/LoadPostData.php | 10 +++---- .../DataFixtures/ORM/LoadUserData.php | 30 +++++++++++++++---- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadCommentsData.php b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadCommentsData.php index c44f2c5..4a369f4 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadCommentsData.php +++ b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadCommentsData.php @@ -14,28 +14,36 @@ class LoadCommentsData extends AbstractFixture implements OrderedFixtureInterfac public function load(ObjectManager $om) { /** @var Post $post */ - $post = $this->getReference('test_post'); + $post = $this->getReference('test_post_longpost'); - /** @var User $user */ - $user = $this->getReference('test_user'); + /** @var User[] $users */ + $users = [ + $this->getReference('test_user_99999'), + $this->getReference('test_user_99998'), + $this->getReference('test_user_99997'), + $this->getReference('test_user_99996'), + $this->getReference('test_user_99995'), + ]; $comments = []; foreach (range(1, 10000) as $num) { $comment = (new Comment()) ->setNumber($num) - ->setDeleted(rand(0, 15) ? false : true) + ->setDeleted(mt_rand(0, 15) ? false : true) ->setCreatedAt(new \DateTime()) - ->setAuthor($user) + ->setAuthor(array_rand($users)) ->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') + ->setText( + 'Some text with [link to @skobkin-ru site](https://skobk.in/) and `code block`'.PHP_EOL. + 'and some quotation:'.PHP_EOL. + '> test test quote'.PHP_EOL. + 'and some text after' + ) ; - if (count($comments) > 0 && rand(0, 1)) { - $comment->setParent($comments[rand(0, count($comments) - 1)]); + if (count($comments) > 0 && mt_rand(0, 1)) { + $comment->setParent($comments[mt_rand(0, count($comments) - 1)]); } $post->addComment($comment); diff --git a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php index ac33393..3e86d1f 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php +++ b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php @@ -12,11 +12,11 @@ class LoadPostData extends AbstractFixture implements OrderedFixtureInterface { public function load(ObjectManager $om) { - /** @var User $user */ - $user = $this->getReference('test_user'); + /** @var User $testUser */ + $testUser = $this->getReference('test_user_99999'); - $post = (new Post('testpost')) - ->setAuthor($user) + $post = (new Post('longpost')) + ->setAuthor($testUser) ->setCreatedAt(new \DateTime()) ->setText('Test post with many comments') ->setPrivate(false) @@ -27,7 +27,7 @@ class LoadPostData extends AbstractFixture implements OrderedFixtureInterface $om->persist($post); $om->flush(); - $this->addReference('test_post', $post); + $this->addReference('test_post_longpost', $post); } public function getOrder() diff --git a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php index 3d43073..e9a4633 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php +++ b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php @@ -9,16 +9,34 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User; class LoadUserData extends AbstractFixture implements OrderedFixtureInterface { + private $users = [ + // 99999 + ['login' => 'testuser', 'name' => 'Test User 1'], + // 99998 + ['login' => 'testuser2', 'name' => 'Test User 2'], + // 99997 + ['login' => 'testuser3', 'name' => 'Test User 3'], + // 99996 + ['login' => 'testuser4', 'name' => 'Test User 4'], + //99995 + ['login' => 'testuser5', 'name' => 'Test User 5'], + ]; + public function load(ObjectManager $om) { - $user = (new User(99999, 'testuser', 'Test User')) - ->setCreatedAt(new \DateTime()) - ; + $userId = 99999; + + foreach ($this->users as $userData) { + $user = (new User($userId--, $userData['login'], $userData['name'])) + ->setCreatedAt(new \DateTime()) + ; + + $om->persist($user); + + $this->addReference('test_user_'.$user->getId(), $user); + } - $om->persist($user); $om->flush(); - - $this->addReference('test_user', $user); } public function getOrder()