CompanyUserHelper::haveRegisteredCompanyUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 16
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 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
declare(strict_types = 1);
9
10
namespace PyzTest\Yves\CompanyUser\Helper;
11
12
use Codeception\Module;
13
use Codeception\Stub;
14
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...
15
use Generated\Shared\Transfer\CompanyRoleCollectionTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...yRoleCollectionTransfer 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...
16
use Generated\Shared\Transfer\CompanyRoleTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CompanyRoleTransfer 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...
17
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...
18
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...
19
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...
20
use Generated\Shared\Transfer\PermissionCollectionTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ssionCollectionTransfer 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...
21
use Pyz\Zed\Permission\PermissionDependencyProvider;
22
use Spryker\Zed\CompanyMailConnector\CompanyMailConnectorDependencyProvider;
23
use Spryker\Zed\CompanyMailConnector\Dependency\Facade\CompanyMailConnectorToMailFacadeBridge;
24
use Spryker\Zed\Mail\Business\MailFacadeInterface;
25
use Spryker\Zed\Permission\Business\PermissionFacadeInterface;
26
use Spryker\Zed\PermissionExtension\Dependency\Plugin\PermissionStoragePluginInterface;
27
use SprykerTest\Shared\CompanyUser\Helper\CompanyUserHelper as SprykerTestCompanyUserHelper;
28
use SprykerTest\Shared\Testify\Helper\DependencyHelperTrait;
29
use SprykerTest\Shared\Testify\Helper\LocatorHelperTrait;
30
use SprykerTest\Zed\Company\Helper\CompanyHelper;
31
use SprykerTest\Zed\CompanyBusinessUnit\Helper\CompanyBusinessUnitHelper;
32
use SprykerTest\Zed\CompanyRole\Helper\CompanyRoleHelper;
33
34
class CompanyUserHelper extends Module
35
{
36
    use LocatorHelperTrait;
37
    use DependencyHelperTrait;
38
39
    protected const COMPANY_USER_PERMISSIONS_KEY_LIST = [
40
        'AddCartItemPermissionPlugin',
41
        'ChangeCartItemPermissionPlugin',
42
        'RemoveCartItemPermissionPlugin',
43
    ];
44
45
    public function haveRegisteredCompanyUser(CustomerTransfer $customerTransfer): CompanyUserTransfer
46
    {
47
        $companyTransfer = $this->createCompany();
48
        $companyRoleTransfer = $this->createCompanyRole([
49
            CompanyRoleTransfer::FK_COMPANY => $companyTransfer->getIdCompany(),
50
            CompanyRoleTransfer::PERMISSION_COLLECTION => $this->createPermissionCollectionTransferWithCartPermissions(),
51
        ]);
52
        $companyBusinessUnitTransfer = $this->createCompanyBusinessUnit([
53
            CompanyBusinessUnitTransfer::FK_COMPANY => $companyTransfer->getIdCompany(),
54
        ]);
55
56
        return $this->createCompanyUser([
57
            CompanyUserTransfer::CUSTOMER => $customerTransfer,
58
            CompanyUserTransfer::FK_COMPANY => $companyTransfer->getIdCompany(),
59
            CompanyUserTransfer::FK_COMPANY_BUSINESS_UNIT => $companyBusinessUnitTransfer->getIdCompanyBusinessUnit(),
60
            CompanyUserTransfer::COMPANY_ROLE_COLLECTION => (new CompanyRoleCollectionTransfer())->addRole($companyRoleTransfer),
61
        ]);
62
    }
63
64
    protected function createPermissionCollectionTransferWithCartPermissions(): PermissionCollectionTransfer
65
    {
66
        $this->setDependency(PermissionDependencyProvider::PLUGINS_PERMISSION_STORAGE, [
67
            $this->getPermissionStoragePluginMock(),
68
        ]);
69
70
        $availablePermissions = $this->getPermissionFacade()
71
            ->findMergedRegisteredNonInfrastructuralPermissions()
72
            ->getPermissions();
73
74
        $permissionCollectionTransfer = new PermissionCollectionTransfer();
75
        foreach ($availablePermissions as $permissionTransfer) {
76
            if (!in_array($permissionTransfer->getKey(), static::COMPANY_USER_PERMISSIONS_KEY_LIST, true)) {
77
                continue;
78
            }
79
80
            $permissionCollectionTransfer->addPermission($permissionTransfer);
81
        }
82
83
        return $permissionCollectionTransfer;
84
    }
85
86
    protected function createCompanyRole(array $seed = []): CompanyRoleTransfer
87
    {
88
        return $this->getModule('\\' . CompanyRoleHelper::class)
89
            ->haveCompanyRole($seed);
0 ignored issues
show
Bug introduced by
The method haveCompanyRole() does not exist on Codeception\Module. It seems like you code against a sub-type of Codeception\Module such as SprykerTest\Zed\CompanyR...elper\CompanyRoleHelper. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

89
            ->/** @scrutinizer ignore-call */ haveCompanyRole($seed);
Loading history...
90
    }
91
92
    protected function createCompany(array $seed = []): CompanyTransfer
93
    {
94
        $mailMock = new CompanyMailConnectorToMailFacadeBridge($this->getMailMock());
95
        $this->setDependency(CompanyMailConnectorDependencyProvider::FACADE_MAIL, $mailMock);
96
97
        return $this->getModule('\\' . CompanyHelper::class)->haveCompany($seed + [
0 ignored issues
show
Bug introduced by
The method haveCompany() does not exist on Codeception\Module. It seems like you code against a sub-type of Codeception\Module such as SprykerTest\Zed\Company\Helper\CompanyHelper. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

97
        return $this->getModule('\\' . CompanyHelper::class)->/** @scrutinizer ignore-call */ haveCompany($seed + [
Loading history...
98
                CompanyTransfer::IS_ACTIVE => true,
99
                CompanyTransfer::STATUS => 'approved',
100
            ]);
101
    }
102
103
    protected function createCompanyBusinessUnit(array $seed = []): CompanyBusinessUnitTransfer
104
    {
105
        return $this->getModule('\\' . CompanyBusinessUnitHelper::class)
106
            ->haveCompanyBusinessUnit($seed);
0 ignored issues
show
Bug introduced by
The method haveCompanyBusinessUnit() does not exist on Codeception\Module. It seems like you code against a sub-type of Codeception\Module such as SprykerTest\Zed\CompanyB...mpanyBusinessUnitHelper. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

106
            ->/** @scrutinizer ignore-call */ haveCompanyBusinessUnit($seed);
Loading history...
107
    }
108
109
    protected function createCompanyUser(array $seed = []): CompanyUserTransfer
110
    {
111
        return $this->getModule('\\' . SprykerTestCompanyUserHelper::class)
112
            ->haveCompanyUser($seed + [
0 ignored issues
show
Bug introduced by
The method haveCompanyUser() does not exist on Codeception\Module. It seems like you code against a sub-type of Codeception\Module such as SprykerTest\Shared\Compa...elper\CompanyUserHelper. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

112
            ->/** @scrutinizer ignore-call */ haveCompanyUser($seed + [
Loading history...
113
                CompanyUserTransfer::IS_ACTIVE => true,
114
            ]);
115
    }
116
117
    protected function getPermissionFacade(): PermissionFacadeInterface
118
    {
119
        return $this->getLocator()->permission()->facade();
120
    }
121
122
    protected function getPermissionStoragePluginMock(): PermissionStoragePluginInterface
123
    {
124
        return Stub::makeEmpty(PermissionStoragePluginInterface::class);
125
    }
126
127
    protected function getMailMock(): MailFacadeInterface
128
    {
129
        return Stub::makeEmpty(MailFacadeInterface::class);
130
    }
131
}
132