Many test users in fixtures

This commit is contained in:
Alexey Skobkin 2016-12-12 01:53:56 +03:00
parent 9264170d0b
commit 22784542bf
3 changed files with 48 additions and 22 deletions

View file

@ -14,28 +14,36 @@ class LoadCommentsData extends AbstractFixture implements OrderedFixtureInterfac
public function load(ObjectManager $om) public function load(ObjectManager $om)
{ {
/** @var Post $post */ /** @var Post $post */
$post = $this->getReference('test_post'); $post = $this->getReference('test_post_longpost');
/** @var User $user */ /** @var User[] $users */
$user = $this->getReference('test_user'); $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 = []; $comments = [];
foreach (range(1, 10000) as $num) { foreach (range(1, 10000) as $num) {
$comment = (new Comment()) $comment = (new Comment())
->setNumber($num) ->setNumber($num)
->setDeleted(rand(0, 15) ? false : true) ->setDeleted(mt_rand(0, 15) ? false : true)
->setCreatedAt(new \DateTime()) ->setCreatedAt(new \DateTime())
->setAuthor($user) ->setAuthor(array_rand($users))
->setRec(false) ->setRec(false)
->setText('Some text with [link to @skobkin-ru site](https://skobk.in/) and `code block` ->setText(
and some quotation: 'Some text with [link to @skobkin-ru site](https://skobk.in/) and `code block`'.PHP_EOL.
> test test quote 'and some quotation:'.PHP_EOL.
and some text after') '> test test quote'.PHP_EOL.
'and some text after'
)
; ;
if (count($comments) > 0 && rand(0, 1)) { if (count($comments) > 0 && mt_rand(0, 1)) {
$comment->setParent($comments[rand(0, count($comments) - 1)]); $comment->setParent($comments[mt_rand(0, count($comments) - 1)]);
} }
$post->addComment($comment); $post->addComment($comment);

View file

@ -12,11 +12,11 @@ class LoadPostData extends AbstractFixture implements OrderedFixtureInterface
{ {
public function load(ObjectManager $om) public function load(ObjectManager $om)
{ {
/** @var User $user */ /** @var User $testUser */
$user = $this->getReference('test_user'); $testUser = $this->getReference('test_user_99999');
$post = (new Post('testpost')) $post = (new Post('longpost'))
->setAuthor($user) ->setAuthor($testUser)
->setCreatedAt(new \DateTime()) ->setCreatedAt(new \DateTime())
->setText('Test post with many comments') ->setText('Test post with many comments')
->setPrivate(false) ->setPrivate(false)
@ -27,7 +27,7 @@ class LoadPostData extends AbstractFixture implements OrderedFixtureInterface
$om->persist($post); $om->persist($post);
$om->flush(); $om->flush();
$this->addReference('test_post', $post); $this->addReference('test_post_longpost', $post);
} }
public function getOrder() public function getOrder()

View file

@ -9,16 +9,34 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User;
class LoadUserData extends AbstractFixture implements OrderedFixtureInterface 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) public function load(ObjectManager $om)
{ {
$user = (new User(99999, 'testuser', 'Test User')) $userId = 99999;
foreach ($this->users as $userData) {
$user = (new User($userId--, $userData['login'], $userData['name']))
->setCreatedAt(new \DateTime()) ->setCreatedAt(new \DateTime())
; ;
$om->persist($user); $om->persist($user);
$om->flush();
$this->addReference('test_user', $user); $this->addReference('test_user_'.$user->getId(), $user);
}
$om->flush();
} }
public function getOrder() public function getOrder()