Here is the class I'm testing. I am currently testing the doSomething function:
class FooClass { public function doSomething( $user ) { $conn = $this->getUniqueConnection( $user->id ); $conn->doSomethingDestructive(); } private function getUniqueConnection( $id ) { return new UniqueConnection( $id ); } }
As you can see, the doSomething function receives a new instance of UniqueConnection (a class that I am not testing here) based on the property of the argument it receives. The problem is that the UniqueConnection:: doSomethingDestructive is what I cannot name during the tests because of its ... destructiveness. So I would like to UniqueConnection / mock UniqueConnection , and not use the real one.
I see no way to introduce my mock UniqueConnection . I would make the argument of the UniqueConnection constructor for FooClass , but, as you can see, a new one is created based on the parameter of the doSomething function, and all the unique identifiers with which it can be called are unknown beforehand.
My only option I see is to check the layout of FooClass instead of FooClass . Then I would replace the getUniqueConnection function getUniqueConnection the one that returns mock / stub. It seems to be bad to check the layout, but I see no way to achieve what I'm after. UniqueConnection is a third-party vendor library and cannot be changed.
source share