$mock = $this->getMockBuilder('MyClass') ->setMethods(['getMessage']) ->getMock();
$mock->expects($this->once()) ->method('getMessage') ->willReturn('Hello, world!'); $this->assertEquals('Hello, world!', $mock->getMessage());In this example, we set an expectation on the `getMessage` method of the mock object. We expect it to be called once, and we set it to return the string "Hello, world!". We then call the method and assert that it returned the expected value. Package library: PHPUnit testing framework's MockObject library.