Skip to content

Commit

Permalink
Merge pull request #1123 from TomChaton/AdvocateInterfacesInFinalClasses
Browse files Browse the repository at this point in the history
Advocate for the use of interfaces, rather than against the use of final
  • Loading branch information
davedevelopment committed Jul 7, 2021
2 parents d1339f6 + 31cc5eb commit 002ca46
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/reference/final_methods_classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ classes or methods marked final is hard. The final keyword prevents methods so
marked from being replaced in subclasses (subclassing is how mock objects can
inherit the type of the class or object being mocked).

The simplest solution is to not mark classes or methods as final!
The simplest solution is to implement an interface in your final class and
typehint against / mock this.

However, in a compromise between mocking functionality and type safety,
However this may not be possible in some third party libraries.
Mockery does allow creating "proxy mocks" from classes marked final, or from
classes with methods marked final. This offers all the usual mock object
goodness but the resulting mock will not inherit the class type of the object
Expand Down

0 comments on commit 002ca46

Please sign in to comment.