Completed
Push — master ( 692aa1...25e5a7 )
by Paweł
60:22
created

LoadUsersData::load()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
ccs 11
cts 11
cp 1
cc 1
eloc 19
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Fixtures Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\FixturesBundle\DataFixtures\ORM;
16
17
use Doctrine\Common\DataFixtures\FixtureInterface;
18
use Doctrine\Common\Persistence\ObjectManager;
19
use SWP\Bundle\CoreBundle\Model\UserInterface;
20
use SWP\Bundle\FixturesBundle\AbstractFixture;
21
22
class LoadUsersData extends AbstractFixture implements FixtureInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 100
    public function load(ObjectManager $manager)
28
    {
29 100
        $userManager = $this->container->get('fos_user.user_manager');
30
31 100
        /** @var UserInterface $user */
32 100
        $user = $userManager->createUser();
33 100
        $user->setEnabled(true);
34 100
        $user->setUsername('test.user');
35 100
        $user->setEmail('[email protected]');
36
        $user->setPlainPassword('testPassword');
37 100
38
        $userManager->updateUser($user);
39 100
40 100
        $apiKey = $this->container->get('swp.factory.api_key')->create($user, base64_encode('test_token:'));
41 100
        $this->container->get('swp.repository.api_key')->add($apiKey);
42
43
        /** @var UserInterface $user */
44
        $user = $userManager->createUser();
45
        $user->setEnabled(true);
46
        $user->setUsername('test.client1');
47
        $user->setEmail('[email protected]');
48
        $user->setPlainPassword('testPassword');
49
        $user->setTenantCode('456def');
50
51
        $userManager->updateUser($user);
52
53
        $apiKey = $this->container->get('swp.factory.api_key')->create($user, base64_encode('client1_token'));
54
        $this->container->get('swp.repository.api_key')->add($apiKey);
55
    }
56
}
57