Completed
Push — master ( 860366...55daec )
by Kamil
19:37
created

TestUserFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
c 2
b 1
f 0
lcom 1
cbo 1
dl 0
loc 61
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 17 1
A createDefault() 0 9 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\CoreBundle\Test\Factory;
13
14
use Sylius\Component\Core\Test\Factory\TestUserFactoryInterface;
15
use Sylius\Component\Resource\Factory\FactoryInterface;
16
use Symfony\Component\Security\Core\User\UserInterface;
17
18
/**
19
 * @author Mateusz Zalewski <[email protected]>
20
 */
21
class TestUserFactory implements TestUserFactoryInterface
22
{
23
    const DEFAULT_USER_EMAIL = '[email protected]';
24
    const DEFAULT_USER_FIRST_NAME = 'John';
25
    const DEFAULT_USER_LAST_NAME = 'Doe';
26
    const DEFAULT_USER_PASSWORD = 'password123';
27
28
    /**
29
     * @var FactoryInterface
30
     */
31
    private $customerFactory;
32
33
    /**
34
     * @var FactoryInterface
35
     */
36
    private $userFactory;
37
38
    /**
39
     * @param FactoryInterface $customerFactory
40
     * @param FactoryInterface $userFactory
41
     */
42
    public function __construct(FactoryInterface $customerFactory, FactoryInterface $userFactory)
43
    {
44
        $this->customerFactory = $customerFactory;
45
        $this->userFactory = $userFactory;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function create($email, $password, $firstName = self::DEFAULT_USER_FIRST_NAME, $lastName = self::DEFAULT_USER_LAST_NAME)
52
    {
53
        $customer = $this->customerFactory->createNew();
54
55
        $customer->setFirstName($firstName);
56
        $customer->setLastName($lastName);
57
58
        $user = $this->userFactory->createNew();
59
60
        $user->setCustomer($customer);
61
        $user->setUsername($email);
62
        $user->setEmail($email);
63
        $user->setPlainPassword($password);
64
        $user->enable();
65
66
        return $user;
67
    }
68
69
    /**
70
     * @return UserInterface
71
     */
72
    public function createDefault()
73
    {
74
        return $this->create(
75
            self::DEFAULT_USER_EMAIL,
76
            self::DEFAULT_USER_PASSWORD,
77
            self::DEFAULT_USER_FIRST_NAME,
78
            self::DEFAULT_USER_LAST_NAME
79
        );
80
    }
81
}
82