Skip to content

function addCustomControlMappings() #114

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 10 commits into from
May 8, 2018
Merged

Conversation

Lynesth
Copy link
Collaborator

@Lynesth Lynesth commented May 8, 2018

Just to allow doing

$menu->addCustomControlMappings([
    "a" => $thisCallable,
    "b" => $otherCallable,
    "c" => $someCallable,
    "x" => new ExitAction
]);

instead of

$menu->addCustomControlMapping("a", $thisCallable);
$menu->addCustomControlMapping("b", $otherCallable);
$menu->addCustomControlMapping("c", $someCallable);
$menu->addCustomControlMapping("x", new ExitAction);

@codecov-io
Copy link

codecov-io commented May 8, 2018

Codecov Report

Merging #114 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #114      +/-   ##
============================================
+ Coverage     96.86%   96.86%   +<.01%     
- Complexity      338      340       +2     
============================================
  Files            23       23              
  Lines          1051     1054       +3     
============================================
+ Hits           1018     1021       +3     
  Misses           33       33
Impacted Files Coverage Δ Complexity Δ
src/CliMenu.php 92.3% <100%> (+0.11%) 77 <2> (+2) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 32e9b55...df04578. Read the comment docs.

@Lynesth
Copy link
Collaborator Author

Lynesth commented May 8, 2018

I finally worked out this whole phpunit thing. I'm just not undertanding why the last test fails.
I'm counting on your help @AydinHassan :p

$first = true;
$this->terminal->expects($this->any())
->method('read')
->will(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can just use ->willReturn('c', 'x'). c will be returned on the first call to read and x on the next :)

Copy link
Collaborator Author

@Lynesth Lynesth May 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ! You've got to be kidding me. What will it return on subsequent calls ? 'x' ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it just returns null after anything you don't specify.

$this->expectExceptionMessage('Cannot rebind this input');

$menu = new CliMenu('PHP School FTW', []);
$menu->addCustomControlMappings([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a little while to figure this - you actually only send one element to the method, the second c key overwrites the first ! So it's actually not possible to call this method once and cause a rebind exception, you'd have to call it twice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahaha, of course ! Thank you !

@AydinHassan AydinHassan merged commit 94a9c54 into php-school:master May 8, 2018
@AydinHassan AydinHassan added this to the 3.0 milestone May 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants