Passed
Pull Request — master (#319)
by Dmitry
22:36
created

CompanyUserAuthAccessTokensRestApiFixtures   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 190
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 47
dl 0
loc 190
c 1
b 0
f 0
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A createCustomer() 0 5 1
A createOauthResponseForCustomerWithTwoCompanyUsers() 0 7 1
A createOauthResponseForNotCompanyUser() 0 6 1
A getNonDefaultCompanyUserTransfer() 0 3 1
A createCompanyUser() 0 17 1
A createCustomerWithTwoCompanyUsers() 0 14 1
A createCustomerWithCompanyUser() 0 10 1
A getOauthResponseTransferForCompanyUser() 0 3 1
A createOauthResponseForCompanyUser() 0 6 1
A getOauthResponseTransferForNonCompanyUser() 0 3 1
A getOauthResponseTransferForCustomerWithTwoCompanyUsers() 0 3 1
A buildFixtures() 0 9 1
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace PyzTest\Glue\CompanyUserAuth\RestApi;
9
10
use Generated\Shared\Transfer\CompanyBusinessUnitTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...anyBusinessUnitTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Generated\Shared\Transfer\CompanyTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CompanyTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Generated\Shared\Transfer\CompanyUserTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CompanyUserTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Generated\Shared\Transfer\CustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CustomerTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Generated\Shared\Transfer\OauthResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OauthResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use PyzTest\Glue\CompanyUserAuth\CompanyUserAuthRestApiTester;
16
use SprykerTest\Shared\Testify\Fixtures\FixturesBuilderInterface;
17
use SprykerTest\Shared\Testify\Fixtures\FixturesContainerInterface;
18
19
class CompanyUserAuthAccessTokensRestApiFixtures implements FixturesBuilderInterface, FixturesContainerInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    protected const TEST_PASSWORD = 'change123';
25
26
    /**
27
     * @var \Generated\Shared\Transfer\OauthResponseTransfer
28
     */
29
    protected OauthResponseTransfer $oauthResponseTransferForCompanyUser;
30
31
    /**
32
     * @var \Generated\Shared\Transfer\OauthResponseTransfer
33
     */
34
    protected OauthResponseTransfer $oauthResponseTransferForNonCompanyUser;
35
36
    /**
37
     * @var \Generated\Shared\Transfer\OauthResponseTransfer
38
     */
39
    protected OauthResponseTransfer $oauthResponseTransferForCustomerWithTwoCompanyUsers;
40
41
    /**
42
     * @var \Generated\Shared\Transfer\CompanyUserTransfer
43
     */
44
    protected CompanyUserTransfer $nonDefaultCompanyUserTransfer;
45
46
    /**
47
     * @param \PyzTest\Glue\CompanyUserAuth\CompanyUserAuthRestApiTester $I
48
     *
49
     * @return \SprykerTest\Shared\Testify\Fixtures\FixturesContainerInterface
50
     */
51
    public function buildFixtures(CompanyUserAuthRestApiTester $I): FixturesContainerInterface
52
    {
53
        $I->haveCompanyMailConnectorToMailDependency();
54
55
        $this->oauthResponseTransferForCompanyUser = $this->createOauthResponseForCompanyUser($I);
56
        $this->oauthResponseTransferForNonCompanyUser = $this->createOauthResponseForNotCompanyUser($I);
57
        $this->oauthResponseTransferForCustomerWithTwoCompanyUsers = $this->createOauthResponseForCustomerWithTwoCompanyUsers($I);
58
59
        return $this;
60
    }
61
62
    /**
63
     * @return \Generated\Shared\Transfer\OauthResponseTransfer
64
     */
65
    public function getOauthResponseTransferForCompanyUser(): OauthResponseTransfer
66
    {
67
        return $this->oauthResponseTransferForCompanyUser;
68
    }
69
70
    /**
71
     * @return \Generated\Shared\Transfer\OauthResponseTransfer
72
     */
73
    public function getOauthResponseTransferForNonCompanyUser(): OauthResponseTransfer
74
    {
75
        return $this->oauthResponseTransferForNonCompanyUser;
76
    }
77
78
    /**
79
     * @return \Generated\Shared\Transfer\OauthResponseTransfer
80
     */
81
    public function getOauthResponseTransferForCustomerWithTwoCompanyUsers(): OauthResponseTransfer
82
    {
83
        return $this->oauthResponseTransferForCustomerWithTwoCompanyUsers;
84
    }
85
86
    /**
87
     * @return \Generated\Shared\Transfer\CompanyUserTransfer
88
     */
89
    public function getNonDefaultCompanyUserTransfer(): CompanyUserTransfer
90
    {
91
        return $this->nonDefaultCompanyUserTransfer;
92
    }
93
94
    /**
95
     * @param \PyzTest\Glue\CompanyUserAuth\CompanyUserAuthRestApiTester $I
96
     *
97
     * @return \Generated\Shared\Transfer\OauthResponseTransfer
98
     */
99
    protected function createOauthResponseForCompanyUser(CompanyUserAuthRestApiTester $I): OauthResponseTransfer
100
    {
101
        $customerTransfer = $this->createCustomerWithCompanyUser($I);
102
        $customerTransfer = $I->confirmCustomer($customerTransfer);
103
104
        return $I->haveAuthorizationToGlue($customerTransfer);
105
    }
106
107
    /**
108
     * @param \PyzTest\Glue\CompanyUserAuth\CompanyUserAuthRestApiTester $I
109
     *
110
     * @return \Generated\Shared\Transfer\OauthResponseTransfer
111
     */
112
    protected function createOauthResponseForNotCompanyUser(CompanyUserAuthRestApiTester $I): OauthResponseTransfer
113
    {
114
        $customerTransfer = $this->createCustomer($I);
115
        $customerTransfer = $I->confirmCustomer($customerTransfer);
116
117
        return $I->haveAuthorizationToGlue($customerTransfer);
118
    }
119
120
    /**
121
     * @param \PyzTest\Glue\CompanyUserAuth\CompanyUserAuthRestApiTester $I
122
     *
123
     * @return \Generated\Shared\Transfer\OauthResponseTransfer
124
     */
125
    protected function createOauthResponseForCustomerWithTwoCompanyUsers(
126
        CompanyUserAuthRestApiTester $I,
127
    ): OauthResponseTransfer {
128
        $customerTransfer = $this->createCustomerWithTwoCompanyUsers($I);
129
        $customerTransfer = $I->confirmCustomer($customerTransfer);
130
131
        return $I->haveAuthorizationToGlue($customerTransfer);
132
    }
133
134
    /**
135
     * @param \PyzTest\Glue\CompanyUserAuth\CompanyUserAuthRestApiTester $I
136
     *
137
     * @return \Generated\Shared\Transfer\CustomerTransfer
138
     */
139
    protected function createCustomerWithCompanyUser(CompanyUserAuthRestApiTester $I): CustomerTransfer
140
    {
141
        $customerTransfer = $I->haveCustomer([
142
            CustomerTransfer::PASSWORD => static::TEST_PASSWORD,
143
            CustomerTransfer::NEW_PASSWORD => static::TEST_PASSWORD,
144
        ]);
145
146
        $this->createCompanyUser($I, $customerTransfer);
147
148
        return $customerTransfer;
149
    }
150
151
    /**
152
     * @param \PyzTest\Glue\CompanyUserAuth\CompanyUserAuthRestApiTester $I
153
     *
154
     * @return \Generated\Shared\Transfer\CustomerTransfer
155
     */
156
    protected function createCustomerWithTwoCompanyUsers(CompanyUserAuthRestApiTester $I): CustomerTransfer
157
    {
158
        $customerTransfer = $I->haveCustomer([
159
            CustomerTransfer::PASSWORD => static::TEST_PASSWORD,
160
            CustomerTransfer::NEW_PASSWORD => static::TEST_PASSWORD,
161
        ]);
162
163
        $this->createCompanyUser($I, $customerTransfer, [
164
            CompanyUserTransfer::IS_DEFAULT => true,
165
        ]);
166
167
        $this->nonDefaultCompanyUserTransfer = $this->createCompanyUser($I, $customerTransfer);
168
169
        return $customerTransfer;
170
    }
171
172
    /**
173
     * @param \PyzTest\Glue\CompanyUserAuth\CompanyUserAuthRestApiTester $I
174
     *
175
     * @return \Generated\Shared\Transfer\CustomerTransfer
176
     */
177
    protected function createCustomer(CompanyUserAuthRestApiTester $I): CustomerTransfer
178
    {
179
        return $I->haveCustomer([
180
            CustomerTransfer::PASSWORD => static::TEST_PASSWORD,
181
            CustomerTransfer::NEW_PASSWORD => static::TEST_PASSWORD,
182
        ]);
183
    }
184
185
    /**
186
     * @param \PyzTest\Glue\CompanyUserAuth\CompanyUserAuthRestApiTester $I
187
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
188
     * @param array $seed
189
     *
190
     * @return \Generated\Shared\Transfer\CompanyUserTransfer
191
     */
192
    protected function createCompanyUser(
193
        CompanyUserAuthRestApiTester $I,
194
        CustomerTransfer $customerTransfer,
195
        array $seed = [],
196
    ): CompanyUserTransfer {
197
        $companyTransfer = $I->haveActiveCompany([
198
            CompanyTransfer::STATUS => 'approved',
199
        ]);
200
201
        $companyBusinessUnitTransfer = $I->haveCompanyBusinessUnit([
202
            CompanyBusinessUnitTransfer::FK_COMPANY => $companyTransfer->getIdCompany(),
203
        ]);
204
205
        return $I->haveCompanyUser($seed + [
206
            CompanyUserTransfer::CUSTOMER => $customerTransfer,
207
            CompanyUserTransfer::FK_COMPANY => $companyTransfer->getIdCompany(),
208
            CompanyUserTransfer::FK_COMPANY_BUSINESS_UNIT => $companyBusinessUnitTransfer->getIdCompanyBusinessUnit(),
209
        ]);
210
    }
211
}
212