-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Use getEncoding() instead of accessing options array directly #7159
Use getEncoding() instead of accessing options array directly #7159
Conversation
@@ -53,7 +53,7 @@ public function filter($value) | |||
} | |||
$value = (string) $value; | |||
|
|||
if ($this->options['encoding'] !== null) { | |||
if (null !== $this->getEncoding()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no yoda condition for consistencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The yoda condition is cosmetic indeed, but so is PSR2 😉 Personally I prefer yoda conditions, because I think defensive programming is good practice.
@Martin-P this requires testing, IMO. Mocking the |
How can I mock the method of the same class? This does not work: public function testFilterUsesGetEncoding()
{
$filterMock = $this->getMock('StringToLowerFilter');
$filterMock->expects($this->once())
->method('getEncoding')
->with();
$filterMock->filter('foo');
}
Adding the |
@Martin-P add |
*/ | ||
public function testFilterUsesGetEncodingMethod() | ||
{ | ||
$filterMock = $this->getMock('\Zend\Filter\StringToLower', array('getEncoding')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that in strings you always deal with an absolute namespace, therefore the leading \
is not needed and should be avoided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay, I have removed them.
Use getEncoding() instead of accessing options array directly
Merged to develop for release with 2.4. |
…fix/abstract-unicode-filters Use getEncoding() instead of accessing options array directly
Fix for issue #7147. Both
Zend\Filter\StringToLower
andZend\Filter\StringToUpper
extendZend\Filter\AbstractUnicode
.No new tests, but that is because I don't see a way to test this change. If anyone got suggestions on how to test it, I will add the tests.