Inherits the old class and chains the mock methods of an aggregated mock object.
class MyClass { public function add($a, $b) { return $a + $b; } public function multiply($a, $b) { return $a * $b; } } $mock = $this->getMockBuilder(MyClass::class) ->setMethods(['multiply']) ->getMock(); $mock->expects($this->once()) ->method('multiply') ->with(2, 3) ->willReturn(6); $partialMock = $this->getMockBuilder(MyClass::class) ->setMethods(['add']) ->getMock(); $partialMock->method('add') ->will($this->callParent()); $partialMock->method('multiply') ->will($this->returnCallback([$mock, 'multiply'])); $result = $partialMock->add(2, 3); $this->assertEquals(5, $result); $result = $partialMock->multiply(2, 3); $this->assertEquals(6, $result);In this example, we first create a mock object of the MyClass class with the multiply method overridden to return a specific value. We then create a partially mocked object of the MyClass class with the add method overridden to call the parent implementation, and the multiply method overridden to call the mock implementation. We then test that the partially mocked object correctly calls the parent implementation of add(), and the mock implementation of multiply(). The package library for PHP Mock is PHPUnit, a popular testing framework for PHP applications.