Skip to content
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

Add default callback functionality #42

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

yak0d3
Copy link
Member

@yak0d3 yak0d3 commented Mar 7, 2020

Resolves #11

@yak0d3 yak0d3 added the enhancement New feature or request label Mar 7, 2020
@yak0d3 yak0d3 added this to the v0.4.0 milestone Mar 7, 2020
@yak0d3 yak0d3 requested a review from a team March 7, 2020 15:02
@yak0d3 yak0d3 changed the title Default callback Add default callback functionality Mar 7, 2020
Copy link

@nerg4l nerg4l left a comment

Choose a reason for hiding this comment

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

I added some minor comment. If you have time have a look and let me know what do you think.

src/CallbackRegistrar.php Outdated Show resolved Hide resolved
Comment on lines +121 to +129
public function testIfSetDefaultInvokesCallbackIfArgIsString()
{
$this->registrar = Mockery::mock(CallbackRegistrar::class)->makePartial();
$this->registrar->loadCallbacks(['foo' => '\LaraCrafts\GeoRoutes\Tests\Mocks\Callbacks::foo']);

$this->registrar->shouldReceive('callback')->with('foo')->once();

$this->registrar->setDefault('foo');
}
Copy link

Choose a reason for hiding this comment

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

In my opinion this test is unnecessary. You should test the functionality, not the implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Omitting this test means that we'll have non-test covered code, also this test assures that the method does not interpret callables (e.g. FooClass::bar) as strings which would result in an exception.

Copy link

Choose a reason for hiding this comment

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

In my opinion you should test setDefault with getDefault. As I said test the functionality not the implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have thought of that during the testing phase, but that would make the tests tightly coupled and would cause both to fail if the getDefault method is failing. In addition, in my own humble opinion, this is actually testing the functionality which is accepting both callables and strings and in return setting the default value.

Copy link

Choose a reason for hiding this comment

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

To be exact my problem is at line 126. With that you are testing the implementation. However, as far as I know you made setDefault to return something. in that case you can test the return of that function. Lastly, getters and setters are usually "tightly coupled" similarly to push and pop.

src/Callbacks.php Show resolved Hide resolved
@yak0d3 yak0d3 requested a review from nerg4l March 28, 2020 09:03
public function setDefault($callback, ...$arguments)
{
if (is_callable($callback)) {
return $this->default = [$callback, $arguments];
Copy link

Choose a reason for hiding this comment

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

According to the doc block @return void but this clearly returns the default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh that is a typo, forgot to change the auto generated return type, i will also add the @throws exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configurable default callback
3 participants