Skip to content

Commit f03e360

Browse files
authored
Merge pull request #18 from adhocore/fix-io-case
Fix io case
2 parents 90cdea4 + 5e0e3f1 commit f03e360

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Framework agnostic Command Line Interface utilities and helpers for PHP. Build C
1313
- Inspired by nodejs [commander](https://github.com/tj/commander.js) (thanks tj)
1414
- For PHP7 and for good
1515

16-
![Screen Preview](https://i.imgur.com/qIYg9Zn.gif "Preview from adhocore/phalcon-ext which uses this cli package")
16+
[![Screen Preview](https://i.imgur.com/qIYg9Zn.gif "Preview from adhocore/phalcon-ext which uses this cli package")](https://github.com/adhocore/phalcon-ext/tree/master/example/cli)
1717

1818
#### What's included
1919

@@ -198,6 +198,8 @@ $name = $interactor->prompt('Name', null, $nameValidator, 5);
198198
$interactor->greenBold("The name is: $name", true);
199199
```
200200

201+
![Interactive Preview](https://i.imgur.com/qYBNd29.gif "Interactive Preview")
202+
201203
### IO Components
202204

203205
The interactor is composed of `Ahc\Cli\Input\Reader` and `Ahc\Cli\Output\Writer` while the `Writer` itself is composed of `Ahc\Cli\Output\Color`. All these components can be used standalone.

src/IO/Interactor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ protected function isValidChoice($choice, array $choices, bool $case)
205205
$choices = \array_keys($choices);
206206
}
207207

208-
$fn = ['\strcmp', '\strcasecmp'][(int) $case];
208+
$fn = ['\strcasecmp', '\strcmp'][(int) $case];
209209

210210
foreach ($choices as $option) {
211211
if ($fn($choice, $option) == 0) {

tests/IO/InteractorTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public function test_confirm_more()
5252
$this->assertFalse($i->confirm('OK?'));
5353
}
5454

55+
public function test_case_sensitivity()
56+
{
57+
$i = $this->newInteractor('A'); // `A` is not `a`
58+
$this->assertSame('b', $i->choice('Select one', ['a', 'b', 'c'], 'b', true));
59+
60+
$i = $this->newInteractor('B');
61+
$cho = $i->choice('Select one', ['a', 'b', 'c'], 'c', false);
62+
63+
$this->assertNotSame('c', $cho);
64+
$this->assertSame('B', $cho);
65+
}
66+
5567
public function test_choice()
5668
{
5769
$i = $this->newInteractor('a');

0 commit comments

Comments
 (0)