Completed
Push — symfony-flex ( 2a70a0 )
by Kamil
26:10 queued 12:40
created

RegistrationAfterCheckoutContext::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Context\Ui\Shop\Checkout;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Behat\Element\Shop\Account\RegisterElementInterface;
18
use Sylius\Behat\Page\Shop\Account\DashboardPageInterface;
19
use Sylius\Behat\Page\Shop\Account\LoginPageInterface;
20
use Sylius\Behat\Page\Shop\Account\VerificationPageInterface;
21
use Sylius\Behat\Page\Shop\HomePageInterface;
22
use Sylius\Behat\Page\Shop\Order\ThankYouPageInterface;
23
use Sylius\Behat\Service\NotificationCheckerInterface;
24
use Sylius\Behat\Service\SharedStorageInterface;
25
use Sylius\Component\Core\Model\CustomerInterface;
26
use Webmozart\Assert\Assert;
27
28
final class RegistrationAfterCheckoutContext implements Context
29
{
30
    /** @var SharedStorageInterface */
31
    private $sharedStorage;
32
33
    /** @var LoginPageInterface */
34
    private $loginPage;
35
36
    /** @var ThankYouPageInterface */
37
    private $thankYouPage;
38
39
    /** @var DashboardPageInterface */
40
    private $dashboardPage;
41
42
    /** @var HomePageInterface */
43
    private $homePage;
44
45
    /** @var VerificationPageInterface */
46
    private $verificationPage;
47
48
    /** @var RegisterElementInterface */
49
    private $registerElement;
50
51
    /** @var NotificationCheckerInterface */
52
    private $notificationChecker;
53
54
    public function __construct(
55
        SharedStorageInterface $sharedStorage,
56
        LoginPageInterface $loginPage,
57
        ThankYouPageInterface $thankYouPage,
58
        DashboardPageInterface $dashboardPage,
59
        HomePageInterface $homePage,
60
        VerificationPageInterface $verificationPage,
61
        RegisterElementInterface $registerElement,
62
        NotificationCheckerInterface $notificationChecker
63
    ) {
64
        $this->sharedStorage = $sharedStorage;
65
        $this->loginPage = $loginPage;
66
        $this->thankYouPage = $thankYouPage;
67
        $this->dashboardPage = $dashboardPage;
68
        $this->homePage = $homePage;
69
        $this->verificationPage = $verificationPage;
70
        $this->registerElement = $registerElement;
71
        $this->notificationChecker = $notificationChecker;
72
    }
73
74
    /**
75
     * @When I specify a password as :password
76
     */
77
    public function iSpecifyThePasswordAs(string $password): void
78
    {
79
        $this->registerElement->specifyPassword($password);
80
        $this->sharedStorage->set('password', $password);
81
    }
82
83
    /**
84
     * @When /^I confirm (this password)$/
85
     */
86
    public function iConfirmThisPassword(string $password): void
87
    {
88
        $this->registerElement->verifyPassword($password);
89
    }
90
91
    /**
92
     * @When I register this account
93
     */
94
    public function iRegisterThisAccount(): void
95
    {
96
        $this->registerElement->register();
97
    }
98
99
    /**
100
     * @When I verify my account using link sent to :customer
101
     */
102
    public function iVerifyMyAccountUsingLink(CustomerInterface $customer): void
103
    {
104
        $user = $customer->getUser();
105
        Assert::notNull($user, 'No account for given customer');
106
107
        $this->verificationPage->verifyAccount($user->getEmailVerificationToken());
108
    }
109
110
    /**
111
     * @Then the registration form should be prefilled with :email email
112
     */
113
    public function theRegistrationFormShouldBePrefilledWithEmail(string $email): void
114
    {
115
        $this->thankYouPage->createAccount();
116
117
        Assert::same($this->registerElement->getEmail(), $email);
118
    }
119
120
    /**
121
     * @Then I should be able to log in as :email with :password password
122
     */
123
    public function iShouldBeAbleToLogInAsWithPassword(string $email, string $password): void
124
    {
125
        $this->loginPage->open();
126
        $this->loginPage->specifyUsername($email);
127
        $this->loginPage->specifyPassword($password);
128
        $this->loginPage->logIn();
129
130
        Assert::true($this->homePage->hasLogoutButton());
131
    }
132
}
133