Skip to content

Fix io case #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Framework agnostic Command Line Interface utilities and helpers for PHP. Build C
- Inspired by nodejs [commander](https://github.com/tj/commander.js) (thanks tj)
- For PHP7 and for good

![Screen Preview](https://i.imgur.com/qIYg9Zn.gif "Preview from adhocore/phalcon-ext which uses this cli package")
[![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)

#### What's included

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

![Interactive Preview](https://i.imgur.com/qYBNd29.gif "Interactive Preview")

### IO Components

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.
Expand Down
2 changes: 1 addition & 1 deletion src/IO/Interactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected function isValidChoice($choice, array $choices, bool $case)
$choices = \array_keys($choices);
}

$fn = ['\strcmp', '\strcasecmp'][(int) $case];
$fn = ['\strcasecmp', '\strcmp'][(int) $case];

foreach ($choices as $option) {
if ($fn($choice, $option) == 0) {
Expand Down
12 changes: 12 additions & 0 deletions tests/IO/InteractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ public function test_confirm_more()
$this->assertFalse($i->confirm('OK?'));
}

public function test_case_sensitivity()
{
$i = $this->newInteractor('A'); // `A` is not `a`
$this->assertSame('b', $i->choice('Select one', ['a', 'b', 'c'], 'b', true));

$i = $this->newInteractor('B');
$cho = $i->choice('Select one', ['a', 'b', 'c'], 'c', false);

$this->assertNotSame('c', $cho);
$this->assertSame('B', $cho);
}

public function test_choice()
{
$i = $this->newInteractor('a');
Expand Down