I have simple class wrapper Curl under the curl_ functions.
And I have several classes, that uses Curl to perform requests. Each of them has its own configuration for curl. So I need to pass freshly instantiated Curl to each of them, so I can't take service from DIC and pass it as an external dependency. But, ofcourse, I need the ability to swap real Curl to fake one in the tests, to prevent interractions with real external services.
One approach is to add abstract function setCurl(Curl $curl) to the parent class of these several classes, but not all of them has dependency on Curl. So I will need to check if this function exists before call it, or smth.
Another approach is to ad Curl as a hard internal dependency to each class, that needs it. Something like that:
public function __construct(array $settings)
{
[...]
$this->curl = new Curl();
}
But this code isn't so testable. I know, that Mockery can handle this sort of dependency, but I won't add it to project only for that reason.
Aucun commentaire:
Enregistrer un commentaire