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

Fixed a bug with string setters being executed as callables #35

Merged
merged 3 commits into from
Oct 16, 2018

Conversation

davidyell
Copy link
Contributor

@davidyell davidyell commented Oct 15, 2018

This bug fixes an issue with the behaviour which arises if a setter is used and a string is passed which matches a PHP function name. The function is then executed as a callable and unknown side effects are created.

I have fixed this bug and also included a new test-case to cover the regression.

/cc @ogrrd

@@ -180,4 +181,25 @@ public function testWithTranslation()
->all();
$this->assertEquals(2, $records->count());
}

public function testDuplicateWithSetters()
Copy link
Collaborator

@ADmad ADmad Oct 15, 2018

Choose a reason for hiding this comment

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

This new test passes even without the change you have done to the behavior, so it's not really useful 🙂.

In general when fixing a bug write a failing test first and then fix the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 I'll have to revise this test.

@@ -292,7 +292,7 @@ protected function _doAction($action, EntityInterface $entity, $prop, $value = n
break;

case 'set':
if (is_callable($value)) {
if (is_callable($value) && !is_string($value)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Micro optimisation, the !is_string() check could be done first.

@segy
Copy link
Member

segy commented Oct 16, 2018

thanks!

@segy segy merged commit 6ac4f41 into riesenia:master Oct 16, 2018
@davidyell davidyell deleted the non-callable-setters branch October 17, 2018 11:13
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