Skip to content

Commit 6064d88

Browse files
committed
Add case-insensitive option status
1 parent 4c301bb commit 6064d88

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/Domain/DecisionContent.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,26 @@ private function setTitle(string $title): void
134134
*/
135135
private function setStatus(string $status): void
136136
{
137-
$map = [
137+
$statuses = [
138138
self::STATUS_PROPOSED,
139139
self::STATUS_ACCEPTED,
140140
self::STATUS_REJECTED,
141141
self::STATUS_DEPRECATED,
142142
];
143143

144-
if (! in_array($status, $map)) {
144+
$key = array_search(strtolower($status), array_map('strtolower', $statuses));
145+
146+
if (false === $key) {
145147
$message = sprintf(
146148
'Invalid status "%s". Available status: [%s]',
147149
$status,
148-
implode(', ', $map)
150+
implode(', ', $statuses)
149151
);
150152

151153
throw new InvalidArgumentException($message);
152154
}
153155

154-
$this->status = $status;
156+
$this->status = $statuses[$key];
155157
}
156158

157159
/**

tests/Domain/DecisionContentTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ class DecisionContentTest extends TestCase
1010
/**
1111
* @dataProvider providerTestInstanceSuccessfully
1212
*/
13-
public function testInstanceSuccessfully($status)
13+
public function testInstanceSuccessfully($input, $output)
1414
{
15-
$content = new DecisionContent(1, 'Foo', $status);
15+
$content = new DecisionContent(1, 'Foo', $input);
1616

1717
$this->assertEquals(1, $content->getId());
1818
$this->assertEquals('Foo', $content->getTitle());
19-
$this->assertEquals($status, $content->getStatus());
19+
$this->assertEquals($output, $content->getStatus());
2020
}
2121

2222
/**
@@ -38,10 +38,14 @@ public function testInstanceFailureWithStatus()
3838
public function providerTestInstanceSuccessfully()
3939
{
4040
return [
41-
['Proposed'],
42-
['Accepted'],
43-
['Rejected'],
44-
['Deprecated'],
41+
['Proposed', 'Proposed'],
42+
['proposed', 'Proposed'],
43+
['Accepted', 'Accepted'],
44+
['accepted', 'Accepted'],
45+
['Rejected', 'Rejected'],
46+
['rejected', 'Rejected'],
47+
['Deprecated', 'Deprecated'],
48+
['deprecated', 'Deprecated'],
4549
];
4650
}
4751

0 commit comments

Comments
 (0)