We're trying to write unit tests around our usage of NetworkReachabilityManager by subclassing it to mock out some behavior for the purposes of tests. We seem to have identified an issue because the class is marked as open but because of the design of the initializers there doesn't seem to be a way to subclass it in a way that compiles. Currently there are 3 inits for NetworkReachabilityManager:
This is a problem because if we create a subclass there is no way to properly init it as we cannot call the base class designated initializer which is required by the compiler.
Either the initializers need to be adjusted to allow for this or perhaps the class should not be marked as open.
While I question the need to do you own testing on a class Alamofire provides, since we already have testing for it, thanks for the report. We'll investigate. Cheers! 🍻
To clarify, it wasn't to test the ReachabilityManager, it was a way to mock out its behavior to test OUR code that utilizes the ReachabilityManager 😄
The goal was to make it mockable so you could define a protocol for this which we could mock or adjust the initializers for subclassing. Either would meet the need.
[Issue #1809] Moved the NetworkReachabilityManager back to public ACL.
This class was never intended to be subclassable. It was incorrectly made open and should have always been public instead. Proxying can be done at the app levels using protocol rather than subclassing.
Thanks for letting us know @SlashDevSlashGnoll. You are absolutely right, it was not set up correctly at all. Upon further investigation, we realized we never should have made the class open in the first place. This is not a feature that we really want people customizing. Therefore, I moved it back to a public ACL in 779930c.
If you need to "proxy" the functionality for testing, you'll want to create a proxy protocol and have the NetworkReachabilityManager conform to it. Then you can customize everything you need for your own internal testing.
This change will go out as part of the 4.3.0 release here shortly.
Thanks again! 🍻