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)
{
/** @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);

View file

@ -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()

View file

@ -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()