You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be wonderful if you could have your cURL class implement some interface.
Right now, if I want to type-hint the type of a class method argument, I'm forced to type hint the concrete class. If the concrete class would implement an interface, I could type-hint the interface instead.
If I can type-hint an interface, I can more easily supply a mock object for unit testing purposes.
The text was updated successfully, but these errors were encountered:
I don't see a problem with implementing an interface, though there are a lot of "magic" methods which wouldn't be covered by it.
I would argue that you probably shouldn't mock the curl class, instead write a wrapper on top of it that encapsulates your business logic, add integration tests for that class and then mock your business class, but that's a topic for another day.
That's exactly what I do: I've a wrapper that encapsulate the business logic. To separate the concerns and improve testability, I inject the php-curl into the constructor, instead of instantiating it inside the class.
Right now, the constructor has anlutro\cURL\cURL as a type hint, which pretty much forces me to supply an instance of the concrete class anlutro\cURL\cURL. If anlutro\cURL\cURL would implement an interface, I could instead create a mock object for testing, which implements the same interface, thereby testing my class in isolation.
The interface only needs to define a minimal set of methods; the following would be enough (for the purpose of loosely coupling functionality, while preserving the option to type-hint, even an empty interface would suffice):
It would be wonderful if you could have your
cURL
class implement some interface.Right now, if I want to type-hint the type of a class method argument, I'm forced to type hint the concrete class. If the concrete class would implement an interface, I could type-hint the interface instead.
If I can type-hint an interface, I can more easily supply a mock object for unit testing purposes.
The text was updated successfully, but these errors were encountered: