模拟测试的服务或测试实例

I ended up in a discussion with one of our my colleagues about how to setup a unit-test for testing a service class.

When setting up the test case one of us suggests mocking the actual class that we are testing, while the other prefers to make an instance of the class and only mocking the dependencies.

So let's say we are testing SomeService

One solution would be to mock the actual service and test the mock:

$firstDependency  = //create mock for first dependency
$secondDependency = //create mock for second dependency
$this->someService = $this->getMockBuilder(SomeService::class)
     ->setMethods(null)
     ->setConstructorArgs(array($firstDependency, $secondDependency))
     ->getMock();

// continue testing $this->someService which is a mock

The other solution would be to test the instance of the service and only mocking the dependencies:

$firstDependency  = //create mock for first dependency
$secondDependency = //create mock for second dependency
$this->someService= new SomeService($firstDependency, $secondDependency);

// continue testing $this->someService which is direct instance of SomeService

Which of these solutions is considered best practice?

Answers preferably with some reference to official php-unit documentation or other reliable sources.

Don't mock class under test. Not exactly php-unit documentation, yet all the points are still valid. Mocking the SUT you end up testing the mock, not the actual class that will be used in production.

The purpose of unit testing is to test behaviour. Mocking the object you want to test actually means you are testing 'faked' behaviour. What's the point of testing the behaviour that was predefined?

In case of testing an abstract class creating a mock is considered good practice:

class AbstractClassTest extends PHPUnit_Framework_TestCase
{
    /**
     * Service under test in this case an abstract class
     */
    $this->sut;

    public function setUp()
    {
        $this->sut = $this->getMockForAbstractClass('My\Abstract\Class');
    }

    public function testMyAbstractClass()
    {
        $this->sut // do your test
    }
}