Test Setup Failed
Push — master ( 93071b...1b2df8 )
by Alexey
02:48
created

LoadSubscribersData::getRandomSubscribers()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 21
rs 9.0534
ccs 0
cts 15
cp 0
cc 4
eloc 10
nc 5
nop 2
crap 20
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\DataFixtures\ORM;
4
5
use Doctrine\Common\DataFixtures\AbstractFixture;
6
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
7
use Doctrine\Common\Persistence\ObjectManager;
8
use Skobkin\Bundle\PointToolsBundle\Entity\Subscription;
9
use Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent;
10
use Skobkin\Bundle\PointToolsBundle\Entity\User;
11
12
/**
13
 * Load user subscriptions
14
 */
15
class LoadSubscribersData extends AbstractFixture implements OrderedFixtureInterface
16
{
17
    public function load(ObjectManager $om)
18
    {
19
        /** @var User[] $users */
20
        $users = [
21
            99999 => $this->getReference('test_user_99999'),
22
            99998 => $this->getReference('test_user_99998'),
23
            99997 => $this->getReference('test_user_99997'),
24
            99996 => $this->getReference('test_user_99996'),
25
            99995 => $this->getReference('test_user_99995'),
26
        ];
27
28
        $subscriptions = [
29
            99999 => [99998, 99997, 99996, 99995],
30
            99998 => [99999, 99997],
31
            99997 => [99999],
32
        ];
33
34
        foreach ($users as $key => $user) {
35
            foreach ($subscriptions[$key] as $userId) {
36
                $subscriber = $users[$userId];
37
                $subscription = new Subscription($user, $subscriber);
38
                $subscriptionEvent = new SubscriptionEvent($user, $subscriber, SubscriptionEvent::ACTION_SUBSCRIBE);
39
                $om->persist($subscription);
40
                $om->persist($subscriptionEvent);
41
                $user->addSubscriber($subscription);
42
            }
43
        }
44
45
        $om->flush();
46
    }
47
48
    public function getOrder(): int
49
    {
50
        return 4;
51
    }
52
}