How to mock methods from an external dependency class

I want to mock some methods from an external dependency class without executing the original constructor for this external class. This external class is from somewhere else, imported to our project by composer for example.

First of all let’s inject dependency through a protected property. Watch the example code:

Let’s use standard PHPUnit to mock.
I do not want to execute constructor of the external dependency class. I use getMockBuilder() in combination with disableOriginalConstructor() for this. The standard mocking method getMock() can disable constructor call too, by setting it’s 4th parameter to false.
To mock the Logic::execute() method I first create a mock for property by using mock::returnCallback() call the returns an anonymous function that creates mock for an external Logic class.