[Flow] Best way to test protected method
Christian Loock
chl at vkf-renzel.de
Tue Oct 14 09:20:00 CEST 2014
So here is what i basically ended up doing:
https://sebastian-bergmann.de/archives/881-Testing-Your-Privates.html
Works good and i think in my case it makes sense, to test the specific
bug fix.
Cheers,
Christian
Am 13.10.2014 um 15:58 schrieb Aimo Kuenkel:
> Thanks for the details, I'm totally with you regarding protected method testing in unit tests, that's why i wrote that library.
> But as far as i know there are only explicit tests for public methods - didn't have a look into the core for quite some time though, so maybe someone should confirm this please.
>
> Greetings,
>
> Aimo
>
> -----Ursprüngliche Nachricht-----
> Von: flow-bounces at lists.typo3.org [mailto:flow-bounces at lists.typo3.org] Im Auftrag von Christian Loock
> Gesendet: Montag, 13. Oktober 2014 15:53
> An: TYPO3 Flow mailing list
> Betreff: Re: [Flow] Best way to test protected method
>
> Well yes, you might be right. But also, if a protected method only does a little isolated thing that went wrong, it seems a bit unpractical to me to go all the way up to the actual public method that will somehow call it. The method I speak of is TYPO3\Flow\Object\Proxy\Compiler::cacheOriginalClassFileAndProxyCode .
> If I were to call the complete compile method, this would be way to complex I feel like, especially when all I really want to test is, if a regex matches correctly. Thats why I put the part that actually does the regex into a separate protected method to be able to only test that little part that is affected by my change. If I were forced to only call the compile method, I actually would have no freaking idea on how to actually test the thing I want to test. :(
>
>
>
> Am 13.10.2014 um 15:48 schrieb Aimo Kuenkel:
>> If there's a bug in a protected method, then there will be a public method using it, hence having that bug, too.
>> In the end (as i understand the 'normal' way of unit testing) it's only a bug if some functionality that you can use from the outside is having that bug (please correct me here if i'm wrong).
>> If no public method is "inheriting" that bug, it's either not a bug, or the protected method is unused and can be removed anyways.
>>
>> Can you share the method so we don't misunderstand?
>>
>> Regards,
>>
>> Aimo
>>
>> -----Ursprüngliche Nachricht-----
>> Von: flow-bounces at lists.typo3.org
>> [mailto:flow-bounces at lists.typo3.org] Im Auftrag von Christian Loock
>> Gesendet: Montag, 13. Oktober 2014 15:41
>> An: TYPO3 Flow mailing list
>> Betreff: Re: [Flow] Best way to test protected method
>>
>> Well, the contributions doc says that I need to add a unit test to a bugfix, and the bugfix is in a protected method.
>>
>> Am I supposed to leave it as it is?
>>
>>
>>
>> Am 13.10.2014 um 15:41 schrieb Aimo Kuenkel:
>>> Hi Christian,
>>>
>>> I've written a testing package to address those issues (https://github.com/econic/Testers/blob/master/Classes/Econic/Testers/Domain/Model/Accessibility.php#L18), but as far as i remember the Flow team generally does not test any non-public code.
>>> So i think you're done with just testing the public methods.
>>>
>>> Regards,
>>>
>>> Aimo
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: flow-bounces at lists.typo3.org
>>> [mailto:flow-bounces at lists.typo3.org] Im Auftrag von Christian Loock
>>> Gesendet: Montag, 13. Oktober 2014 15:35
>>> An: flow >> TYPO3 Flow mailing list
>>> Betreff: [Flow] Best way to test protected method
>>>
>>> Hi,
>>>
>>> I am currently trying to push a little change to gerrit but am stuck a little on the unit tests. Basically I added a new protected method to a class and now want to test it. I know there are ways to access protected class properties, but is this also possible with methods?
>>>
>>> Cheers,
>>>
>>> Christian
>>> _______________________________________________
>>> Flow mailing list
>>> Flow at lists.typo3.org
>>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>>> _______________________________________________
>>> Flow mailing list
>>> Flow at lists.typo3.org
>>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>> _______________________________________________
>> Flow mailing list
>> Flow at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>> _______________________________________________
>> Flow mailing list
>> Flow at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
More information about the Flow
mailing list