|
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
|
|
|
|