dependency = $this->prophesize(Dependency::class); } /** * Create a new object, optionally with some methods mocked. * * @param string[] $mock_methods * List of method names to mock. * * @return \Project\MyObject|\PHPUnit_Framework_MockObject_MockObject * Mock object wrapping the real object. */ protected function createMyObject($mock_methods = []) { $report_generator = $this->getMockBuilder(Object::class) ->setConstructorArgs([ $this->dependency->reveal(), ]) ->setMethods($mock_methods) ->getMock(); return $report_generator; } public function testProtectedMethod() { // Create the object under test, but we're going to mock one of it's internal methods // so that our test *only* calls the method under test, and any other methods that // get called are mocked (in this case, there's only one). $object = $this->createMyObject(['internalMethod']); $object->method('internalMethod') ->willReturn(['value' => 'test']); $result = $this->invokeMethod($object, 'protectedMethod', ['argument1']); $this->assertEqual("expected value", $result); } }