tddwizard /
magento2-fixtures
| 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
|
|||
| 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 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths