1 | <?php |
||
24 | final class UserContext implements Context |
||
25 | { |
||
26 | /** |
||
27 | * @var SharedStorageInterface |
||
28 | */ |
||
29 | private $sharedStorage; |
||
30 | |||
31 | /** |
||
32 | * @var UserRepositoryInterface |
||
33 | */ |
||
34 | private $userRepository; |
||
35 | |||
36 | /** |
||
37 | * @var ExampleFactoryInterface |
||
38 | */ |
||
39 | private $userFactory; |
||
40 | |||
41 | /** |
||
42 | * @var ObjectManager |
||
43 | */ |
||
44 | private $userManager; |
||
45 | |||
46 | /** |
||
47 | * @param SharedStorageInterface $sharedStorage |
||
48 | * @param UserRepositoryInterface $userRepository |
||
49 | * @param ExampleFactoryInterface $userFactory |
||
50 | * @param ObjectManager $userManager |
||
51 | */ |
||
52 | public function __construct( |
||
53 | SharedStorageInterface $sharedStorage, |
||
54 | UserRepositoryInterface $userRepository, |
||
55 | ExampleFactoryInterface $userFactory, |
||
56 | ObjectManager $userManager |
||
57 | ) { |
||
58 | $this->sharedStorage = $sharedStorage; |
||
59 | $this->userRepository = $userRepository; |
||
60 | $this->userFactory = $userFactory; |
||
61 | $this->userManager = $userManager; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @Given there is a user :email identified by :password |
||
66 | * @Given there was account of :email with password :password |
||
67 | * @Given there is a user :email |
||
68 | */ |
||
69 | public function thereIsUserIdentifiedBy($email, $password = 'sylius') |
||
70 | { |
||
71 | $user = $this->userFactory->create(['email' => $email, 'password' => $password, 'enabled' => true]); |
||
72 | |||
73 | $this->sharedStorage->set('user', $user); |
||
74 | |||
75 | $this->userRepository->add($user); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @Given the account of :email was deleted |
||
80 | * @Given my account :email was deleted |
||
81 | */ |
||
82 | public function accountWasDeleted($email) |
||
83 | { |
||
84 | /** @var ShopUserInterface $user */ |
||
85 | $user = $this->userRepository->findOneByEmail($email); |
||
86 | |||
87 | $this->sharedStorage->set('customer', $user->getCustomer()); |
||
88 | |||
89 | $this->userRepository->remove($user); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @Given its account was deleted |
||
94 | */ |
||
95 | public function hisAccountWasDeleted() |
||
101 | |||
102 | /** |
||
103 | * @Given /^(this user) is not verified$/ |
||
104 | * @Given /^(I) have not verified my account (?:yet)$/ |
||
105 | */ |
||
106 | public function accountIsNotVerified(UserInterface $user) |
||
112 | |||
113 | /** |
||
114 | * @Given /^(?:(I) have|(this user) has) already received a verification email$/ |
||
115 | */ |
||
116 | public function iHaveReceivedVerificationEmail(UserInterface $user) |
||
120 | |||
121 | /** |
||
122 | * @Given a verification email has already been sent to :email |
||
123 | */ |
||
124 | public function aVerificationEmailHasBeenSentTo($email) |
||
130 | |||
131 | /** |
||
132 | * @Given /^(I) have already verified my account$/ |
||
133 | */ |
||
134 | public function iHaveAlreadyVerifiedMyAccount(UserInterface $user) |
||
140 | |||
141 | /** |
||
142 | * @param UserInterface $user |
||
143 | */ |
||
144 | private function prepareUserVerification(UserInterface $user) |
||
153 | } |
||
154 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: