CustomerFixture   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 42.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 96
ccs 18
cts 42
cp 0.4286
rs 10
wmc 15

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getDefaultBillingAddressId() 0 3 1
A getDefaultShippingAddressId() 0 3 1
A getCustomer() 0 3 1
A getConfirmation() 0 3 1
A logout() 0 8 2
A getId() 0 3 1
A rollback() 0 3 1
A login() 0 8 2
A getOtherAddressId() 0 3 1
A getEmail() 0 3 1
A getNonDefaultAddressIds() 0 6 1
A getAllAddressIds() 0 7 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TddWizard\Fixtures\Customer;
5
6
use Magento\Customer\Api\Data\AddressInterface;
7
use Magento\Customer\Api\Data\CustomerInterface;
8
use Magento\Customer\Model\Session;
9
use Magento\TestFramework\Helper\Bootstrap;
0 ignored issues
show
Bug introduced by
The type Magento\TestFramework\Helper\Bootstrap 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...
10
11
/**
12
 * Object that can be returned from customer fixture, contains ids for test expectations
13
 */
14
class CustomerFixture
15
{
16
    /**
17
     * @var CustomerInterface
18
     */
19
    private $customer;
20
21 29
    public function __construct(CustomerInterface $customer)
22
    {
23 29
        $this->customer = $customer;
24 29
    }
25
26
    public function getCustomer(): CustomerInterface
27
    {
28
        return $this->customer;
29
    }
30
31
    public function getDefaultShippingAddressId(): int
32
    {
33
        return (int) $this->customer->getDefaultShipping();
34
    }
35
36
    public function getDefaultBillingAddressId(): int
37
    {
38
        return (int) $this->customer->getDefaultBilling();
39
    }
40
41
    public function getOtherAddressId(): int
42
    {
43
        return $this->getNonDefaultAddressIds()[0];
44
    }
45
46
    /**
47
     * @return int[]
48
     */
49
    public function getNonDefaultAddressIds(): array
50
    {
51
        return array_values(
52
            array_diff(
53
                $this->getAllAddressIds(),
54
                [$this->getDefaultBillingAddressId(), $this->getDefaultShippingAddressId()]
55
            )
56
        );
57
    }
58
59
    /**
60
     * @return int[]
61
     */
62
    public function getAllAddressIds(): array
63
    {
64
        return array_map(
65
            function (AddressInterface $address): int {
66
                return (int)$address->getId();
67
            },
68
            (array)$this->customer->getAddresses()
69
        );
70
    }
71
72 28
    public function getId(): int
73
    {
74 28
        return (int) $this->customer->getId();
75
    }
76
77
    public function getConfirmation(): string
78
    {
79
        return (string)$this->customer->getConfirmation();
80
    }
81
82
    public function getEmail(): string
83
    {
84
        return $this->customer->getEmail();
85
    }
86
87 16
    public function login(Session $session = null): void
88
    {
89 16
        if ($session === null) {
90 16
            $objectManager = Bootstrap::getObjectManager();
91 16
            $objectManager->removeSharedInstance(Session::class);
92 16
            $session = $objectManager->get(Session::class);
93
        }
94 16
        $session->setCustomerId($this->getId());
95 16
    }
96
97 14
    public function logout(Session $session = null): void
98
    {
99 14
        if ($session === null) {
100 14
            $objectManager = Bootstrap::getObjectManager();
101 14
            $session = $objectManager->get(Session::class);
102
        }
103
104 14
        $session->logout();
105 14
    }
106
107
    public function rollback(): void
108
    {
109
        CustomerFixtureRollback::create()->execute($this);
110
    }
111
}
112