Skip to content

Commit 9828d4c

Browse files
HP-1631: created Behat test for check ActionStateDeterminer class
1 parent ebdf697 commit 9828d4c

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/customer/Customer.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ class Customer implements CustomerInterface
3737
*/
3838
protected $sellers = [];
3939

40-
/**
41-
* @var string|null
42-
*/
43-
protected ?string $state = null;
40+
protected ?CustomerState $state = null;
4441

45-
public function __construct($id, $login, CustomerInterface $seller = null, ?string $state = null)
42+
public function __construct($id, $login, CustomerInterface $seller = null, ?CustomerState $state = null)
4643
{
4744
$this->id = $id;
4845
$this->login = $login;
@@ -82,11 +79,18 @@ public function getSeller()
8279
/**
8380
* {@inheritdoc}
8481
*/
85-
public function getState(): ?string
82+
public function getState(): ?CustomerState
8683
{
8784
return $this->state;
8885
}
8986

87+
public function setState(CustomerState $state): self
88+
{
89+
$this->state = $state;
90+
91+
return $this;
92+
}
93+
9094
public function isDeleted(): bool
9195
{
9296
return CustomerState::isDeleted($this);
@@ -100,7 +104,12 @@ public static function fromArray(array $info)
100104
$seller = null;
101105
}
102106

103-
return new static($info['id'], $info['login'], $seller, $info['state'] ?? null);
107+
return new static(
108+
$info['id'],
109+
$info['login'],
110+
$seller,
111+
isset($info['state']) ? CustomerState::from($info['state']) : null,
112+
);
104113
}
105114

106115
public function jsonSerialize(): array

src/customer/CustomerInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ public function getSeller();
3838

3939
/**
4040
* Get Customer state.
41-
* @return null|string
41+
* @return null|CustomerState
4242
*/
43-
public function getState(): ?string;
43+
public function getState(): ?CustomerState;
44+
45+
public function setState(CustomerState $state): self;
4446

4547
public function isDeleted(): bool;
4648
}

src/customer/CustomerState.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ enum CustomerState: string
1111

1212
public static function isDeleted(CustomerInterface $customer): bool
1313
{
14-
return self::tryFrom((string)$customer->getState()) === self::DELETED;
14+
return $customer->getState() === self::DELETED;
15+
}
16+
17+
public static function deleted(): CustomerState
18+
{
19+
return self::DELETED;
1520
}
1621
}

0 commit comments

Comments
 (0)